I am using msp430G2553.
I basically want to find the time for which ADC value is greater than 511 and use this time to put on either the red or green led.
But whenever I run this code only the if(t<3000000) condition is executed at all times.
I want the code to run dynamically.
This is my code.
#include<msp430.h>
unsigned int value=0;
// Function prototypes
void ConfigureAdc(void);
void main(void)
{
{ int t;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3);
P1DIR|=BIT0+BIT6;
P1SEL|=BIT1;
P1SEL |= BIT3;
TACTL=TASSEL_2+ID_0+MC_2;
ConfigureAdc(); // ADC set-up function call
__enable_interrupt(); // Enable interrupts.
while(1)
{
__delay_cycles(1000); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled// Low Power Mode 0 with interrupts enabled
value = ADC10MEM;
if(value>511)
TA1R=0;
else
{
t=TA1R;
if(t<3000000)
{P1OUT&=~(BIT0+BIT6);
P1OUT|=BIT0;
}
else
{P1OUT&=~(BIT0+BIT6);
P1OUT|=BIT6;
}
}
}
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode
}
// Function containing ADC set-up
void ConfigureAdc(void)
{
ADC10CTL1 = INCH_3 + ADC10DIV_3 ; // Channel 3, ADC10CLK/3
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable
ADC10AE0 |= BIT3; // ADC input enable P1.3
}