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.

CC2530 TIMER1 counter mode?

Other Parts Discussed in Thread: CC2530, CC2430

Hi,

I am using CC2530 and I want to ask can CC2530 work in counter mode? I've read something in datashezet and guide but I don't understand it quite well. Can I connect some binary counter to one of external Timer 1 pins and than count those events on rising or falling edge and ofter some time to read out that value?

Any help would be appreciated, thank you.

  • Hi,

     

    The timers in CC2530 can only count with an external clock source (the system clock or a divided variant of that). The peripheral Timer 1 pins can be used (as output) to generate a pattern or (as input) to capture the counter value when an edge occurs on the input pin. This means that it is unfortunately not possible to use the counter to count external events as you suggested.

    If your external events are sufficiently separated in time, you can use a GPIO interrupt to count the events (increment the counter in the ISR).

  • I made a typo here: The first sentence should of course be: The timers in CC2530 can only count with an internal clock source (the system clock or a divided variant of that).

  • Hi Hec,

    I'm trying implement the Timer1(16bit)  in counter mode in cc2530.. and it has to just count the inetrnal clock cycles and gives interrupt at every second .

    So I used The follwoing code but it didnt work;

    Kindly ho through the below code..

    pls let me know why it not going to the ISR function..?

    main()

    {

     halTimerInit();

    halTimerIntEnable();

     

    HAL_ISR_FUNCTION(T1_ISR,T1_VECTOR)
    {
      Function_todisplay();// Functiona has to called for every 2 sec

    }

    void halTimerInit(void)
    {
     uint16 compareValue=0xFFFF;
     
      // Set prescaler divider value to 128
     T1CTL |= 0x0C;

      // Set compare value
        T1CC0H = HI_UINT16(compareValue);
     T1CC0L = LO_UINT16(compareValue);

        // clear interrupt pending flag, disable interrupt
     T1CTL &= ~0x10; // T1CTL.OVFIF = 0
        IEN1  &=  ~0x02; // IEN1.T1EN = 0
    }

    void halTimerIntEnable(void)
    {
        IEN1 |=  0x02; // IEN1.T1EN = 1

     // Start timer in modulo mode
     T1CTL |= 0x02; // T1CTL.MODE = 10

    }

     

    void halTimer32kIntDisable(void)
    {
         IEN1  &=  ~0x02; // IEN1.T1EN = 0
    }

  • Hi,

    It seems that the code you are using is for CC2430, not CC2530. CC2530 does not have the OVFIF flag in the T1CTL register. Furthermore, it does not genereate an overflow interrupt in modulo mode. Even for CC2430, I cannot see that you clear the source interrupt flag in the ISR, unless this is hidden in the Function_todisplay routine.

    For CC2530, you must use the channel 0 interrupt instead of the overflow interrupt. It means that you need to replace the 3 lines in the end of halTimerInit by

      // clear interrupt pending flag
      T1STAT = ~0x01; //T1STAT.CH0IF = 0
      T1IE = 0;
      // Set compare mode, interrupt enabled for channel 0
      T1CCTL0 = 0x44;

    In HAL_ISR_FUNCTION, you need to add the following before calling Function_todisplay():

      // Clear interrupt flag
      T1STAT = ~0x01; //T1STAT.CH0IF = 0

    If you clear the OVFIF flag inside Function_todisplay(), you should remove it.

    I haven't tried out this code, so there could be typos, but this is basically what you need to do to port the code to CC2530.