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?