Hi-
I've been playing around with my launchpad and am trying to use TimerA0 to read the ADC and timerA1 to run an LED PWM (with another interrupt to deal with switches). I've been using the code below, and while there is no problem with TimerA0 interrupt, the code never enters the TimerA1 interrupt service routine. When debugging, I pause the system and can see that the TA1IV register shows '0x0002', suggesting that the interrupt flag has be tripped.
What could I be missing? Thanks a ton!
Dave
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long voltageRaw; //Declared for ADC
volatile unsigned int i; //for main loop code
volatile unsigned int t_on; //Peltier time on
volatile unsigned int t_off; //Peltier time off
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigIO(void);
void ConfigADC10(void);
void ConfigTimerA(void);
void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigIO();
ConfigADC10();
ConfigTimerA();
_BIS_SR(GIE); //Enable global interrupts
while(1)
{
}
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}
void ConfigIO(void)
{
P1DIR = BIT6 + BIT0; // P1.6 and P1.0 outputs
P1OUT = 0; // LEDs off
P1IE |= BIT3 + BIT4; //P1.3 and P1.4 interrupt enabled.
P1IES |= BIT3 + BIT4; // Set interrupts for a rising edge
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_1 + ADC10DIV_0; // INCH1 means P1.1 (pin3), and ADC10 clock divider of 1
}
void ConfigTimerA(void)
{
CCTL0 = CCIE; //enable the counter compare reg 0 interrupt
CCR0 = 12000; //12000 represents 1 second at 12kHz
TA1CCTL0 = CCIE;
TA1CCTL1 = CCIE;
TA1CCR1 = 1000;
TA1CCR2 = 2000;
TA1CTL = TASSEL_1 + MC_2;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON; //config ADC for Vref+, Max sample and hold, turn on ref, turn on ADC
_delay_cycles(5); // Wait for ADC Ref to settle (at least 30uS)
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
P1OUT |= BIT6; // P1.6 on (green LED)
_delay_cycles(100); //delay for 13 ADC cycles (2.6uS with a 5MHZ ADC10CLK)
ADC10CTL0 &= ~ENC; // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
voltageRaw = ADC10MEM; // Read conversion value
P1OUT &= ~BIT6; // green LED off
CCR0 +=12000; // add 1 second to the timer
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A1(void)
{
switch( TAIV )
{
case 2:
P1OUT |= BIT0;
TA1CCR1 += 1000; // Add offset to CCR1
break;
case 4:
P1OUT &= ~BIT0;
TA1CCR2 += 1000;
break;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if(P1IFG & BIT3)
{
P1OUT |= BIT0; //Turn on Red LED
P1IFG &= ~BIT3; //P1.3 IFG Cleared
}
if(P1IFG & BIT4)
{
P1OUT &= ~BIT0; //Turn off Red LED
P1IFG &= ~BIT4; //P1.4 IFG Cleared
}
}