NumberOneRobot
NumberOneRobot

Reputation: 1791

MSP430 g2553 ADC Voltage conversion, not getting a value

I'm trying to program a TI MSP430 g2553 ADC10 to read input voltages. When I connect it to a power source, however, I get no value from the ADC10MEM register. I've tried many different tutorials, but nothing has been able to fix the issue. I believe it's an issue in how I'm setting up the ADC, but I don't know what a lot of the variables are, so I'm not sure what needs to be set and what doesn't. Does anyone have any insight on how I can figure this out, or know what to do to properly set up the ADC? The code I'm using was taken from

http://blog.elevendroids.com/2013/06/code-recipe-reading-msp430-power-supply-voltage-level/

and modified to fit my needs, but it isn't giving me any working value, even when the power supply is off, it doesn't give me 0.

Upvotes: 0

Views: 1656

Answers (1)

ekoeppen
ekoeppen

Reputation: 126

Could you try this? It returns the voltage in millivolts:

unsigned read_voltage(void)
{
    unsigned adc, voltage;

    ADC10CTL1 = INCH_11 | ADC10DIV_3 | ADC10SSEL_3;
    ADC10CTL0 = ADC10SHT_3 | ADC10ON | ENC | REF2_5V | ADC10SC | REFON | SREF_1;
    while (ADC10CTL1 & ADC10BUSY) ;
    adc = ADC10MEM;
    ADC10CTL0 &= ~ENC;
    voltage = adc * 5;

    return voltage;
}

Upvotes: 0

Related Questions