Hi, I just want to take an analog sample at pin 6.0 (MSP430F149) and convert it.The only thing is that i want to use a timer so that i can tell exactly when to take the sample. Below is my code. Although it compiles, it does not work. Does any1 know what is wrong with it? Thanks in advance. #include "msp430x14x.h" // Standard Equations void main(void) { WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer P6SEL |= 0x01; // Enable A/D channel A0 TACTL = TASSEL_1+MC_1; // Timer_A setup, UP mode,Crystal TACTL = TAIE; CCTL0 = CM_0; // No Captures, TACCTL0 = CCIFG; // I dont think we need the interupt flag! TACCTL0 = CCIE; //Enable interupts //TACCTL1 = OUTMOD_3; // CCR1 setup TACCR0 = 0x0111;//Compare Value.Call interupt after xcycles #pragma vector=TIMERA0_VECTOR__interrupt void Timer_A0_ISR (void) // The set delay has passed i.e. the timer has counted // to the value specified above { ADC12CTL0 = ADC12ON+SHT0_2; // Turn on ADC12, set sampling time ADC12CTL1 = SHS_1+SHP; // TAOUT.1 triggers sampling timer while (1) { ADC12CTL0 |= ENC; // Enable conversions ADC12CTL0 |= ADC12SC; // Start conversion while ((ADC12IFG & ADC12BUSY)==0); ADC12CTL0 &= ~ENC; // Clear ENC bit, SET } } }
TimerA and ADC12 problem
Started by ●January 3, 2005
Reply by ●January 3, 20052005-01-03
Hi,
I don't know if your ADC configuration is incorrect, but I noticed the
clock configuration is missing. Have you checked chapter 4 of the user's
guide? And, besides, take care with these two instructions:
TACCTL0 = CCIFG; // I dont think we need the interupt flag!
TACCTL0 = CCIE; //Enable interupts
Only the last one will be valid. To set both bits, you should do:
TACCTL0 = CCIFG + CCIE;
But you don't need to do that in this case, because if you set CCIFG and
CCIE later, your timer A ISR will be immediately executed. When you
enable interrupts, you have to clear the interrupt flags before, in
general.
Regards,
Adriano.
projecttamim wrote:
>
> Hi,
> I just want to take an analog sample at pin 6.0 (MSP430F149) and
> convert it.The only thing is that i want to use a timer so that i
> can tell exactly when to take the sample. Below is my code. Although
> it compiles, it does not work. Does any1 know what is wrong with it?
> Thanks in advance.
>
>
>
> #include "msp430x14x.h" // Standard Equations
>
>
> void main(void)
> {
>
> WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
> P6SEL |= 0x01; // Enable A/D channel A0
>
>
> TACTL = TASSEL_1+MC_1; // Timer_A setup, UP mode,Crystal
> TACTL = TAIE;
>
> CCTL0 = CM_0; // No Captures,
> TACCTL0 = CCIFG; // I dont think we need the interupt flag!
> TACCTL0 = CCIE; //Enable interupts
>
> //TACCTL1 = OUTMOD_3; // CCR1 setup
>
> TACCR0 = 0x0111;//Compare Value.Call interupt after xcycles
>
>
>
> #pragma vector=TIMERA0_VECTOR__interrupt void Timer_A0_ISR
> (void) // The set delay has passed i.e. the timer has counted
> // to the value specified above
> {
> ADC12CTL0 = ADC12ON+SHT0_2; // Turn on ADC12, set sampling time
> ADC12CTL1 = SHS_1+SHP; // TAOUT.1 triggers sampling timer
> while (1)
> {
> ADC12CTL0 |= ENC; // Enable conversions
> ADC12CTL0 |= ADC12SC; // Start conversion
> while ((ADC12IFG & ADC12BUSY)==0);
> ADC12CTL0 &= ~ENC; // Clear ENC bit, SET
> }
> }
> }
>
>
>
>
>
>
> .
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
Reply by ●January 3, 20052005-01-03
First of all by setting the CCIFG flag you have forced an interrupt to
occur as soon as you enable CCIE. You must do the opposite, you must
explicitly clear IFG before enabling CCIE.
Enabling the ADC12 in the interrupt is about as wrong as you can get.
Why not read the ADC12 section in the user guide? It shows you how to
set up repeating interrupts to trigger from one of two timer compare
matches.
Looping in an ISR waiting for something to happen is simply poor
programme design, this is why ISR's are provided, so that the micro can
continue with opther things until it needs to respond.
Al
projecttamim wrote:
>
> Hi,
> I just want to take an analog sample at pin 6.0 (MSP430F149) and
> convert it.The only thing is that i want to use a timer so that i
> can tell exactly when to take the sample. Below is my code. Although
> it compiles, it does not work. Does any1 know what is wrong with it?
> Thanks in advance.
>
>
>
> #include "msp430x14x.h" // Standard Equations
>
>
> void main(void)
> {
>
> WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
> P6SEL |= 0x01; // Enable A/D channel A0
>
>
> TACTL = TASSEL_1+MC_1; // Timer_A setup, UP mode,Crystal
> TACTL = TAIE;
>
> CCTL0 = CM_0; // No Captures,
> TACCTL0 = CCIFG; // I dont think we need the interupt flag!
> TACCTL0 = CCIE; //Enable interupts
>
> //TACCTL1 = OUTMOD_3; // CCR1 setup
>
> TACCR0 = 0x0111;//Compare Value.Call interupt after xcycles
>
>
>
> #pragma vector=TIMERA0_VECTOR__interrupt void Timer_A0_ISR
> (void) // The set delay has passed i.e. the timer has counted
> // to the value specified above
> {
> ADC12CTL0 = ADC12ON+SHT0_2; // Turn on ADC12, set sampling time
> ADC12CTL1 = SHS_1+SHP; // TAOUT.1 triggers sampling timer
> while (1)
> {
> ADC12CTL0 |= ENC; // Enable conversions
> ADC12CTL0 |= ADC12SC; // Start conversion
> while ((ADC12IFG & ADC12BUSY)==0);
> ADC12CTL0 &= ~ENC; // Clear ENC bit, SET
> }
> }
> }
>
>
>
>
>
>
> .
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>