Shop OBEX P1 Docs P2 Docs Learn Events
Problems with different prop speeds — Parallax Forums

Problems with different prop speeds

CrosswindsCrosswinds Posts: 182
edited 2013-03-28 17:34 in Propeller 1
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

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

  • lonesocklonesock Posts: 917
    edited 2013-03-26 13:09
    Anytime you do a waitcnt( N + cnt ), if N < 381 that line will sit until the clock wraps, which takes a long time if not at PLL16x!

    Jonathan
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-26 13:13
    Well the thing is, the prop dont even do the first cycle (fast speed) on the breadboard prop. and as i said, it works on the demo board.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-26 14:50
    That's odd. I tried your program in a board I've been working on here and it ran fine.

    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.
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-26 15:49
    That's odd. I tried your program in a board I've been working on here and it ran fine.

    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?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-26 18:26
    Yes, I'd suspect a power supply issue, or something is holding it in reset. Is the serial cable or USB cable still connected?

    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.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-03-27 14:26
    I wrote that speed switching code you are using :-) it's always nice to see others using my stuff. I've used it for a long time, and have never had a problem (except mine says 381, not 351....maybe I fixed that at some point, and you have an old copy? not sure).

    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.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-03-27 14:45
    Here is my newest version, it now contains all of the possible speeds (though I could change the method names to be more fitting...)
    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
    
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-27 15:44
    Here's a condensed snippet for setting a crystal-based frequency:
    [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]
    
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-28 14:55
    Hello guys!

    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:
    CON
    _xinfreq = 5_000_000
    _clkmode = xtal1 + pll16x
    

    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?
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-03-28 14:59
    Crosswinds wrote: »
    ...as i understand, then its not possible to change clockspeed during runtime?

    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.
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-28 15:02
    Yes, i meant that, when you set clockspeed in the CON section, is it possible to change the clockspeed later on?

    Its so strange, since it can run on both internal and external oscillators on its own, but cant take any code that changes it..
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-28 17:34
    I ran you post#1 program on a board here, and it ran fine. I changed it so that it would flash a red led when running fast and a green led when running slow. Try it with just the two RC oscillators, see if it will make the transition from rcfast to rcslow and back. It seems like the issue with your breadboard setup might have something to do with starting up the crystal oscillator. Oh, and yes indeed, you can change clock speeds at run time even when an initial value is declared in the CON section.
    [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]
    
Sign In or Register to comment.