- Announcement about May 10th, 2018 update and your password.
Switching from 20kHz RCSLOW to XTAL1@5MHz or RCFAST
I didn't want to hijack John's thread
about generating 38kHz for an LED.
The following program alternates between RCSLOW and XTAL1 5MHz in a loop with about 1 second in each phase. Pin p3 is an indicator and trigger for the 'scope image attached, p3 is in red, and the 5MHz crystal output XO is in yellow. P3 goes high just before it enables the oscillator, and it goes low again once the Prop is operating at 5MHz. It happens that there is a 22ms delay before the first kick to the xtal, and then there is another 22+ ms delay before the chip switches over to operate at 5MHz. The crystal ramps up to speed in well under 10 ms. If you take out the two clkset instructions, the pair of outa instructions generate an pulse of less than 1ms duration. So my question is, why do the two clkset instructions take so long?
_clkmode = RCSLOW
dira := $ffff ' all pins are outputs
outa := $3000 ' all pins except 28,29 (scl,sda) are low
ctra := %00100<<26 ' NCO on p0
frqa := 32641751 ' 26.315us, 38.000.85 kHz o=.1us
outa~~ . ' pin p3 goes high to trigger 'scope
clkset(%0_01_01_001, 20_000) ' xtal 5MHz oscillator on, no PLL, still operating on RCslow
' no additional delay needed here in Spin '
clkset(%0_01_01_010, 5_000_000) ' switch to operate on 5MHz xtal, no PLL
waitcnt(clkfreq+cnt) . ' one second generating 38kHz.
clkset(%0_00_00_001, 20_000) ' drop to RCSLOW at ~20 KHz