Hello All,
I want to trigger the 12-bit ADC (repeat single channel mode) using the timer of MSP430F5529. Timer is programmed to generate interrupt every 1.9 ms (it is working fine, verified with toggling of Red LED using oscilloscope) and should start the ADC conversion in its ISR. Once the conversion is done, ADC ISR should toggle the Green LED . In the debugging mode I can see that it is not entering in the ADC ISR routine . I am not able to locate the error. The program works fine without timer interrupt and configuring the ADC accordingly. It would be great if someone can pin point the mistake.
void setup()
{
pinMode(P1_0, OUTPUT); // Red LED
pinMode(P8_1, OUTPUT); //Green LED
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//for ADC initialization
P6SEL |= 0x01; // Enable A/D channel A0 p6.0
REFCTL0 &= ~REFMSTR; // Reset REFMSTR to hand over control to ADC12_A ref control registers
ADC12CTL0 = ADC12ON+ADC12REFON+ADC12SHT0_4+ADC12REF2_5V; //on+64 clock cycle
ADC12CTL1 =ADC12SHP+ADC12CONSEQ_2+ADC12SSEL_1; // TRIGGER FROM timer a , repeat single channel,ACLK for ADC
ADC12CTL1 =ADC12SHS_1; //timer source for sample and hold source select
ADC12IE = 0x01; //enable interrupt
for ( i=0; i<0x30; i++); // Delay for reference start-up to settle generator
// for Timer interrupt 1.9 ms
TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0= 63 ; //interrupting every 1.9ms
TA0CTL = TASSEL_1 + MC_1 + TACLR; // ACLK, upmode, clear TAR
__enable_interrupt(); // Enable interrupts.
__bis_SR_register(LPM0_bits + GIE);
}
void loop() { }
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR (void)
{
ADC12CTL0 |= ADC12ENC ; //Starts ADC every 1.9ms
P1OUT ^= 0x01; // Toggle P1.0 and P1.6 using exclusive-OR
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
ADC12CTL0 &= ~ADC12ENC;
results = ADC12MEM0 & 0x0FFF; //lower 12 bit result
digitalWrite(P8_1, !digitalRead(P8_1)); //toggle LED
}