PHSA/PHSB access from Spin
Phil Pilgrim (PhiPi)
Posts: 23,514
Here's a program whose behavior perplexes me:
It starts two NCO clocks, both with the same frequency, with outputs on pins 14 and 15. In the repeat loop, phsb gets incremented by advance. But here's the weird thing: The amount by which the phase of pin 15, relative to that of pin 14, advances at each step (as seen on a scope) is independent of the value of advance, and equals about -3.7µs. What's up with that? Is Spin doing a read-modify-write on phsb, thereby reading phsb's shadow register? Well, I tested that theory by doing an explicit read, followed by a modify, then a write. 'Same results, with just a longer phase shift.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 1/8/2008 5:05:39 AM GMT
[b]CON[/b] [b]_clkmode[/b] = [b]xtal[/b]1 + [b]pll[/b]16x [b]_xinfreq[/b] = 5_000_000 freq = 10000 advance = 6000 pina = 14 pinb = 15 [b]PUB[/b] start [b]frqa[/b] := ((freq << 16) / clkfreq) << 16 [b]ctra[/b] := constant(%00100 << 26) | pina [b]dira[/b][noparse][[/noparse]pina]~~ [b]frqb[/b] := ((freq << 16) / clkfreq) << 16 [b]ctrb[/b] := constant(%00100 << 26) | pinb [b]dira[/b][noparse][[/noparse]pinb]~~ [b]repeat[/b] [b]phsb[/b] += advance [b]waitcnt[/b]([b]cnt[/b] + clkfreq * 2)
It starts two NCO clocks, both with the same frequency, with outputs on pins 14 and 15. In the repeat loop, phsb gets incremented by advance. But here's the weird thing: The amount by which the phase of pin 15, relative to that of pin 14, advances at each step (as seen on a scope) is independent of the value of advance, and equals about -3.7µs. What's up with that? Is Spin doing a read-modify-write on phsb, thereby reading phsb's shadow register? Well, I tested that theory by doing an explicit read, followed by a modify, then a write. 'Same results, with just a longer phase shift.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 1/8/2008 5:05:39 AM GMT
Comments
have you tried
ctrb:= (constant (%00100 << 26)) | pinb
or····
ctrb := %00100<< 26 | pinb
just some guesses that I would try..
ron Mel oz
Post Edited (OzStamp) : 1/8/2008 5:36:38 AM GMT
-Phil
The value, advance=6000 is practically nothing in terms of phase, because phsb would be advancing by 524_288 (=2^19) every 12.5 ns. It should take a value of advance=155_189_248 to evoke a 3.7 µs phase advance. That is about 1/28 of the full cycle. Did you try numbers up in that range or higher, and still the same result?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Steven
A phase retardation of x is just a phase advance of period - x, so that doesn't bother me, since I assume there's some Spin overhead that also gets added in.
I did try some numbers orders of magnitude bigger than 6000, but you're right: they weren't nearly big enough to make a noticeable difference. Now that I've tried some really, really big numbers, I'm seeing some effective differences. Thanks for making me revisit my assumptions!
-Phil
So you practically discard all the hardware induced PHS increments during that time, giving you the observed retardation. When beeing morte explicite that
PHSA += advance
this retardation will increase of course, as you already noticed.