Shop OBEX P1 Docs P2 Docs Learn Events
CLKSET in ASM — Parallax Forums

CLKSET in ASM

Helen CHelen C Posts: 34
edited 2010-05-11 00:36 in Propeller 1
Hi

I am using Propbasic for a new project that has the following clock set up.

DEVICE P8X32A, XTAL1, PLL16X
FREQ 80_000_000

However I need to put the prop chip into low power sleep mode every so often. I can use the clkset cmd in asm to do this but the prop manual states that you need to write the freqaddr to byte 0 in the main RAM.

So to put it in RCFAST mode the following command works:
\clkset %0000_0000 'set clock to RCFAST
\wrlong 0,#0 'write freqaddr to byte 0

but what I want to know is what freqaddr to use for RCSLOW and then also to put it back to the original settings.

\clkset %0110_1111 'set clock to XTAL1, PLL16X
\wrlong ?,#0 'write freqaddr to byte 0


Thanks and kind regards,

Helen

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-05-11 00:36
    Helen C said...
    However I need to put the prop chip into low power sleep mode every so often. I can use the clkset cmd in asm to do this but the prop manual states that you need to write the freqaddr to byte 0 in the main RAM.
    It doesn't actually say that but what is said could have been said better (including a small example). The datasheet is slightly better in that respect. What it boils down to is that any assembler program should update the soft copy of the clock frequency (long[noparse][[/noparse] 0]) and the clock mode (byte[noparse][[/noparse] 4]) in hub RAM. Having said that, this is only required when you also have SPIN code running which relies on those settings, so it's generally a good idea to do it.
    Helen C said...

    So to put it in RCFAST mode the following command works:
    \clkset %0000_0000 'set clock to RCFAST
    \wrlong 0,#0 'write freqaddr to byte 0
    If this is PASM, forget it. It may work but there is also a big chance that it won't. clkset takes one parameter in its destination slot. Meaning the %0000_0000 you specified is a cog register address. The lower 8 bits from that 32 bit value are written to the clock register. Also, the whole 32 bit value is subsequently written as the frequency value (wrlong). Let's look at an example:

                    org     0
    
    loader          jmpret  $, #:setup              ' once
                    ...
                    clkset  %0000_0000              ' set clock to RCFAST
                    wrlong  0,#0                    ' write freqaddr to byte 0
    


    The long at location 0 in cog memory is $5CFC000B (jmpret instruction). So what will happen is that the clock register has %0000_1011 written to it. Then the system frequency is announced as 1_560_018_955Hz. This is very unlikely to work.

    If you use PASM for this you can do something like this:

            clkset  :mode
            wrlong  :freq, #0
            wrbyte  :mode, #4
            ...
    :mode   long    %0000_0000
    :freq   long    12_000_000
    


    I'm sure you can figure out the other mode settings yourself. If you want to preserve the original values (e.g. current frequency) you'll have to read them from their appropriate location(s). The frequency value for RCSLOW is 20_000 (as used by the propeller tool). Also, if you transition to PLL based modes (e.g. from RCFAST to PLL16X) make sure you do this in two steps as described in manual and datasheet.
Sign In or Register to comment.