Problems with different prop speeds
Hello!
The other day i was experimenting with different clockspeeds in a project of mine. (battery optimized)
Im shifting between, full 80mhz speed, down to slow speed using internal oscillator. After adding that to my code, it stopped working. Thought i did something wrong with the adaptation so i wrote a small LED toggle program to see if that worked. but it didnt.
Now the funny part is, the code works if i load it to my prop demo board, or my big pro developmentboard. but not if i have a prop on a breadboard setup. (have the fundamentals kit)
on that one it just dont work. It works just fine if i dont have the clockspeed shifting code and i set the clockspeed in the CON segment in the beginning of the code.
Please see the code. I did find the routines for change clockspeed on the forums
The other day i was experimenting with different clockspeeds in a project of mine. (battery optimized)
Im shifting between, full 80mhz speed, down to slow speed using internal oscillator. After adding that to my code, it stopped working. Thought i did something wrong with the adaptation so i wrote a small LED toggle program to see if that worked. but it didnt.
Now the funny part is, the code works if i load it to my prop demo board, or my big pro developmentboard. but not if i have a prop on a breadboard setup. (have the fundamentals kit)
on that one it just dont work. It works just fine if i dont have the clockspeed shifting code and i set the clockspeed in the CON segment in the beginning of the code.
Please see the code. I did find the routines for change clockspeed on the forums
Pub Start
DIRA[16]~~
repeat
_rc_to_fast_prop
repeat 10
!outa[16]
waitcnt(clkfreq*1 +cnt)
_rcslow_prop
repeat 10
!outa[16]
waitcnt(clkfreq*1 +cnt)
''Below follows clock management routines found on parallax forums.
PRI _rcslow_prop
'' put propeller into slowest power save speed (using internal oscilator)
clkset(%0_0_0_00_001, 20_000) ' ~20kHz no PLL
PRI _rcfast_prop
'' put propeller into ~12Mhz (using internal oscilator)
clkset(%0_0_0_00_000, 12_000_000) ' ~12MHz no PLL
PRI _rc_to_slow_prop
'' put propeller into slowest power save speed (using XTAL), intended to be used after propeller was put in rcslow/rcfast mode
clkset(%0_0_1_01_001, 20_000) ' turn on crystal, but don't use it
waitcnt(351 + cnt) ' wait [at least] 10ms for PLL/crystal to stabilize
clkset(%0_0_1_01_010, 5_000_000) ' 5MHz no PLL
PRI _rc_to_med_prop
'' put propeller into a medium speed (20MHz), intended to be used after propeller was put in rcslow/rcfast mode
clkset(%0_1_1_01_000, 12_000_000) ' turn on PLL/crystal, but don't use it
waitcnt(120000 + cnt) ' wait 10ms for PLL/crystal to stabilize
clkset(%0_1_1_01_101, 20_000_000) ' 20MHz
PRI _rc_to_fast_prop
'' put propeller into a fast speed (80MHz), intended to be used after propeller was put in rcslow/rcfast mode
clkset(%0_1_1_01_000, 12_000_000) ' turn on PLL/crystal, but don't use it
waitcnt(120000 + cnt) ' wait 10ms for PLL/crystal to stabilize
clkset(%0_1_1_01_111, 80_000_000) ' 80MHz
PRI _slow_prop
'' put propeller into slowest power save speed (using XTAL)
clkset(%0_0_1_01_010, 5_000_000) ' 5MHz no PLL
PRI _slow_to_med_prop
'' put propeller into a medium speed (20MHz), intended to be used after propeller was put in slow mode
clkset(%0_1_1_01_010, 5_000_000) ' turn on PLL, but don't use it
waitcnt(500 + cnt) ' wait 100us for PLL to stabilize
clkset(%0_1_1_01_101, 20_000_000) ' 20MHz
PRI _slow_to_fast_prop
'' put propeller into a fast speed (80MHz), intended to be used after propeller was put in slow mode
clkset(%0_1_1_01_010, 5_000_000) ' turn on PLL, but don't use it
waitcnt(500 + cnt) ' wait 100us for PLL to stabilize
clkset(%0_1_1_01_111, 80_000_000)

