Skip to content

Instantly share code, notes, and snippets.

@alexymik
Last active August 29, 2015 13:57
Show Gist options
  • Save alexymik/9497395 to your computer and use it in GitHub Desktop.
Save alexymik/9497395 to your computer and use it in GitHub Desktop.
Experiment to see if various low cost ATMega processors on Arduinos were fast enough to trigger some scientific equipment. Next step would be ASM. Measured with an oscilloscope
const int TRIGGER_PIN = 8;
const double HIGH_TIME = .012;
const int LOW_TIME = 10;
const int PULSE_DELAY = 98;
const int GROUP_DELAY = 920;
void setup() {
TRIGGER_PINMode(TRIGGER_PIN, OUTPUT);
}
// Written sequentially to avoid
// any wasted cycles on control flow
// delay(millisec)
// delayMicroseconds(microsec)
void loop() {
//Packet 1
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(PULSE_DELAY);
//Packet 2
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(PULSE_DELAY);
//Packet 3
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(PULSE_DELAY);
//Packet 4
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(LOW_TIME);
digitalWrite(TRIGGER_PIN, 1);
delayMicroseconds(HIGH_TIME);
digitalWrite(TRIGGER_PIN, 0);
delay(GROUP_DELAY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment