SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By reflex19
#149365
Hi all,
I'm using the code below to program a msp430f2274 microcontroller: the analog ADC10 input is the A3 channel, while port 4.7 is the ADC10 output which is connected to a led. I must compare the result of convertion to a theshold to turn the led ON or OFF. The voltage at the analog ADC input come from a photodiode; I measured it with a multimeter and it's about 200 mV with the light of the day.
The problem is that the value in the ADC10MEM register is 0x00 and I can't understand why!
Please is there anyone who can help me?
Thanks in advance...


#include "msp430x22x4.h"

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 + MC_1; // TACLK = SMCLK, Up mode.
__bis_SR_register(CPUOFF + GIE); // LPM0, TA0_ISR will force exit
TACCTL0 &= ~CCIE; // Disable timer Interrupt
ADC10AE0 |= 0x03; // A3 ADC option select
P4DIR |= 0x80; // Set P4.7 to output direction
for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
if (ADC10MEM < 0x1C) // ADC10MEM = A3 > 0.1V?
P4OUT &= ~0x80; // Clear P4.7 LED off
else
P4OUT |= 0x80; // Set P4.7 LED on
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}

#pragma vector=TIMERA0_VECTOR
__interrupt void TA0_ISR(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}