How to simulate 70µs signals mechanically

Contemplating a project that needs to accurately measure the time between two signals. The shortest time is likely to be over 70µs and the longest about 300µs - from reading around, I'll be using Timer1 which should give me sufficient resolution (as even the shortest time is over 1,000 clock cycles).

It's for a rifle chronograph concept but I don't want to have to test things by shooting continuously, especially as I think there is going to be a lot of tweaking needed.

Bolting something to my lathe faceplate gives me a minimum time interval of over 300µs (6 studs at 3,000rpm) and having something large spinning around that quick is a bit dangerous too.

Only need two pulses simulated at a time - mousetrap isn't quick enough - tip speed is about 30m/s which would mean I'd need to set my sensors apart 2mm, which isn't really enough

Any ideas?

Hello,

Well,

What do you really need?

Do you need to test your code or test the sensor?

It may be simpler to use a second Arduino to generate the pulses.

I will need to test both.

Initially I can use a second Arduino to generate the pulses as you say - this will test the software to some extent.

I will then need to test the sensor(s) - think I will have to use a high RPM motor that strikes two targets set at a known distance apart. The actual accuracy of the test rig isn't too vital as long as the two pulses arrive within a short distance of each other (although actually stopping at 2 will be difficult).

On another note, should I receive both signals on the same input (in series) or on different inputs? The actual calibration can be done with a number of rifle chronographs that I own or can borrow

spandit:
On another note, should I receive both signals on the same input (in series) or on different inputs? The actual calibration can be done with a number of rifle chronographs that I own or can borrow

I would use on two distinct ports, and with interrupt, as on port D2 and D3

rtek1000:
I would use on two distinct ports, and with interrupt, as on port D2 and D3

I will write my code accordingly, thank you

Yes, two distinct ports is the way to go.

Both interrupts set a flag and read the timer value. Your code tests for these flags, and calculates speed based on it.

volatile bool startDetected;
volatile bool endDetected;
volatile uint16_t flightTime;

void ISR1() {
  TCNT1 = 0;
  startDeteced = true;
  endDetected = false; // safety: in case we had a false end trigger.
}

void ISR2() {
  flightTime = TCNT1;
  endDeteced = true;
}

void loop() {
  if (startDetected && endDetected) {
    startDetected = false;
    endDetected = false;
    // calculate speed based on the value of flightTime.
  }
}

Attach interrupts to FALLING or RISING edge, as appropriate for your sensors.

On your sending Arduino you could do something like:

void setup() {
  randomSeed(analogRead(A0)); // Or any unconnected analog pin.
  pinMode(startPin, OUTPUT);
  pinMode(endPin, OUTPUT);
  Serial.begin(115200);
  digitalWrite(startPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(startPin, LOW);
  int delayTime = random(70, 300);
  delayMicroseconds(delayTime);
  digitalWrite(endPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(endPin, LOW);
  Serial.print("Delay time was:");
  Serial.print(delayTime);
  Serial.println(" µs.");
}
viod loop() {}

Now every time you press the reset button a new "pulse" will be generated: two pulses of 5 µs each on two separate pins, 70-300 µs apart, after which it prints that value to the Serial output. Compare that to what your chronograph thinks it is (it should be 5µs longer than what the pulse generator tells you). Those two outputs connect to your inputs on the other board. Do connect grounds between the boards.

Wow, thank you!