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.

CC2540 Timer 3 Channel 1 problems



So i wrote the following function to configure channels 0 and 1 of timer 3. Problem is, when i configure channel 1, timer 3 doesn't start counting.

void ChannelInit(channelNum_t channel)
{ 
  PERCFG |= 0x20; // Timer 3 output alternative 2 location: channel 0 - P1.6, channel 1 - P1.7
  
  if (channel == R)
  {
    P1DIR |= 0x40;  // P1.6 configured as output
    P1SEL |= 0x40;  // P1.6 configured as peripheral pin (timer 3 output)

    T3CCTL0 &= ~0x40; // Channel 0 interrupt disabled
    T3CCTL0 &= ~0x20; // Set output on compare-up, clear on 0
    T3CCTL0 |=  0x18;
    T3CCTL0 |=  0x04; // Compare mode
    T3CCTL0 &= ~0x03; // No capture

    T3CC0 = 0xDE; // Compare value ~ YkHz @ 8MHz
  }
  else
  {
    P1DIR |= 0x80;  // P1.7 configured as output
    P1SEL |= 0x80;  // P1.7 configured as peripheral pin (timer 3 output)

    T3CCTL1 &= ~0x40; // Channel 1 interrupt disabled
    T3CCTL1 &= ~0x20; // Set output on compare-up, clear on 0
    T3CCTL1 |=  0x18;
    T3CCTL1 |=  0x04; // Compare mode
    T3CCTL1 &= ~0x03; // No capture

    T3CC1 = 0xDE; // Compare value ~ YkHz @ 8MHz
  }
  
  T3CTL &= ~0xA0; // Tick frequency / 4 => 8MHz
  T3CTL |=  0x40;
  T3CTL &= ~0x08; // Interrupts disabled
  T3CTL |=  0x03; // Up-and-down mode
  T3CTL |=  0x04; // Clear the counter
  T3CTL |=  0x10; // Start timer
}

Here are the contents of timer 3's registers after ChannelInit has been run with parameter R, and hence channel 0 was configured. Notice how T3CNT starts counting up immediately.

Here is the same thing after running ChannelInit with parameter L. Notice how registers have the same values, except for channels 0 and 1, which are reversed. Also note how T3CNT is 0 (and stays at 0) even thought T3CTL.START is 1. For some reason the timer just isn't working. Why?

  • Just a guess, but one thing to check is the peripheral IO mapping in the user guide. Maybe there is conflict with another peripheral.

  • The only peripheral which could claim the same pins as timer 3 alt. 2 is uart 1 in alt. 2 mode, which I don't use. Even if I did, that wouldn't explain why one of the channels works, and other doesn't.


    Also, the deeper problem I see here is that when channel 1 is configured, timer 3 doesn't run at all.

  • You have set Timer 3 in mode 3, which is described as "Up-and-down, repeatedly count from 0x00 to T3CC0 and down to 0x00". Since T3CC0 is 0x00, the counter will be "counting" from 0x00 to 0x00 and down to 0x00 again, which is the same as not counting at all.

    For Timer 1, 3, and 4, channel 0 has a special meaning, as it is used as the period register in addition to having compare capabilities.

  • Right, that explains why timer didn't run when only channel 1 was configured.


    My original question was why didn't channel 1 work even when channel 0 was configured along with it.
    Answer to that question is that channel 1 and channel 0 registers aren't exactly equal - T3CCTL1.CMP and T3CCTL0.CMP are very different and have been the source of my error.