Shop OBEX P1 Docs P2 Docs Learn Events
Question about CLKMODE — Parallax Forums

Question about CLKMODE

ReinhardReinhard Posts: 489
edited 2011-11-26 06:14 in Propeller 1
Hi,
should it be possible to change the CLKMODE at runtime.
with this piece of code, it seem's not:
#include "propeller.h"

#define P0 (1<<0)
#define RCFAST 0
#define RCSLOW 1

void main ()
{
    unsigned x = 0;
    DIRA |= P0;
    for(;;)
    {
        OUTA ^= P0;
        x++;
        if(x == 1000)
        {
            CLKMODE(RCFAST); 
        }
        if(x == 2000)
        {
            CLKMODE(RCSLOW); 
            x=0;
        }
    }
    
    
    

}


but with differnt parameters at loading the code:

propeller-load -pcom6 -D clkmode=RCSLOW -D clkfreq=20000 -r rcmode.elf
or
propeller-load -pcom6 -D clkmode=RCFAST -D clkfreq=120000000 -r rcmode.elf

I see an effect. (observe the pin with an oszi)

Maybe I have misunderstood this feature ?

Comments

  • ersmithersmith Posts: 6,100
    edited 2011-11-16 17:03
    It appears the CLKMODE() variable just changes the stored value in RAM, it doesn't actually execute the __builtin_propeller_clkmode() function to change the hardware. I'm not sure if this is deliberate or not -- I'm not as familiar with the propeller.h header file as others, so perhaps they can comment.

    On loading the code it does work because the Spin interpreter that boots gcc reads that variable and sets the clock mode based on it.

    Eric
  • jazzedjazzed Posts: 11,803
    edited 2011-11-16 17:17
    ersmith wrote: »
    It appears the CLKMODE() variable just changes the stored value in RAM, it doesn't actually execute the __builtin_propeller_clkmode() function to change the hardware. I'm not sure if this is deliberate or not -- I'm not as familiar with the propeller.h header file as others, so perhaps they can comment.

    On loading the code it does work because the Spin interpreter that boots gcc reads that variable and sets the clock mode based on it.

    Eric

    Yes, this is my bug. I'm opening an issue on it.

    I would call it CLKSET, but that has a different meaning in SPIN. Opinions?

    Thanks,
    --Steve
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-16 17:19
    jazzed wrote: »
    I would call it CLKSET, but that has a different meaning in SPIN. Opinions?
    What stops you from making it the same (2nd parameter, update clkfreq as well)?
  • jazzedjazzed Posts: 11,803
    edited 2011-11-16 17:56
    kuroneko wrote: »
    What stops you from making it the same (2nd parameter, update clkfreq as well)?
    I was thinking about that. It would be nice to have a CLKSET macro too.
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-16 18:04
    jazzed wrote: »
    I was thinking about that. It would be nice to have a CLKSET macro too.
    Clock related macros/fns will still be different in behaviour from SPIN. clkfreq and clkmode are r/o in SPIN (you can't assign to them by name, e.g. clkmode := $6F). To set them you have to use clkset. C seems to allow them to be set separately (provided I read the top post correctly, unless it's misused). This just needs documenting.
  • jazzedjazzed Posts: 11,803
    edited 2011-11-17 08:06
    Hi. Here's the plan for CLKMODE.

    CLKMODE will become a read-only macro like CLKFREQ.
    A macro clkset(mode, frequency) will be added.

    All macros that use a __builtin_propeller_* function are lower case.
    CLKMODE and CLKFREQ are variables that can be read or written.
  • ReinhardReinhard Posts: 489
    edited 2011-11-18 07:45
    jazzed wrote: »
    Hi. Here's the plan for CLKMODE.

    CLKMODE will become a read-only macro like CLKFREQ.
    A macro clkset(mode, frequency) will be added.

    All macros that use a __builtin_propeller_* function are lower case.
    CLKMODE and CLKFREQ are variables that can be read or written.

    Sounds good !
    Can not await next version :-)
  • ReinhardReinhard Posts: 489
    edited 2011-11-26 06:14
    Hi,

    Today I have downloaded the 0_1_9 version and the first experiment is the clkset demo,

    because just in time I finished a little hardware work with only a DIP40 Propeller chip and RS232 converter from MAXIM.

    No XTAL and no EEPROM currently in use. RCMODE only.

    The modified version, included in the demo pack, shows the effect of clockswitch better than my origin.

    (observed with an oszi ).

    Many Thanks to the Team !!!

    If I remember right ( for United States ) happy Thanksgiving.
    1024 x 1109 - 193K
Sign In or Register to comment.