How to phase-sync two counters of one cog?
ul5255
Posts: 14
Dear all,
I'd like to use the two counters of one cog to output a signal
in PLL mode. Both counters shall produce the signal with the
same frequency *and* phase.
My approach is to pre-load the PHSB register with a value
of 2x FRQA (I have previously verified that after the operation
'mov frqb, f' the value of PHSA already advanced by
2x FRQA):
signal with the same phase. For this I use another cog's counter
A to count the number of times where the two pins 15 and 16
have different logic levels. I let this counter run for ~ 10 sec.
Then I serial.dec(PHSA) back to the PC. Unfortunately that
value is never zero. To make matters worse that value is not
a constant.
I can imagine to dynamically adjust the PHSB value of the
signal generating cog until the phase difference between both
counters is getting (close to) zero but I hope there is a
better way to do this (perhaps start both counter at the
same time?) ...
Any ideas?
Cheers,
ul5255.
I'd like to use the two counters of one cog to output a signal
in PLL mode. Both counters shall produce the signal with the
same frequency *and* phase.
My approach is to pre-load the PHSB register with a value
of 2x FRQA (I have previously verified that after the operation
'mov frqb, f' the value of PHSA already advanced by
2x FRQA):
[FONT=courier new] mov ctra, ctraval ' PLL square wave at pin 15[/FONT][FONT=courier new] mov ctrb, ctrbval ' PPL square wave at pin 16 mov phsb, phase_delta ' advance PHSB by 2*FRQA because ' counter A starts one MOV ' instruction before counter B mov frqa, f ' start counter A mov frqb, f ' start counter B (counter A already ' counts!) mov DIRA, d ' finally set pin 15+16 as output [/FONT]After this I hoped that both counters would generate the
signal with the same phase. For this I use another cog's counter
A to count the number of times where the two pins 15 and 16
have different logic levels. I let this counter run for ~ 10 sec.
Then I serial.dec(PHSA) back to the PC. Unfortunately that
value is never zero. To make matters worse that value is not
a constant.
I can imagine to dynamically adjust the PHSB value of the
signal generating cog until the phase difference between both
counters is getting (close to) zero but I hope there is a
better way to do this (perhaps start both counter at the
same time?) ...
Any ideas?
Cheers,
ul5255.
Comments
-Phil
In other cases (uploading the exact same code to the propeller) the signals are almost 180 degree phase-shifted.
The alignment is never 100% ...
Is this because it is essentially unpredictable when/how the PLL locks to the programmed frequency?
-ul5255
As long as the PLL multiplier is x1 or greater, that should work. If it's less than that, you're better off just going the NCO route, since you won't be able to predict the phase relationship.
-Phil
Here is the complete code, my bench-top frequency counter agrees that the
frequency is ~ 3.56MHz. My two channel scope and the cog#0
logic counter both show that occasionally one pin has the inverted
square wave of the other ...
I also completely removed the Serial code to rule out any side effects but
the result was the same.
-Phil
Thanks a lot, Phil !
-Phil