Time between edges
Ltech
Posts: 380
in Propeller 1
I try to get the time between variable edges of a square wave.
The minimum time are 240us, the maximum 1_020us.
I only need to detect value 250us or 1_000us, it is "Biphase marque"
I try in spin
Is this to simple ?
I do not get the expected timings, compare to my scope
The minimum time are 240us, the maximum 1_020us.
I only need to detect value 250us or 1_000us, it is "Biphase marque"
I try in spin
ctra := %01110<<26 + pin 'ctra for neg edge detection frqa := 1 ctrb := %01000<<26 + pin 'ctrb for pulstime high frqb := 1 ... repeat i from 0 to 80 'main loop detection phsa := phsb := 0 'clr edge and pulstime repeat until (phsa OR phsb) 'wait for neg edge OR pos edge pulses[i] := (phsb+phsa) ' I expect to get the time between edges => A can be 0; or b can be 0. So sum would be edge time
Is this to simple ?
I do not get the expected timings, compare to my scope
Comments
So, in your code, PHSA is always 0, and PHSB is almost same some small value each time.
If you don't need accuracy and quickness, below might work:
Also you can use WAITPxx command, instead of REPEAT UNITIL command:
And also you can use system counter CNT to measure time, instead of cog-counters:
(Sorry I did not test these yet but I'll later.)
It's best to use a constant for your pin mask. Spin already has some overhead and you don't want to add any more by creating a mask in place.
If you just want the next complete half cycle, regardless of phase, this works (I tested both methods with an oscillator running using CTRA).
Warning: If the pin doesn't change, these methods will block your program. What you could do is launch it into its own temporary cog which would allow your foreground code to timeout the measurement.
I don't have time today to test this part.
I wil test it tomorrow
Daniel
I got in a dedicated cog, detecting all the edges and toggle pin:
And other cog, analyzing @ 6/8 time, of the next pulse:
The result if I have 2 pulses, we got a 1, if we have 1 pulse we got 0
Proof of concept is working fine.
Now I go try in pasm