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.

Using Timers on CC2430

Other Parts Discussed in Thread: TIMAC, CC2430

Hi all,

I'm new in all of this. I have acquired a CC2430DK and I've downloaded the TIMAC. I'm trying to configure a Timer with a timeout of 27us.

First I did it with osal_start_timerEx() but it only works with milli seconds, and i want to do it with microseconds.

So I'm trying to do it with Hal Timers. First, I've configured the timer in msa_Main.c like this:

HalTimerConfig (HAL_TIMER_0,
                  HAL_TIMER_MODE_NORMAL,
                  HAL_TIMER_CHANNEL_SINGLE,
                  HAL_TIMER_CH_MODE_OVERFLOW,
                  TRUE,
                  MSA_Main_TimerCallBack);

And then, when I press Key Down (S3) i've written:

HalTimerStart(HAL_TIMER_0,timeout);

My question is: where I have to write the code when HAL_TIMER_0 expires this timeout?

In hal_timer.c it says that HAL_TIMER_0 is HW_TIMER_3 and there is halProcessTimer3() but i've tried to write it there and it doesn't works properly.

I've also tried in MSA_Main_TimerCallBack() from msa_Main.c, but doesn't works.

Furthemore, i don't understand what CHANNELS mean, (Single, A,B or C). And the difference between Output Compare Mode and Input Compare Mode.

Can anyone help me?

 

Thank you so much.

  • Hi,

    I'm really interested in this question. I can't go forward in my project without this...

    I would appreciate any thing related to this.

     

    Thank you

  • T3 said:

    My question is: where I have to write the code when HAL_TIMER_0 expires this timeout?

    I would say that the code which dictates your actions you want to take based on this timer expiring is in the callback function passed to the Timer HAL via HalTimerConfg().
    In your example, this would be the MSA_Main_TimerCallBack().  This is the function which will get called by the Timer interrupt service routine, which for HAL_TIMER_0, is HW_TIMER_3, which corresponds to halTimer3Isr->halProcessTimer3().

     

    T3 said:

    In hal_timer.c it says that HAL_TIMER_0 is HW_TIMER_3 and there is halProcessTimer3() but i've tried to write it there and it doesn't works properly.

    I would not add your code in the hal_timer.c.  The Timer HAL (ie. hal_timer.c) provides a mechanism to call your specific function, via the callback routine passed to the Timer HAL via HalTimerConfg().

     

    T3 said:

    I've also tried in MSA_Main_TimerCallBack() from msa_Main.c, but doesn't works.

    I'm not sure why this wouldn't work, if you are checking which HAL_TIMER_x was the source of the call.

     

    T3 said:

    Furthemore, i don't understand what CHANNELS mean, (Single, A,B or C). And the difference between Output Compare Mode and Input Compare Mode.

    Only Output Compare Mode is supported.  Details of this mode are described in the CC2430 datasheet.

  • Thankyou for your answer Brandon.

    I've been trying, and i can't make it work. In MSA_Main_TimerCallBack, I've written:

    if ((timerId == HAL_TIMER_0))
        HalLedSet(2,HAL_LED_MODE_TOGGLE);

    And when I press joystick down (SW3):

    HalTimerStart(HAL_TIMER_0,10000000);

     

    I'm testing to toggle the LED On/Off after 10seconds since i've pressed joystick down. But right now when i press down, the LED switches automatically, so timer seems that's not working.

    The actual Timer configuration is:

      HalTimerConfig (HAL_TIMER_0,
                      HAL_TIMER_MODE_CTC,
                      HAL_TIMER_CHANNEL_SINGLE,
                      HAL_TIMER_CH_MODE_OUTPUT_COMPARE,
                      FALSE,
                      MSA_Main_TimerCallBack);

    Is exactly as OSAL_TIMER but with HAL_TIMER_0.

    I dont know what more to do i'm stuck here.

     

    Thank you

  • So, to debug this, are you able to place a break point in Components/hal/target/CC2430EB/hal_timer.c : halProcessTimer3() and see if this is entered?

    Also, if you step through the HalTimerConfig(), is it setting up the parameters correctly?

  • Thank you Brandon,

    I've been able to place a breakpoint in halProcessTimer3(), and I see that when the key is pressed (the timer starts counting) it enters in the first condition without waiting anytime:

    if (halTimerRecord[halTimerRemap(HAL_TIMER_0)].channelMode == HAL_TIMER_CH_MODE_OUTPUT_COMPARE)
      {
        if (TIMIF & TIMIF_T3CH0IF)
        {
          TIMIF &= ~(TIMIF_T3CH0IF);
          halTimerSendCallBack (HAL_TIMER_0, HAL_TIMER_CHANNEL_A, HAL_TIMER_CH_MODE_OUTPUT_COMPARE);
        }

    In the debugging mode it enters here twice every time i press the key, so the led switches to On the first time it enters, and the second time it is switched to Off.

    In normal mode the led is only switched to On. It's just something strange.

     

    I have stepped through the HalTimerConfig() and apparently everything works well, every parameter is set correctly and the function returns HAL_TIMER_OK.

    I have added HalTimerStop(HAL_TIMER_0) after switching the LED inside the CallBackFunction, it's correct?

     

    I really don't know what am I doing wrong.

  • Hi,

    I'm trying to implement a some code using TImac in cc2430.

    I need to broadcast the message to all the devices in the network(which are reachable) every 10minitues .

    so I used the following code to enable the Timer3 interrupt .

    void Call_Function_Babling (void)
    {

    // broad cast the message to all the devices in the network
    }

    main(){
    HalTimerConfig (HAL_TIMER_3,
                      HAL_TIMER_MODE_NORMAL,
                      HAL_TIMER_CHANNEL_SINGLE,
                      HAL_TIMER_CH_MODE_OVERFLOW,
                      TRUE,
                      Call_Function_Babling);
    HalTimerStart(HAL_TIMER_3,0x0FFF);
    }

    But it never comes to the callback function which i have used.

    Have i missed anything in the timer functions.?

    pls help me

    thanks and regards

    chethan