Phil Pilgrim (PhiPi)
01-08-2008, 11:52 AM
Here's a program whose behavior perplexes me:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
freq = 10000
advance = 6000
pina = 14
pinb = 15
PUB start
frqa := ((freq << 16) / clkfreq) << 16
ctra := constant(%00100 << 26) | pina
dira[pina]~~
frqb := ((freq << 16) / clkfreq) << 16
ctrb := constant(%00100 << 26) | pinb
dira[pinb]~~
repeat
phsb += advance
waitcnt(cnt + 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
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
freq = 10000
advance = 6000
pina = 14
pinb = 15
PUB start
frqa := ((freq << 16) / clkfreq) << 16
ctra := constant(%00100 << 26) | pina
dira[pina]~~
frqb := ((freq << 16) / clkfreq) << 16
ctrb := constant(%00100 << 26) | pinb
dira[pinb]~~
repeat
phsb += advance
waitcnt(cnt + 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