This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How do you set up the sleep timer compare value in CC2530?

Other Parts Discussed in Thread: CC2530

how do you set up the sleep timer compare value in CC2530? Would you please help me to find out what is wrong here? Thanks a lot. I set the ST2:ST1:ST0 to 0x200000, I can see the value in ST0, ST1, ST2 is changing while the device is running. But it can not set the flag STIF to 1 when the value pass 0x200000. Before I set up the sllep timer compare value I did the following: // clear sleep timer interrupt flag STIF = 0; // enable the sleep timer EA=1; STIE=1;

  • There are two things you need to be aware of:

    1. You should check that STLOAD is 1 before you write the compare value. This is only an issue if you had written another compare value shortly before a new one.
    2. You must write ST0 as the last of your registers, as writing to ST0 makes the whole ST2:ST1:ST0 apply.

    So the following setup should work:

    // Set sleep timer compare value
    while (STLOAD == 0);
    ST2 = 0x20;
    ST1 = 0x00;
    ST0 = 0x00;
    // Enable sleep timer interrupt
    STIF = 0;
    STIE = 1;
    EA = 1;

     

  • I want to use the sleep timer in both active mode and PM2 mode to keep time. Say, I want the MCU work in active mode for 3 seconds and to go PM2 mode, then after 5 seconds back to active mode. Is it possible to do this job? If so, please let me know how to do it.

  • Yes, that's no problem. The sleep timer runs uninterrupted regardless of the power mode, and you will get an interrupt when the compare event occurs. How do you plan to time the time in active mode? It this just staying in active mode until the processing is done, or do you plan to use a timer for it? The best way of doing it is probably to either base it on when processing/radio operations are done, or to use a different timer for timing the time in active mode.

    If so, whenever you wake up, you can just add 8 s (262144 ticks) to the compare time vs. the last compare time you wrote and write that value to the sleep timer registers. You then go to PM2 when you are done in active mode, and the interrupt will wake you up. In case you stayed too long in active mode and never went too sleep, you would still get the sleep timer interrupt, which could then help you deal with that situation.

    But if you for some reason want to use the sleep timer for timing the time in active mode (in this case, I suppose you will be doing some operation just before you go to PM2), you would add 3 s to your last compare value when you wake up. When the next sleep timer IRQ occurs, you do the operation you need to do, add 5 s to the sleep timer compare value, and go to sleep. You will then wake up at the next sleep timer IRQ. Note that you must not go to sleep from inside the sleep timer interrupt routine, as you will then not be able to wake up again. (If you go to sleep from inside an ISR, you can only be waked by interrupts having a higher priority than the ISR from which you went to sleep.)

  • in sleep timer PM2 for 5second of cc2530 other timer 1 for 100milisecond, is timer 1 values are preserved or not??

    Ever time i am transmitting a packet waiting for 100milisec timeout to receive an acknowledgement ,

    then going to sleep for 5sec is my timer 1 value is lost??

  • Timer 1 is stopped while the system enters PM2. This is because the high-speed oscillator stops in that mode, and Timer 1 runs off the high-speed oscillator (possibly divided). If I am not mistaken, the configuration and  timer value is preserved while the system is in PM2.

    This means that Timer 1 will have the same counter value when you wake up from PM2 that it had when you went into PM2. Since a lot of time passes during that period, this is probably of little interest, and you can just as well stop Timer1 before going to PM2 and restart it when coming up.

  • Hi,

    I am beginner to cc2530 codeing,can any one plz tell me:

    What is difference between halMcuWaitMs(100) and delay(100) in CC2530?

    Thanks in Advance.

  • I don't see these two APIs, halMcuWaitMs and delay, in ZStack. Where do you see these 2 APIs?

  • Sir,

    Here with the code, i took it from ZigBee compliant protocol stack for IEEE 802.15.4 products .

    #include "clock.h"
     
     
     
    /******************************************************************************
        Filename: clock.c
     
        This file defines clock related functions for the CC2530 family
        of RF system-on-chips from Texas Instruments.
     
    ******************************************************************************/
     
    #include "types.h"
     
    //Custom delay function---NOT reccomended
    void delay(unsigned long int cnt);
     
    //DELAY FUNCTION
    void delay(unsigned long int cnt)
    {
        volatile int i;
        for(i=0;i < cnt;i++)
        {
                i++;
                i--;
        }
    }  
     
    /***********************************************************************************
    * @fn          halMcuWaitUs
    *
    * @brief       Busy wait function. Waits the specified number of microseconds. Use
    *              assumptions about number of clock cycles needed for the various
    *              instructions. This function assumes a 32 MHz clock.
    *
    *              NB! This function is highly dependent on architecture and compiler!
    *
    * @param       uint16 usec - number of microseconds delays
    *
    * @return      none
    */
    #pragma optimize=none
    void halMcuWaitUs(uint16 usec)
    {
        usec>>= 1;
        while(usec--)
        {
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
            NOP();
        }
    }
    /***********************************************************************************
    * @fn          halMcuWaitMs
    *
    * @brief       Busy wait function. Waits the specified number of milliseconds. Use
    *              assumptions about number of clock cycles needed for the various
    *              instructions.
    *
    *              NB! This function is highly dependent on architecture and compiler!
    *
    * @param       uint16 millisec - number of milliseconds delay
    *
    * @return      none
    */
    #pragma optimize=none
    void halMcuWaitMs(uint16 msec)
    {
        while(msec--)
            halMcuWaitUs(1000);
    }
     

  • I still can't find those source codes that you posted in any ZStack version on my hand. From your post, halMcuWaitUs should work but not accurate because it use nop to estimate elapsed time. About delay function, I don't think it will work   . Because it puts  i-- right after i++ and this makes I unchanged , which means it is dead locked in for loop.

  • Hi Vishal,

    If you want to delay microseconds in ZStack, please use Onboard_wait() API which is defined in Onboard.h/Onboard.c.