Shop OBEX P1 Docs P2 Docs Learn Events
clkset Question — Parallax Forums

clkset Question

smthrllsmthrll Posts: 4
edited 2013-10-30 09:29 in Learn with BlocklyProp
Wondering if somebody could show me what I'm missing on the 'clkset' function.
[I]#include "simpletools.h" 
[/I][I]int main()[/I]

[I]{[/I]
[I]   clkset(0b01101111,80000000);[/I]     //xtal1 + 16pll

[I]   while(1)[/I]

[I]    {[/I]

[I]         high(15);   [/I]

[I]         low(15);[/I]

[I]    } [/I]

[I]}[/I]

My goal was to flash an LED at 5MHz crystal speed, and then increase the speed to 80MHz with the above code, and measure the difference on an oscilloscope. There seems to be no change - obviously missing something. The length of a high pulse remains ~ 12us with no difference.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-10-29 19:10
    My guess would be that this is already as fast as it can go (depending on compiler options and memory model; what are they?). You could try lower dividers (e.g. PLL2) to see if there is a difference. IOW if you are already running at 80MHz then you wouldn't see any difference.
  • jazzedjazzed Posts: 11,803
    edited 2013-10-29 19:53
    You don't need to use clkset in the code. The loader does it for you.

    If you want to blink the LED at 80MHz, you will need to use a counter.

    The fastest you can blink an LED with an instruction loop is 10MHz (with an 80MHz system clock).
  • smthrllsmthrll Posts: 4
    edited 2013-10-30 09:05
    When you say " the loader does it for you", is that because the loader picks up on my board selection -board type: activity board? As far as compiler: C , memory model - I think it was CMM main RAM. So maybe it's as fast as possible with these settings (without using counters). Thanks for the suggestions.
  • jazzedjazzed Posts: 11,803
    edited 2013-10-30 09:29
    smthrll wrote: »
    When you say " the loader does it for you", is that because the loader picks up on my board selection -board type: activity board?

    Yes.
    smthrll wrote: »
    As far as compiler: C , memory model - I think it was CMM main RAM. So maybe it's as fast as possible with these settings (without using counters). Thanks for the suggestions.

    Actually, simple/small code can be re-written to be faster even in CMM mode, but just for generating a square wave (toggling a pin) using the counters is the best solution.

    This program toggles P15 at about 2.5MHz in CMM or LMM memory models. Fcache makes a small function run inside the COG. This can be even faster using in-line ASM.
    /**
     * This is the main FcacheToggle program file.
     */
    #include "simpletools.h"
    
    
    __attribute__((fcache)) void togglePin()
    {
      int mask = 1 << 15; // make a mask for toggling P15
      DIRA |= mask; // set pin to output
      while(1)
        OUTA ^= mask; // toggle pin
    }
    
    int main(void)
    {
      togglePin();
      return 0;
    }
    
Sign In or Register to comment.