PDA

View Full Version : Question about CLKMODE



Reinhard
11-16-2011, 08:25 PM
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 ?

ersmith
11-17-2011, 12:03 AM
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

jazzed
11-17-2011, 12:17 AM
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

kuroneko
11-17-2011, 12:19 AM
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)?

jazzed
11-17-2011, 12:56 AM
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.

kuroneko
11-17-2011, 01:04 AM
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.

jazzed
11-17-2011, 03:06 PM
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.

Reinhard
11-18-2011, 02:45 PM
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 :-)

Reinhard
11-26-2011, 01:14 PM
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.