Go Down

Topic: Timing circuit (Read 1 time) previous topic - next topic


Im working on a project to measure the time difference between on off signals.

The output is 0-24v (however this can be reduced easily) and i need to measure with sub microsecond accuracy.

I just want to measure the time that the signal is high and then output this time digitally to a microcontroller (probably a raspi eventually but an arduino will do for now)

I realise that all this is possible with an arduino due however i will have 6 sensor recording in parallel and think that the loop time will cause me an issue with getting an accurate time.

Does anyone have suggestions of ic chips or small boards that would be suitable for my application? any help would be really appreciated




A very curious setup. If you have 6 sensors recording in parallel, how do you tell one from the other in order to discover a time difference?



hi paul, thanks for your quick reply :)

the sensors use reflected light to detect when an object passes in front of them, im interested in how long the object is in front of the sensor. each sensor is placed in a different location.

I imagine that each sensor will be attached to its own timing circuitry, each of these circuits will then output a time signal each time an object has moved in front of it to an arduino or cpu.

I hope this makes things abit clearer.

Thanks again


You wrote: " i need to measure with sub microsecond accuracy.",

You cannot do this with reflected light due to diffraction at the edge of the object, change in amount of reflected light as more and more of the object is illuminated as it enters the measuring arena, and then the reverse happens as it leaves.

You need "break-beam" measurements so the edges, only of the object are involved in the measuring to get the time in front that you desire.



its not exactly an object im looking at, its a mark on a plate that is moving, one part of the plate is reflective, the other is black. the plate is moving at high speed.

im going to be using keyence fibre sensors to do this  https://www.keyence.co.uk/products/sensor/fiber-optic/fs-n/index.jsp the model im using has a delay of 25us, however this does not vary so i can account for it the calculations.

these sensors have the signal processing in and output a digital signal when they reach threshold.

Thanks again


I have a very quik idea:
First of all its better if you create a easy circuit to mesure time with the precision that you want, something that, precisly every 1 your needed precision do something on a pin. That is connected to a interrupt pin. What interrupt does? Add 1 to a variable. You have also a second interrupt pin, connected to the 0/5V (the 0/24V reduced). What it does? Charge a "last time" variable with the value of the time variable and assign 0 at the time variable.
The loop only use the value of 'last time"
Dove va un numero va una variabile, una funzione e/o  un test.
Per ottenere devi spiegare

Strumenti/Formattazione automatica fino alla morte!


The ATMEGA Input Capture feature may work for you.

caveat: One per ATMEGA328.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!


Oct 09, 2019, 01:11 pm Last Edit: Oct 09, 2019, 01:12 pm by Idahowalker
ESP32 PCNT module and API:
The PCNT (Pulse Counter) module is designed to count the number of rising and/or falling edges of an input signal. Each pulse counter unit has a 16-bit signed counter register and two channels that can be configured to either increment or decrement the counter. Each channel has a signal input that accepts signal edges to be detected, as well as a control input that can be used to enable or disable the signal input. The inputs have optional filters that can be used to discard unwanted glitches in the signal.

The PCNT module has eight independent counting "units" numbered from 0 to 7. In the API they are referred to using pcnt_unit_t. Each unit has two independent channels numbered as 0 and 1 and specified with pcnt_channel_t.
For the counter not to miss any pulses, the pulse duration should be longer than one APB_CLK cycle (12.5 ns).


I have had a similar issue, reading 3 sensor that pulse at quite high frequency (as fast as 180 millis() delay). Having them directly on an interrupt pin would cause the main program to freeze almost.

I decided to use two ATTiny85 doing this constant job, and send their record every second to a Nano by I2C, where the ATTinies act as Masters.

On breadboard this worked with one, test should be done with the two and real life setup is yet to be tested...

Go Up