I could use some help with programming an MSP430. It's for a class assignment. I need to generate a sine wave, and I'm trying to do so by using the TimerA to change an output every 1/50th of the period. Im using the following setup:
int main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
TACCTL0 = CCIE;
TACTL = TASSEL_2 + MC_1 + ID_3 + TAIE; //CLK(1MHz) /8
TACCR0 = 25; //25-100 Hz 250-10Hz
P1DIR = 0x00;
P2DIR = 0xFF; //DAC Ouptut
P3DIR = 0x00; //ADC Input
P4DIR = 0x00; //Digital Input
P3SEL |= BIT6 + BIT7;
ADC10CTL0 = SREF_0 + ADC10SHT_3 + MSC + ADC10ON + ADC10IE;
ADC10CTL1 = INCH_7 + ADC10DIV_3 + CONSEQ_1;
ADC10AE0 |= 0xC0; //Turn on ADC of 3.6 and 3.7
ADC10DTC1 = 2;
double amp = 0;
double freq = 0;
unsigned int ADC[2];
for(;;)
{
wave_sel =P4IN;
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
ADC10SA = (unsigned int)ADC;
ADC10CTL0 |= ENC + ADC10SC;
freq = (double)ADC[0]/1023;
amp = (double)ADC[1]/1023;
TACCR0 = 25 + (freq*225);
dout *= amp;
dac_write(dout);
}
}
and an interrupt that has the following title:
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0(void)
{
But when I run the program, I can't get the interrupt to trigger. I can see the timer counting up in the debugger, and it resets once it hits TACCR0 like it should, but nothing in the interrupt occurs. I put a break point in, and it never hits it. Am I declaring the ISR wrong?
It looks like you have two interrupts in use: one for the capture compare on timer A0 (CCIE
) and also the timer A overflow (TAIE
). If you are getting stuck in the ISR_trap then that can be explained by the fact you do not have a handler for the timer A overflow interrupt.
If you do not intend to use the timer overflow then you need to change this line:
TACTL = TASSEL_2 + MC_1 + ID_3 + TAIE; //CLK(1MHz) /8
to this:
TACTL = TASSEL_2 + MC_1 + ID_3; //CLK(1MHz) /8
If you do intend to use that second interrupt for timer A overflow then you need to make sure you read the TAIV
register each time you enter the interurpt. There are multiple sources that cause that interrupt and that register tells you which one caused it. However, it will not be cleared until you read it (see section 12.2.6.2 TAIV, Interrupt Vector Generator in the MSP430 F2xx Family User's Guide).