Hello,
My ultimate goal is to generate a finite series of 20µs pulses at a frequency of 1kHz, but I am having trouble generating the necessary pulse width. My preliminary attempts have been with pulses spaced 50µs apart, and attempting 20µs pulse width. Once I have this working properly, I believe I can easily add the pulse counting and adjust the frequency/duty cycle.
I am using a MSP430G2553 and have been referencing the Datasheet and MSP430x2xx User Guide. From the Datasheet (p43) I am trying to output my signal on P1.1 so I am setting P1DIR.1 = 1, P1SEL.1 = 1, and P1SEL2.1 = 0. I believe this is all correct because I am getting a signal on P1.1 that behaves somewhat as expected.
My project is based on p372 of the User Guide. I am trying to user Timer A in Up mode to raise the pin high after counting up to TACCR1 and then resetting the pin when reaching TACCR0. For this I am using Output Mode 3 (Set/Reset). To make things easier to see on a oscilloscope, I have been setting TACCR0 = 50 and TACCR1 = 30. If I understand the diagram, when the clock is started it will count to TACCR1 (30), set the pin high, continue counting to TACCR0 (50), then reset the pin. This should result in a pulse width of 20 counts (equivalent to µs for my clock settings). While I am seeing a 50µs period, the pulse width is only 1µs (1 clock cycle). Additionally, changing the value of TACCR1 does not affect the output in any way. This is leading me to believe that I have forgotten to enable something.
My code and scope capture of the output is below. Any help is much appreciated.
#include <msp430g2553.h>
#define TIMER_OUT BIT1
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= TIMER_OUT; // set P1.1 to output direction
P1SEL |= TIMER_OUT; // set P1.1 function to TA0.0
TACCTL0 |= OUTMOD_3; // set output mode to Set/reset
TACCTL1 |= OUTMOD_3; // set output mode to Set/reset
TACCR0 = 50; // (µs)
TACCR1 = 30; // (µs)
TACTL = TASSEL_2 + MC_1; // set Timer_A source to SMCLK and start timer in UP mode
_BIS_SR(CPUOFF);
}
Best,
Anthony
