Electronics > Projects, Designs, and Technical Stuff

Measuring time span very precise

<< < (11/16) > >>

HendriXML:
That's great! This solution with 3 high word counters using also the overflow interrupt has some longer periods on which the linking of a captured counter to its high word is valid (25% -> 33% of a full cycle)


Ian.M:
Heh.  It should be possible to determine the correct software high word for one cycle under half the rollover period after the instant of capture using the 'read all the flags + high bit''method.  That's 2ms on a 16 bit counter clocked at 16MHz e.g on most 5V AVR Arduinos.  Just plot out all the possible race conditions assuming interrupts are never disabled for more than 2 ms, and build the logic accordingly.

KrudyZ:
Measuring the time between two trigger signals is a fairly common requirement.
The equipment used is called a time interval counter or analyzer.
An interesting read describing a state of the art instrument from 1978 !!! which achieved 20 ps single shot resolution can be found here:
https://www.hpl.hp.com/hpjournal/pdfs/IssuePDFs/1978-08.pdf

As you can imagine newer instruments far exceed the 5370B in capabilities, but HP provided chip level schematics with detailed explanations if you want to dive deeper, which makes this very educational to read.

HendriXML:
It's clear to me that using the Mega 2560 board can do very nice stuff with event timing. With a resolution smaller than 1 usec. I will implement the time span measurement with that board. I'll use 2 timers 4 and 5. Their event capture pins on the board are 49 (ipc4) and 48 (ipc5).
Why use 2 timers? That give 2 timestamp registers, so they won't get in each others way. This way (as has been said by Ian and others) very small time spans can be measured. The interrupts will be also queued independent of each other, so no loss of interrupts.
Also the events can be discriminated from each other (start vs stop). Especially in the situation when a Nerfdart is shot wrong (no start gate or no stop gate) this is handy.

Is there a special way to synchronize them? Or is this just a matter of finding the code to
DisableInterrupts
SetCounterTimer4(0)
SetCounterTimer5(0)
EnableInterrups

HendriXML:

--- Quote from: Ian.M on September 07, 2019, 06:51:38 am ---See the ATmega2560 datasheet section 18.4.1 GTCCR - General Timer/Counter Control Register, Bit 7 – TSM: Timer/Counter Synchronization Mode.  Using it, multiple Arduino Mega2560 16 bit timers can be initialised to run in lock-step with each other.  Then you can use separate input capture units to timestamp your start and stop external events and calculate the interval as Magic suggests in reply 6 above, even if the events are only a single ATmega clock cycle apart.  Assuming the counter and captures are extended in software to 32 bit, at the highest resolution of 1/16 us, you get a rollover period of a bit under five minutes.  Drop the resolution to 1/2 using the prescaler and the rollover interval becomes slightly under 36 minutes.  The next step down has a resolution of 4us and a rollover period of 4 3/4 hours.

The only fly in the ointment is the poor accuracy of the typical Arduino ceramic resonator clock oscillator, so you will probably need to feed the Arduino a master clock from a much better quality oscillator.

--- End quote ---
I think this answers the synchronization method. I'm not sure what it does yet, but I'll figure it out.

Is it better to redo the oscillator instead of replacing the resonator with a crystal (don't know if that possible )?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod