finding time between two pulses.

djsfantasi

Joined Apr 11, 2010
9,237
@crutschow had a very nice approach, but for it to work, I think you need two separate signals/pins input to the Arduino. ORing the pulses results in a loss of information which is useful.

The pulses are digital in nature, are they not? An Arduino digitalRead command will let you know when there is a pulse. Is ms sufficient to tell what you want? Then you can use the millis() function in calculating the time difference.

I didn't see how you were planning on outputting the errors you detect? Are you planning on a display or logging them to external storage, such as an SD card?
 

Thread Starter

cornishlad

Joined Jul 31, 2013
242
@ djsfanasi..I think you can see that I'm not very far forward in finding out how much I will be able to do with the Arduino. But I think I have now seen elsewhere that the time difference between two pulses can be measured directly without the need for the external error pulse generating circuit that has been the subject of this thread. To begin with though I will try and use the "PulseIn" script and the single derived pulse.
As for output, I've been looking at 8 digit, Arduino compatible led displays that are listed on eBay for a couple of £'s (a few $ !!) If there is a way to log and save the data I will hopefully come across that in due course...A text file that could be imported into eXcell and graphed would be the ultimate..
 

MikeML

Joined Oct 2, 2009
5,444
Are we overcomplicating it? Assuming that the two pulse trains each have a fixed duty cycle (but near 50% for each), and that the frequencies of the two pulse trains are close, then using a simple AND or NAND will generate a signal whose width will change as the relative phase of the two pulse trains changes...

62.gif
 

djsfantasi

Joined Apr 11, 2010
9,237
There is a way to log and save the data. Get a shield with an SD card holder. Then, you can own a file on the card, write your data and bring the card to your PC to read the data. If you format your output, the data file can be directly read into Excel. I'll supply a parts list later.
 

Thread Starter

cornishlad

Joined Jul 31, 2013
242
@MikeML. I just got to the last line of a long post and it suddenly vanished :-( So...another go.
That solution in your last seems to good to be true! I do find the timing diagram hard to follow but I'm not doubting that you're right. My clock and the GPS start by out-putting 1 PPS each with different, but short, pulse durations. However after dividing by 30 both will present with perfect 50% duty cycle at the divider chain out puts. (I think!) It will be dead easy to apply them to a NAND gate and observe/understand the output. I will try that first.

@djsfantasi. Thanks for that advice. I will order a shield with an SD card holder..other stuff too if you give me a parts list..Then I think I must let this thread cool until I've got a bit further forward with the project. It may be a couple of weeks before the clock is running again and I have the GPS module to play with. (not to mention getting the Arduino out of its jiffy bag)
I can always start a new thread later to deal with whatever problems I've encountered; either with the electronics or in the programming section about the Arduino. That will be a seriously challenging part for me !
Another thank you for the continued help that's been offered...Roger
 

Thread Starter

cornishlad

Joined Jul 31, 2013
242
With such a long time between pulses (30 seconds) it should be easy to tell the difference between the A,B and the B,A measurement if they are compared and processed in either of the first two circuits given earlier. cructshow's circuit take it into account as I understand it. I'm sure I can deal with that anyway.
If the reference pulse was timed as an exact reference for the expected time keeping of the clock the error would either be positive or negative as the clock rate changed. The A or the B could indeed come first.
Now, With more clarity in the nature of the problem, I think I can say that as the GPS pulse is divided down from 1 sec pulses - which it will be - I'm assuming I could manually zero the counter so that the reference GPS pulse always occurs an exact number of seconds early. Earlier in fact than the clock could conceivable drift. This could be, for example, 5 seconds. 5 seconds could then be subtracted from the result to see the way the clock error is actually going.
I can visualize this easily if the two pulses were shortened to a few micrseconds and compared in either of the two circuits suggested earlier. The 50% duty cycle square wave I find more difficult at present to comprehend and so detecting A,B or B,A timing will no doubt become clearer when I can see them.
Mentioning the Arduino has of course taken me further down the line of enquiry than perhaps I was prepared for and may have confused things a bit !....Roger
 

djsfantasi

Joined Apr 11, 2010
9,237
But the OP said that either A or B could be first. He only wanted the time between the two pulses.
@cornishlad, this doesn't necessarily pertain to your problem so please indulge me.

@crutschow, the time between which two pulses? What happens if the sequence of pulses is BBA? Which time period should be measured? BB? BA? Or from the first B to A? To determine which pulse to measure in this case, you need to differentiate between the A and B pulses... Unless the time for BB is acceptable.

It's the programmer in me. I can use all the information present and hence don't like when some if it is lost.
 

crutschow

Joined Mar 14, 2008
38,503
@cornishlad.............
@crutschow, the time between which two pulses? What happens if the sequence of pulses is BBA? Which time period should be measured? BB? BA? Or from the first B to A? To determine which pulse to measure in this case, you need to differentiate between the A and B pulses... Unless the time for BB is acceptable.
It's the difference between the two pulses closest in time. Thus if A is ahead of B by 2 seconds or A is behind B by two seconds, my circuit generates a two second pulse in either case.
 

djsfantasi

Joined Apr 11, 2010
9,237
I
It's the difference between the two pulses closest in time. Thus if A is ahead of B by 2 seconds or A is behind B by two seconds, my circuit generates a two second pulse in either case.
I'm not disputing that your approach is in any way wrong. As I understand it, A and B are two separate sources. What if we received two pulses from A? Do we want the time between them? Or do we wait for a pulse from B? If we OR the pulse sources, we couldn't distinguish the case of two consecutive pulses from the same source, potentially resulting in erroneous data.
 
Top