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.

Reading voltages using ADC10 and display it on LCD

Other Parts Discussed in Thread: MSP430F2274

Hi,

I am trying to read two voltage values on two channels (A0, A1) using the ADC10 of my MSP430F2274(eZ430-RF2500T), and display the voltages on my sparkfun serLCD v2.5. Example: 3V, 5V etc....

This is my code to read in two voltage inputs. Is this the correct way to read in two voltage inputs using the ADC10?

ADC10CTL1 = INCH_0 // A0
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
__bis_SR_register(GIE); // Enable interrupts. Vss Ref.
for(temp = 10; temp > 0; temp-- ); // delay to allow reference to settle
ADC10AE0 |= 0x01; // PA.0 ADC option select
ADC10CTL0 |= ENC + ADC10SC; // Start to perform sampling and conversion
for(temp = 10; temp > 0; temp-- ); // delay to allow reference to settle
unsigned int voltage1 = ADC10MEM;

ADC10CTL1 = INCH_1 ; // A1
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
__bis_SR_register(GIE); // Enable interrupts. Vss Ref.
for(temp1 = 10; temp1 > 0; temp1-- ); // delay to allow reference to settle
ADC10AE0 |= 0x02; // PA.1 ADC option select
ADC10CTL0 |= ENC + ADC10SC; // Start to perform sampling and conversion
for(temp1 = 10; temp1 > 0; temp1-- ); // delay to allow reference to settle
unsigned int voltage2 = ADC10MEM;

This is the code used for my LCD display:

// Set up the timer to simulate a UART
ConfigureTimerUart();
__delay_cycles(1000000); // wait for LCD display to initialize
__enable_interrupt();

TXByte = 0xFE; Transmit();
TXByte = 0x9F; Transmit();
__delay_cycles(500000);
TXString(voltage1);

  • A for loop is not a proper delay. You don’t know how the compiler will compile it and therefore how long it takes. The compiler may even discard it completely, as it doesn’t change the system state. Use __delay_cycles instead, or use a timer.

    The second waiting loop is completely wrong. After starting the conversion, you need to wait until it is done. Which is indicated by ADC10IFG being set and (in case of a single conversion) ADC10SC and ADC10BUSY being clear again.

    Before changing INCH from INCH_0 to INCH_1, you need to clear ENC.

    If the reference is still on (after the first conversion) ,you don’t need to wait for it to settle a second time.

    Why do you enable interrupts? (ADC10IE and GIE)? You don’t have an ISR to handle them.

    For the LCD, I can’t say anything, I don’t know the LCD or how it works.

**Attention** This is a public forum