Strange timing behavior
skywatcher
Posts: 7
Hello @ all
I wanted to measure the frequency of an oscillator (about 30 kHz sqare wave) with the Propeller. Because measuring only one pulse gives not enough resolution for my purpose, i decided to wait for multiple H/L and L/H transitions before capturing the timer end value. When i looked at the results, i saw a jitter of several clock cycles. First i thought that my input signal may have this jitter, but i saw almost the same amount of jitter for every input signal, regardless of its source. It should be very unlikely that different signal sources have exactly the same amount of jitter. So i programmed a second propeller chip to generate a 'clean' signal and connected it to the first one. The jitter remained the same. Ok, maybe it's some sort of PLL jitter... then i used one and the same Propeller chip for signal generation and measurement, and this should be absolutely free of jitter because it's the same clock source. The test code is attached below.
The strange thing is now: If i measure <= 12000 pulses (NCount := 12000) there is no jitter.
The results look like this:
29063957
29063957
29063957
29063957
But if i increase NCount to 12500, it looks like this:
30274949
30274957
30274949
30274957
30274949
30274957
There is a jitter of 8 clock cycles.
I have absolutely no explanation for this.
All variables are 32 bit so there should not be any overflow.
Can anyone explain this ?
I wanted to measure the frequency of an oscillator (about 30 kHz sqare wave) with the Propeller. Because measuring only one pulse gives not enough resolution for my purpose, i decided to wait for multiple H/L and L/H transitions before capturing the timer end value. When i looked at the results, i saw a jitter of several clock cycles. First i thought that my input signal may have this jitter, but i saw almost the same amount of jitter for every input signal, regardless of its source. It should be very unlikely that different signal sources have exactly the same amount of jitter. So i programmed a second propeller chip to generate a 'clean' signal and connected it to the first one. The jitter remained the same. Ok, maybe it's some sort of PLL jitter... then i used one and the same Propeller chip for signal generation and measurement, and this should be absolutely free of jitter because it's the same clock source. The test code is attached below.
The strange thing is now: If i measure <= 12000 pulses (NCount := 12000) there is no jitter.
The results look like this:
29063957
29063957
29063957
29063957
But if i increase NCount to 12500, it looks like this:
30274949
30274957
30274949
30274957
30274949
30274957
There is a jitter of 8 clock cycles.
I have absolutely no explanation for this.
All variables are 32 bit so there should not be any overflow.
Can anyone explain this ?
Comments
That first load needs to be truly edge locked, otherwise is actually depends on the path delays.
In a well designed Reciprocal Counter, you should be able to also have a longer background average, which means no gaps in the samples.
A single capture point is a good idea, and 'pivot' the code housekeeping around that.
So something like The first 3 lines can be removed, if you simply discard the first result.
herzlich willkommen - welcome to the propeller-forum
looking into your code.
Are you sure you want both cogs start with stack0 ?
You also can use the counter-module to measure frequencies. I haven't done much with the counters yet.
best regards
Stefan
The results are written into the HUB RAM after the last sampling of the counter so thi should have no influence, especially as long as the writing is completed before the next falling edge, which is always the case.
Additionally, the question remains why there is no jitter at <= 12000 pulses measurement, and there is jitter at 12500 pulses measurement.
Not quite, see #2, and try the code flow I just added.
8 cycles is not random, it is dependent on what else is happening
I tested your code, and compared to my code the resulting measurements were some clock cycles higher, which is strange because the code in loop2 after the 'waitpeq' instruction should not have any influence on the result, because its execution time is well below the time of the 'high time' of the input signal. But it really looks like the jitter comes from the wrlong HUB instruction which is the only instruction in the whole loop with a variable execution time.
Try it written like this
That is the benefit of a single load point.
I would have expected to be unchanged, or maybe 40 clocks higher, but not lower. This is completely beyond my understanding.
Which code ? The code in #2 should be immune, as it has a single timing point,
The code in #7 is the error simply rephrased (not fixed), to hopefully make it clearer.
The bottom read of CNT is not edge locked, but is a transit-time-added to the real edge pivot, which is further up.
Thus adding NOPS should lower the next difference, as that start is incorrectly late, and pushed later by the NOPs.
You could fix #7 by adding a waitpne pinA,pinA, to get a real edge lock again, but as that then clones the code at Loop2, I personally prefer a single-point-of read, as that avoids these transit-time issues.
[edit: Doh, didn't notice other replies!]
Ok, you are right... in code #2 the NOPs have no effect. I think i have to go to bed and continue tomorrow, it's already 1:30 am here... anyway, thanks for your help. :-)
@all:
Is there any data available about the phase noise of the Propeller PLL ? In the datasheet there is no info about this.
Not that I have seen, but I think it is a true PLL, not some delay-fudged version.
You could test this with two Props, and not quite the same Crystal/Osc, to give you an Audible beat.
Use of a sound card spectrum analyzer should give the jitter.
Sounds good, you should also be able to see the drift between two Oscs - try soldering one, then watch it cool.
On your numbers, you have a LSB in the region of 33ppb.
On the jitter front, if you can find two Oscs/Xtals apx 500Hz apart, you can resolve to
1/(5e6+500)-1/(5e6+450) = -1.9996e-12 seconds - ie a 50Hz change, is ~2 picoseconds
I can see the two oscillators drifting away very slowly. Looks nice.
The difference in measured values in the unsynchronised case is simply down to math (cycles/loop) and the fact that hub windows are only at 16n (start time is affected by wrlong timing).
A timing for my setup