This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Finding time using timer interrupts for adc values

Other Parts Discussed in Thread: MSP430G2553

I am using msp430G2553.I have a led-ldr pair.When my hand is placed over it the adc value increases.I want to find the time for which my hand is placed over it.This is my code and it is not working.

#include<msp430.h>
unsigned int value=0;
unsigned volatile int count;

// Function prototypes
void ConfigureAdc(void);

void main(void)
{
{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3);
P1DIR|=BIT0+BIT6;

P1SEL|=BIT1;
// SMCLK = DCO = 1MHz
P1SEL |= BIT3;
// ADC input pin P1.3
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)
{ TAR=0;
CCTL0 = CCIE; // CCR0 interrupt enabled
TACTL = TASSEL_2 + MC_1 + ID_0;
count=0;// SMCLK/1, upmode
CCR0 = 1000; //overflow freq:1000hz frequency


}

else
{
if(count<3000)
{
P1OUT&=~(BIT0+BIT6);
P1OUT|=BIT6;
}
else
{
P1OUT&=~(BIT0+BIT6);
P1OUT|=BIT0;

}

}


}

}
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR

__interrupt void ADC10_ISR (void)

{

__bic_SR_register_on_exit(CPUOFF); // Return to active mode

}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
count++;
}


// 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
}

**Attention** This is a public forum