Shop OBEX P1 Docs P2 Docs Learn Events
Changing prop speed at runtime? — Parallax Forums

Changing prop speed at runtime?

__red____red__ Posts: 470
edited 2013-09-15 05:18 in Propeller 1
I want to bigbang VGA if a user does some kind of "secret interaction" with the badge.

The badge currently runs at 40Mhz. VGA requires 80Mhz in every version I've seen. Is it possible to up the clockspeed at runtime (with the understanding that I would have to account for that in other areas of the code).

If not at runtime, could I conceivably modify the image in the eeprom and do a hard-reset? Is that part of the image documented somewhere?

We're running at 40Mhz to try and conserve battery.

Thanks,



Red

Comments

  • Heater.Heater. Posts: 21,230
    edited 2013-09-14 08:17
    For sure you can, just write to the appropriate registers to change the clock. I forget what they are called now as I have never done this.

    Many objects are written to work with different clock frequencies. It maybe necessary to restart them on a frequency change so they recalculate their delays and such. You will have to check the objects you want to use.
  • Heater.Heater. Posts: 21,230
    edited 2013-09-14 08:18
    If you really want to save battery why not just stop the cogs you don't need all the time?
  • Mike GreenMike Green Posts: 23,101
    edited 2013-09-14 09:22
    The CLKSET statement in Spin will change the clock source and speed. The description in the Propeller Manual explains how to use it, particularly the precautions you need when switching to the crystal oscillator from one of the RC clocks. As Heater mentioned, you have to be careful about what your various objects assume regarding the clock and remember that cogs drop into a very low power mode when they're stopped or waiting for something using WAITCNT or WAITPxx. If all cogs are waiting or stopped, only the hub is drawing significant current. The Propeller Manual has graphs showing the current drain vs. clock speed for the hub and cogs.
  • Mark_TMark_T Posts: 1,981
    edited 2013-09-14 12:29
    Mike Green wrote: »
    The CLKSET statement in Spin will change the clock source and speed. The description in the Propeller Manual explains how to use it, particularly the precautions you need when switching to the crystal oscillator from one of the RC clocks. As Heater mentioned, you have to be careful about what your various objects assume regarding the clock and remember that cogs drop into a very low power mode when they're stopped or waiting for something using WAITCNT or WAITPxx. If all cogs are waiting or stopped, only the hub is drawing significant current. The Propeller Manual has graphs showing the current drain vs. clock speed for the hub and cogs.

    I believe the best approach in Spin is to use the methods in the Clock object to change settings since it will do the right thing about
    allowing for settling times after changing PLL and OSC settings. I believe the best practice if changing PLL multiplier is switch to
    RCFAST before changing PLL, then waiting an appropriate amount before switching back - until the PLL establishes lock you
    have no guarantee the processor won't be overclocked and go haywire I fear.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-09-14 17:45
    Mark_T wrote: »
    I believe the best approach in Spin is to use the methods in the Clock object to change settings since it will do the right thing about
    allowing for settling times after changing PLL and OSC settings. I believe the best practice if changing PLL multiplier is switch to
    RCFAST before changing PLL, then waiting an appropriate amount before switching back - until the PLL establishes lock you
    have no guarantee the processor won't be overclocked and go haywire I fear.

    Hmmm, that bit about switching PLL modes got me to thinking so I thought I'd try out an exercise in Tachyon as I can interactively change the clock, so I type a little code like this at the serial terminal:
    4 0 DO I CLK LOOP
    which just selects the PLL multipliers x1 x2 x4 and finally x8 (3 CLK) as I work with 10MHz crystals. Well that worked fine so let's really exercise it:
    #100,000 FOR 4 0 DO I CLK LOOP NEXT
    That took quite a few seconds but eventually came back and said "ok" so all's well.
    Now I have left it on the bench with:
    BEGIN 4 0 DO I CLK LOOP SPINNER ESC? UNTIL
    which will repeat the CLK loop with a little spinning prompt so I know it's alive until I hit an escape key
    (still running)
  • Mark_TMark_T Posts: 1,981
    edited 2013-09-14 19:06
    Maybe I'm just being over-cautious - it depends how the PLL division switching happens and I can only guess about that - someone
    here will actually know I suspect. The docs are clear that merely switching the clock between stable sources is guaranteed, but I'm
    not sure about whether changing the PLL divisor counts as switching between sources or reconfiguring the PLL such that it needs
    to stabilise again.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-09-14 19:39
    Mark_T wrote: »
    Maybe I'm just being over-cautious - it depends how the PLL division switching happens and I can only guess about that - someone
    here will actually know I suspect. The docs are clear that merely switching the clock between stable sources is guaranteed, but I'm
    not sure about whether changing the PLL divisor counts as switching between sources or reconfiguring the PLL such that it needs
    to stabilise again.

    Just in case I also ran a random PLL change with this bit of code:
    BEGIN RND 3 AND DUP CLK 3 = IF 3 PINSET SPINNER ELSE 3 PINCLR THEN #P31 PIN@ 0= UNTIL 3 CLK
    So it's a random change and the spinner will update only when it's back at normal speed and It's still running although sometimes when I run it there is a glitch. So I checked it again with a continuous switch between slowest and fastest speeds:
    BEGIN 0 CLK 3 CLK SPINNER AGAIN
    Which appears to run fine but I have had the very rare and occasional glitch (you only need one) too which might indicate that some caution needs to be exercised. I will try this out using RCFAST mode in-between to see if it is totally reliable.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-09-14 19:59
    The issue with switching clock sources involves switching from one of the internal sources like RCSLOW or RCFAST to one of the external sources when the clock oscillator is off. It takes about 10ms for the clock oscillator to start up and become stable and you have to continue to run off RCSLOW or RCFAST for that 10ms while the clock oscillator stablizes. If the clock is running, you can switch anytime you want between any of the clock sources (PLLxxX or RCxxxx). You'll get a one clock cycle "glitch" (short cycle), but there's no way to avoid that. As of the next full clock cycle from the new source, it'll all be good.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-09-15 05:18
    I've found that changing PLL modes (always with the crystal oscillator running) can indeed glitch the Prop, it might only be one in a million chance but it happens. So I tried switching to RCFAST before changing PLL modes and that hasn't missed a beat at all.
    BEGIN RND 3 AND DUP RCFAST CLK 3 = IF SPINNER THEN AGAIN
Sign In or Register to comment.