Electronics > Projects, Designs, and Technical Stuff
Measuring time span very precise
iMo:
TDC7200, easy to use, libs for arduino..
PS: with that chip (works fine) you may upgrade from the nerf darts gun to a railgun later on.. :D
max_torque:
define precise?
I recently did a project with a 32b counter ic, driven by an over stabilised oscillator at 40Mhz, and a micro just uploads the counts when it's triggers, and takes one for the other (as mentioned previously) to get the counts difference. The oscillator was calibrated using a GPSDO, so i've got 25ns resolution. At that level you have to be really carefully of your triggering jitter and latency, matching your triggers so as to not create an offset to the "true" events!
even for a flight time measured in ms, your resolution looks good (10ms = 40,000 counts!)
Ian.M:
There's not much fun and learning in using a single chip time of flight event timer breakout board + 'canned' Arduino libraries. If we want to do it the smart hard way (but not the hard hard way, which would be a board full of individual counter chips, or the lazy way which would be throw a FPGA at the problem), you have to understand the constraints on a practical solution.
Lets put some numbers on the problem. A M61 Vulcan rotary cannon, has a published muzzle velocity of 1050 m/s. Assuming a 10MHz counter clock, you'll get fractionally under 10 counts for every mm the round travels. Nerf guns in the Rival series allegedly top out at around 30 m/s (other series are around half that), so with the same 10MHz counter clock, you'll get 333 counts per mm of round travel. For comparison, a good fastball bowler is about as fast as the Nerf Rival dart.
At 10MHz input clock, a 16 bit counter rolls over in slightly over 6.55 ms, 24 bit in slightly under 1.68 seconds, and 32 bit in slightly over 7 minutes 10 seconds.
That means that with 100mm between sensors slower Nerf darts will probably overflow a 16 bit timer clocked at 10MHz overflow a 16 bit counter clocked at 10MHz. Put the sensors further apart or use the Arduino 16MHz resonator and you'll definitely overflow the AVR 16 bit timer 1 if you don't use the prescaler to drop the timer clock to 1MHz.
Some MCUs are much better than others for high clock speed counting. e.g. the AVRs used in 8 bit Arduino boards synchronise the external counter clock to the core clock, so with a 16Mhz resonator, the maximum input frequency is fractionally under 8MHz with an exact 50% duty cycle.
PIC18 series chips generally do much better as they have an asynchronous up to 8 bit prescaler for timer 0 followed by a synchronous 16 bit timer, and the prescaler can be clocked at up to 50MHz, (50% duty cycle again) as long as you meet the constraint FT0CKI<N/(4/Fosc + 40ns), where N is the prescaler ratio.
At even 1MHz Fosc this constraint can be met for a 50MHz input signal. There's also a trick where art the end of the couter gate period, one clocks the input under software control, and by counting the number of pulses till the counter next increments, you can calculate the count that was in the prescaler, allowing you to use Timer 0 as a 24 bit hardware timer.
No doubt others will chip in with the max. counter clock of their favourite MCU.
Although some MCUs may have all the logic and counters you need for high precision timing internally (e.g. some 8 bit PICs have a gated Timer 1 that can operate at up to 33.3MHz from an external high precision clock source), you may well be better off implementing the timer gate logic externally, which can be as simple as a few gates and flipflops. e.g. adding a single 74LVC1G74 flipflop in front of a PIC18 T0CKI pin gives you a 100MHz gated counter with an uncertainty of 1 count (due to the flipflop.) If you are being really cheap and minimalist, use the flipflop /R input as the gate, (runs when high) and connect both /R and /S back to PIC I/O pins, so you can pulse the Q output under program control to clock out the count in the Timer 0 prescaler by pulsing /S low while /R is low. However adding one AND gate ahead of the flipflop clock pin to handle the gate lets you read the flipflop output before clearing it, for an extra bit of resolution. For external gating with separate start and stop inputs, use another one as a simple SR flipflop, with 1K||33pf between its Q output and the first one + PIC I/O pin so the PIC can override it and hold the gate inactive while it cocks out the prescaler count. That's three tinylogic gates, the cheapest USB PIC18 + commodity crystal, and a good 100MHz TCXO + a significant amount of software development to get a USB interfaced timer with 20ns resolution and on a $30 budget you can probably get 5ppm accuracy.
Similar approaches can be used with Arduino, but due to the AVR timer clock frequency limitation, you'd probably want to use an external prescaler of at least four bits.
HendriXML:
--- Quote from: magic on September 07, 2019, 11:02:50 am ---If your MCU has two timers with separate input capture pins, events A and B can be captured by separate timers.
In such case they may be spaced even 1 clock cycle apart, which is 1/16µs at 16MHz.
The software will then read timestamps captured by each counter and calculate the difference.
edit
Basically, we are trying to convince you that all the digital logic hardware you described in the original post is already in your MCU, just use it :)
--- End quote ---
From what I've read and understood the Mega2560 can indeed be used. It has 2 16 bit timers with capture mode. I think only one would be needed. The time between events is not that small. The 16 bit timers have a overflow bit. That overflow bit will be important in 2 interrupts, the capture interrupt and the overflow interrupt. If the overflow interrupt hasn't counted the overflow yet, the capture interrupt might need to do that to determine what its 16+ bits are if its "near" overflowing. This checking should be done with interrupts disabled (delaying the overflow interrupt). I'm not entirely sure yet if the Arduino software makes this possible.
Using capture mode register gets the current counter and an interrupt will follow to process that value. In meanwhile no other capture events should happen: that seems doable. So thanks for sharing this option!
Will continue to digest the other ones!
HendriXML:
--- Quote from: max_torque on September 07, 2019, 02:03:08 pm ---define precise?
I recently did a project with a 32b counter ic, driven by an over stabilised oscillator at 40Mhz, and a micro just uploads the counts when it's triggers, and takes one for the other (as mentioned previously) to get the counts difference. The oscillator was calibrated using a GPSDO, so i've got 25ns resolution. At that level you have to be really carefully of your triggering jitter and latency, matching your triggers so as to not create an offset to the "true" events!
even for a flight time measured in ms, your resolution looks good (10ms = 40,000 counts!)
--- End quote ---
The nice thing about the 74LV8154 is that the current counter can be copied to an internal register, so bits can't change during readings. Does the counter IC you've used offer something similar?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version