Electronic – Need help with timing circuit for ballistic sensor

timing

I built a project using an Arduino microcontroller to manage high speed photography of an air rifle shooting targets like balloons.

I have a contact switch on the trigger. When that feeds a logic 1 into my Arduino program, I tell the camera to fire it's shutter, turn off the LED room lights, and start looking for the pellet from the air rifle to break a beam of LED light that's placed in front of the barrel of the gun. When that happens, my program times the amount of time the pellet takes to break a second beam that is exactly 2 inches past the first. My program uses the delay between the 2 events to calculate the speed of the pellet, and multiplies the by the distance to the target that I've entered into the Arduino.

At the calculated time my rig uses a solid state optio-isolator to close the contact on a flash.

Everything works well, to a point. I wrote Arduino code that deals with the i/o ports directly rather than using the Arduino functions to minimize the latency of inputs.

However, the Arduino is relatively slow, and it takes several instruction cycles to respond to a triggering event. That means that my calculated time is limited to multiples of the response time, meaning that my timing for firing the flash is often off by a small but important amount.

What I'd like to do is have a microsecond precise programmable realtime clock chip that I could trigger on a rising edge signal, have it measure the delay to the second sensor, calculate the projectile speed and the required delay until the projectile reaches the designated distance to target, and then trigger a logic 1 at that moment with microsecond accuracy.

Most real time clock chips I've seen output the time over a serial line, which would be way, way too slow for this application. Even for my air rifle application the pellet would be stuck in the "bullet trap" at the end of the target before the first time value has finished being sent to my microcontroller.

I'm currently working with air rifles, but hope to switch to .22 caliber bullets, which can move at faster than the speed of sound.

Is there some high precision programmable realtime clock chip I could use for this application? Or perhaps a circuit I could build with a quartz crystal, a digital counter, and a programmable gate array?

P.S. Here is a link to some of the results from my current setup. When it works, the results are very cool looking:

High speed photography

Best Answer

I think you can use the built-in input capture in the AVR microcontroller (possibly with an Arduino library function rather than bare-metal programming). If you did have to do the latter, Atmel Studio is a free download and has everything you need software-wise.

Timer 1 is 16 bits and, I believe with minimum prescaler it can be run at 16MHz (assuming that's the CPU clock), which gives you 62.5ns resolution and 4ms maximum time. The counter free runs and the count is grabbed upon seeing an edge when properly configured.

The only problem I foresee is that the pulses may be two close together for the input capture to be reconfigured to grab the second edge on the other input pin. In bare metal programming you could use an interrupt and probably some microseconds would be enough. At 1500 FPS you would have 111usec for 2" which sounds like a lot of time for an ISR. You could get about 1776 counts which is likely much more than necessary or even useful.

For that, or other reasons, you might consider increasing that 2 inches- it seems rather short to get high accuracy anyway. Commercial bullet speed meters use more like 200mm/8" IIRC.