Tool/software: Code Composer Studio
Hello,
I am using the ADC12 of the MSP430F6638. I need a 100Hz sample rate ADC, and the 100Hz is generated by timer. Otherwords, a 100Hz signal is generated by timer to trigger the ADC's sample and conversion. I am using the up mode for the timer and the toggle and reset mode.
I would like in my program at each rising edge of the toggle and reset signal and so the timer signal to have an interrupt where I could enable and start the ADC12 conversion. I'm not sure at all if this seems to be correct but here is what I tried :
******************************* Configuring 100 Hz timer signal ************************************
P1SEL|=BIT1; //SELECT P1.1 AS TA0 and not I/O where we set the period of the timer signal
P1DIR|=BIT1;
P1SEL|=BIT2; //SELECT P1.2 AS TA0 output and not I/O where we set the duty cycle of the timer signal
P1DIR|=BIT2;
TA0CCR0 = 320 - 1; // 100hz sampling frequency
TA0CCR1 = 295; // duty cycle not important it's the period which is important
TA0CCTL1 = OUTMOD_2; // out mode 2
TA0CTL = TASSEL_1 + TACLR+ MC_1; // ACLK, up mode
TA0CCTL1|= CCIE; // enable interrupt
1) Here should I enable an interrupt on the P1.2 pin where we set the duty cycle of the signal or on the P1.1 pin where we set the period of the signal ? In other words it's TA0CCTL1|= CCIE or TA0CCTL0|= CCIE ?
************* Interrupt routine **********************
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_CCR0_ISR(void){
ADC12CTL0 |= ADC12ENC|ADC12SC; // enable and start conversion
}
2) Is this the correct way to write the interrupt routine ? Is it right as it's written or it's __interrupt void TIMER0_CCR1_ISR (CCR0 or CCR1) ? Is it TIMER0_A0 considering my configuration of timer above ? Do I have to clear the interrupt flag in the interrupt or it is cleared automaticaly ?
3) Also i saw in many examples this _BIS_SR(GIE). Is this important to use ? I mean with the code i have written above am I going to enable and start a new conversion each rising edge of my timer signal or there is some mistakes ?
4) My last question is also about interrupt but this time for ADC12. I also need in my program to have an interrupt each time a conversion is completed. To do this I wrote the interrupt routine where I set a variable equal to 1 so I can read outside the interrupt the ADC12MEM5 (i use ADC5) by testing in the main program if this variable is equal to 1 and if yes I read the ADC12MEM5 register and the variable become 0. But also here i'm not sure at all if it's correct and if I have to use the _BIS_SR(GIE); command. Here is my code.
************************* ADC12 CONFIGURATION ********************************
P6SEL|=BIT5; //SELECT P6.5 AS ADC and not I/O
ADC12CTL0 &= ~ADC12ENC; // ADC12 disabled
ADC12CTL0 = ADC12REFON + ADC12ON + ADC12REF2_5V + ADC12SHT0_2; // Sample time 16, around 16/4.8MHz = 3.3us, reference 2.5 V, reference on and ADC12 on
ADC12CTL1 = ADC12SHP + ADC12SHS_1 + ADC12DIV1; // enable sample timer, ADC clock from MODCLK, trigger source 1 timer
ADC12MCTL6 = ADC12SREF_1 + ADC12INCH_5; // ADC5
ADC12IE = ADC12IE0;
Here I am not sure at all about the interrupt enable command since it talks about a specific bit whereas in my program i need an interrupt not on a specific bit but when a conversion is completed (when the 12 bits word is ready to be read).
****************************** INTERRUPT ROUTINE *****************************************
#pragma vector = ADC12_VECTOR
__interrupt void adc12_ISR(void)
{
write_mem = 1;
}
Since I am using the ADC5 (P6.5 pin of MSP430F6638) should number 5 appear somewhere in the interrupt name or as it's written it's correct ?
***************** MAIN PROGRAM ************************
if (write_mem == 1)
{
write_mem = 0;
converted_value = ADC12MEM5;
}
Since the flag is automaticaly cleared when we access the ADC12MEMX register no need to clear the flag in the interrupt, right ?
Thank you.
Best regards,
Mike