Shop OBEX P1 Docs P2 Docs Learn Events
CLKSET(), syntax? — Parallax Forums

CLKSET(), syntax?

Tracy AllenTracy Allen Posts: 6,656
edited 2006-04-13 19:27 in Propeller 1
What is the proper syntax for CLKSET() in spin? It requires two parameters, and this snippet compiles:

clkset(xtal1 + pll16x ,5_000_000)
twiddle(5,20)
clkset(xtal1 + pll4x ,5_000_000)
twiddle(5,20)
clkset(xtal1 + pll16x ,5_000_000)
twiddle(5,20)
clkset(xtal1 + pll1x ,5_000_000)
twiddle(5,20)
clkset(xtal1 ,5_000_000)
twiddle(5,20)
clkset(RCfast,12_000_000)
twiddle(5,20)
clkset(RCslow,20_000)
twiddle(5,20)




But I am not sure, especially about the 2nd parameter, and in relation to RCfast and RCslow. rolleyes.gif

(Twiddle is just a test program for current drain at different frequencies.)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com

Comments

  • cgraceycgracey Posts: 14,133
    edited 2006-04-13 17:52
    CLKSET(mode, freq)

    'mode' is the 7-bit value which will be written to the global clock register in the HUB. This value is incompatible with the symbolic CONstants used to set up the initial clock mode (_CLKMODE = ...).

    'freq' is the actual internal clock frequency that will be in effect.

    Perhaps later we will harmonize these constants to be compatible with the 'mode' requirement. Well, on second thought, that·will not be·possible. This is because switching between clock modes is sometimes a process, where you must make the switch in two steps. For example, say you're running at 20KHz and you want to switch to 80MHz. You would first have to enable the crystal oscillator and PLL, but not switch to them immediately, because the crystal oscillator needs about 10ms to stabilize, worst case (the PLL takes only 10us, or so). So, you would have to wait for 10ms, and then make the final switch over to the PLL. This is covered in the last page(s) of the 'propellerguts.doc' file which was posted on this forum a few weeks ago.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2006-04-13 18:39
    Thanks, Chip. So are the following settings correct?
    clkset($00, 12_000_000) ' RCfast, nominal clock frequency is 12mhz
    clkset($01, 20_000) ' RCslow, nominal clock frequency is 20khz
    clkset($6F, 80_000_000) ' pll16x with 5mhz xtal, 2000 ohms 36pf, actual clock frequency is 80mhz

    Let's say I want the sequence to go from RCslow to pll16x. Do I need to do it in the following sequence:

    clkset($01, 20_000)    ' RCslow
      ' ... some time at low speed
    clkset($68, 20_000)  ' oscillator & pll warmup, still using RCslow
    waitcnt(cnt+200)  ' approx 10ms at 20khz (won't work, more than 200 clocks to intepret waitcnt?)
    clkset($6F,80_000_000) ' switch to pll16x, 80mhz
    



    Suppose that the task that needs to be performed at high speed does not depend on exact frequency. I just want it to wake up, perform a simple task as fast as possible and get back to sleep asap. Is there anything bad that will happen if I leave out the 10 millisecond warmup? It might be faster to switch to RCfast and back, but resonators can get up to speed pretty fast, and a response critical task might come first and then wait in software for a frequency critical task.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • parskoparsko Posts: 501
    edited 2006-04-13 18:43
    Chip,

    May I suggest you add the propellerguts.pdf file to the download section, or did I just miss it?

    -Parsko
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2006-04-13 18:56
    Here are URLs for the document and for the thread:
    http://forums.parallax.com/attachment.php?attachmentid=40588
    http://forums.parallax.com/showthread.php?p=572669

    Chip, how about this, to first switch to RCfast for response, while the xtal & pll warm up, then switch to them after the delay?

    clkset($01, 20_000)    ' using RCslow
      ' ... some time at low speed
    clkset($68,  12_000_000)  ' oscillator & pll warmup,  using RCfast in the interim
    ' response critical task goes here
    waitcnt(cnt+120_000)  ' approx 10ms at 12mhz 
    clkset($6F,80_000_000) ' switch to pll16x, 80mhz
    ' now can go to frequency critical and other tasks
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • cgraceycgracey Posts: 14,133
    edited 2006-04-13 19:26
    You got it!
    Tracy Allen said...
    Here are URLs for the document and for the thread:
    http://forums.parallax.com/attachment.php?attachmentid=40588
    http://forums.parallax.com/showthread.php?p=572669

    Chip, how about this, to first switch to RCfast for response, while the xtal & pll warm up, then switch to them after the delay?

    clkset($01, 20_000)    ' using RCslow
      ' ... some time at low speed
    clkset($68,  12_000_000)  ' oscillator & pll warmup,  using RCfast in the interim
    ' response critical task goes here
    waitcnt(cnt+120_000)  ' approx 10ms at 12mhz 
    clkset($6F,80_000_000) ' switch to pll16x, 80mhz
    ' now can go to frequency critical and other tasks
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • cgraceycgracey Posts: 14,133
    edited 2006-04-13 19:27
    That looks good, too! That will let you handle something quickly, then go to a faster, more accurate clock,·a little later.
    Tracy Allen said...
    Here are URLs for the document and for the thread:
    http://forums.parallax.com/attachment.php?attachmentid=40588
    http://forums.parallax.com/showthread.php?p=572669

    Chip, how about this, to first switch to RCfast for response, while the xtal & pll warm up, then switch to them after the delay?

    clkset($01, 20_000)    ' using RCslow
      ' ... some time at low speed
    clkset($68,  12_000_000)  ' oscillator & pll warmup,  using RCfast in the interim
    ' response critical task goes here
    waitcnt(cnt+120_000)  ' approx 10ms at 12mhz 
    clkset($6F,80_000_000) ' switch to pll16x, 80mhz
    ' now can go to frequency critical and other tasks
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
Sign In or Register to comment.