Hi,
I need to sample a rectified sine wave of 230V, 50Hz to detect its zero crossing . but I am finding it difficult to continuously sample it. The code is given below:
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_8MHZ; // Set range
DCOCTL = CALDCO_8MHZ;
P1DIR |= BIT0;
P2DIR |=0xF8; // Set ports P2.0/1/2 to Input Direction
P2SEL |=0x07; // Select Ports P2.0/1/2 as analogue input function
// Configure the Timer_A in order to trigger the ADC10
TA1CCTL0 =CCIE; // Enable the Timer_A interrup
TA1CCR0 = 98; // Set Timer_A Capture/Compare Registor to TA_Prd
TA1CTL = TASSEL_2 + MC_1; // Select Sub_system Master Clock SMCLK as source of trigger signal
// Select Up_mode, the timer_A counts up to TACCR0
// ADC10 COnfiguration
ADC10CTL0 =ADC10ON + MSC; //ADC ON, Reference Voltage to 2.5 V and select Up-mode
ADC10CTL1 = INCH_1 +CONSEQ_2; // Select A1 as input channel, repeat single channel as conversion sequence
ADC10DTC0 = ADC10CT; // continuous data transfer
for (;;){
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
if (ADC10MEM == 0x0000) {
// some code
}
}
}
// Timer A0 interrupt service routine
#pragma vector=TIMER1_A1_VECTOR
__interrupt void Timer_A1(void){
_bis_SR_register_on_exit(CPUOFF);
}