Comments
Jonathan
Like Jonathan says, you have to watch out for the time it takes to execute code, spin code especially at 20kHz. For example, if you replace clkfreq+cnt with clkfreq/64+cnt in the lo-speed section, it will stop dead for an eternity.
Hello!
Yes it is real strange! It seems like it wont run on the internal oscillator for some reason. Could it be a power-supply issue? It is the only difference i can see in the breadboard setup and the PDB!
Yes i need to find a another way than waitcnt. I need it to " sleep" for approx 5 minutes, prefferdebly in low power mode, since it will need to save batteries!
Though this code seem to work for 1 sec though?
For low power I have an RTC chip that puts out a hearbeat signal to the Prop. The program enters the low-power loop with the number of seconds to wait until the next activity, and then the loop itself simply counts the tick-tock. Mostly sitting there in waitpne. Occasionally blinks an led.
I've done this before on breadboards, double check you crystal/oscillator connection, if there's a problem it will still program just fine (because it uses the internal oscillator), but as soon as it is instructed to use the xtal, it halts, because there are no cycles coming in.
PRI _rcslow_prop '' put propeller into slowest power save speed (using internal oscilator) clkset(%0_0_0_00_001, 20_000) ' ~20kHz no PLL PRI _rcfast_prop '' put propeller into ~12MHz (using internal oscilator) clkset(%0_0_0_00_000, 12_000_000) ' ~12MHz no PLL PRI _rc_to_slow_prop '' put propeller into slowest power save speed (using XTAL), intended to be used after propeller was put in rcslow/rcfast mode clkset(%0_0_1_01_001, 20_000) ' turn on crystal, but don't use it waitcnt(381 + cnt) ' wait [at least] 10ms for PLL/crystal to stabilize clkset(%0_0_1_01_010, 5_000_000) ' 5MHz no PLL PRI _rc_to_medslow_prop '' put propeller into a medium-slow speed (10MHz), intended to be used after propeller was put in rcslow/rcfast mode clkset(%0_1_1_01_001, 20_000) ' turn on PLL/crystal, but don't use it waitcnt(381 + cnt) ' wait [at least] 10ms for PLL/crystal to stabilize clkset(%0_1_1_01_100, 10_000_000) ' 10MHz PRI _rc_to_med_prop '' put propeller into a medium speed (20MHz), intended to be used after propeller was put in rcslow/rcfast mode clkset(%0_1_1_01_000, 12_000_000) ' turn on PLL/crystal, but don't use it waitcnt(120000 + cnt) ' wait 10ms for PLL/crystal to stabilize clkset(%0_1_1_01_101, 20_000_000) ' 20MHz PRI _rc_to_medfast_prop '' put propeller into a medium-fast speed (40MHz), intended to be used after propeller was put in rcslow/rcfast mode clkset(%0_1_1_01_000, 12_000_000) ' turn on PLL/crystal, but don't use it waitcnt(120000 + cnt) ' wait 10ms for PLL/crystal to stabilize clkset(%0_1_1_01_110, 40_000_000) ' 40MHz PRI _rc_to_fast_prop '' put propeller into a fast speed (80MHz), intended to be used after propeller was put in rcslow/rcfast mode clkset(%0_1_1_01_000, 12_000_000) ' turn on PLL/crystal, but don't use it waitcnt(120000 + cnt) ' wait 10ms for PLL/crystal to stabilize clkset(%0_1_1_01_111, 80_000_000) ' 80MHz PRI _slow_prop '' put propeller into slowest power save speed (using XTAL), intended to be used when propeller already using XTAL clkset(%0_0_1_01_010, 5_000_000) ' 5MHz no PLL PRI _slow_to_medslow_prop '' put propeller into a medium speed (10MHz), intended to be used after propeller was put in slow mode clkset(%0_1_1_01_010, 5_000_000) ' turn on PLL, but don't use it waitcnt(500 + cnt) ' wait 100us for PLL to stabilize clkset(%0_1_1_01_100, 10_000_000) ' 10MHz PRI _slow_to_med_prop '' put propeller into a medium speed (20MHz), intended to be used after propeller was put in slow mode clkset(%0_1_1_01_010, 5_000_000) ' turn on PLL, but don't use it waitcnt(500 + cnt) ' wait 100us for PLL to stabilize clkset(%0_1_1_01_101, 20_000_000) ' 20MHz PRI _slow_to_medfast_prop '' put propeller into a medium-fast speed (40MHz), intended to be used after propeller was put in slow mode clkset(%0_1_1_01_010, 5_000_000) ' turn on PLL, but don't use it waitcnt(500 + cnt) ' wait 100us for PLL to stabilize clkset(%0_1_1_01_110, 40_000_000) ' 40MHz PRI _slow_to_fast_prop '' put propeller into a fast speed (80MHz), intended to be used after propeller was put in slow mode clkset(%0_1_1_01_010, 5_000_000) ' turn on PLL, but don't use it waitcnt(500 + cnt) ' wait 100us for PLL to stabilize clkset(%0_1_1_01_111, 80_000_000) ' 80MHz[SIZE=1][FONT=courier new]PRI clk_xtal(MHz) ' for _xinfreq=5MHz, & MHz= 5,10,20,40,80 if MHz == 5 clkset(%0_01_01_010, 5_000_000) ' switch xtal, no pll else clkset(%0_11_01_000 | >|(MHz/5)+2, MHz*1_000_000) ' xtal+pll at MHz [/FONT][/SIZE]Thanks you very much for your help.
And bobb, your routines is nice to learn from!
But i still have the problem with the breadboard setup.
the code runs if i set:
first.
Also if i dont set anything at all.
But if i include the speed routines, it does not start. (It does if i leav the CON in, but as i understand, then its not possible to change clockspeed during runtime?)
Hope you guys can follow me!
Seems like there is no problem with neither external or internal oscillators?
It is definitely supposed to be possible. I do it all the time in a large project I work on. There has got to be something electrically wrong if the same software works on your dev board, but not your breadboard. I would explore that more.
Its so strange, since it can run on both internal and external oscillators on its own, but cant take any code that changes it..
[SIZE=1][FONT=courier new]repeat _rcfast_prop ' instead of _rc_to_fast_prop outa[14]~ ' repeat 10 !outa[13] ' red flash waitcnt(clkfreq/2 +cnt) _rcslow_prop outa[13]~ repeat 10 !outa[14] ' green flash waitcnt(clkfreq/2 +cnt)[/FONT][/SIZE]