time measurement between two pulses

klaus313

New Member
Hi,
I'm looking for a clever way to measure the time (ms area) between two input pulses (trigger is low to high transistions)
(not a single event it is a continious (not constant) pulse sequence but I would need all the time deltas for the pulse sequence)
any idea ?
Thanks a lot
 
Last edited:

AllyCat

Senior Member
Hi,

The "Timer 1 Gate" hardware (at least in all M2 chips) is designed for exactly that purpose. But it's not supported directly by the PICaxe Operating System, so you would need to use PEEKSFR and POKESFR commands and "work around" that Timer 1 is used by the Operating System (as a 20ms timer for several purposes).

I thought that I had written a "Code Snippet" on the topic, but all I can find at the moment is post #10 (in particular) of this thread.

Cheers, Alan.
 

hippy

Technical Support
Staff member
As AllyCat suggests, a timer with gate control would be best for measuring pulse width with greatest accuracy. All except the 20X2 can support that. The 28X2 and 40X2 have multiple gate control timers so those would be the best choice for measuring consecutive high and low periods in a continuous stream of pulses.

When pulse periods are short there may be an issue if the PICAXE does not have enough time to read a result and get the timer ready for the next. For millisend periods it might be possible to do it entirely in software without using on-chip timers. Even a PULSIN command may do the job.

It is not clear why you need a "clever way" to do things. If you could let us know why the pulse times are needed, where they originate, how they will be used, for what purpose, there may be other, better, or a best way to do things which can be identified.
 

oracacle

Senior Member
I would lean towards either timer one or a PWM signal.
I have one a few occasion used the above (here is one made based on hippys' 20x2 timer: https://picaxeforum.co.uk/threads/high-accuracy-timer.28067/)
its hardware based for capture of the input pulses and relies on having two pulse sources for start and stop - you did not specify if that how your pulses are being sent.
essentially there are 2 SR latches, either can start or stop, but they have to be opposed to one another (ie if one starts, the other stop or the other way round). these capture the pulses and run through an XOR gate, which then in turn feeds into a NAD gate that adds in the clock signal, finally the signal is inverted to get the desired output.
The downside, for your application maybe that the SR latches need to be reset. In my case it resets them when its ready - after it has read the pulse count iirc.

I'm not sure how to quantify "clever" so am not sure if this counts or not
 

klaus313

New Member
Many thanks for you comments. Don't take the word "clever" as granded I, was just looking for a solution.
My latest idea would be to work with two task, one is just reading out the time with pulsin in a register .The other task would process the value accordingly.
I just have to make sure that the signal low time is long enought to start the next pulsin command
 
Top