external battery voltage

hello all,

i’m using msp430f149.i have one external battery,i want to measure it’s voltage range,and display it on lcd. somebody sait that we can use ADC,could you please guide me on this. i read msp430 user guide,but still now i didn’t get clear idea.i’m struggling how to take the value from msp .is there any formula is there?

Thanks

Naz

anybody have any idea about this?

void main(void)

{

volatile unsigned int i,temp;

WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer

P6SEL |= 0x01; // use PIN p6.0 for input

P6DIR &=~0x01; //select adc function for pin p6.0

ADC12CTL0=ADC12ON; //ADC12 ON

ADC12CTL0=SHT0_2; //SET the sampling time

ADC12CTL1=CSTARTADD_0; //conversion starting address

ADC12CTL1=SHP; //sampling timer

ADC12MCTL0=SREF_0; //select reference

ADC12MCTL0=INCH_0; //Input channel

ADC12CTL0|=ENC; //Enable conversions

ADC12CTL0|=ADC12SC; //start single conversion

while((ADC12IFG&BIT0)!=0);

temp=ADC12MEM0;

printf(“%d”,temp);

ADC12CTL0&=~ADC12SC;

ADC12CTL0&=~ENC;

ADC12CTL0&=~ADC12ON;

P6SEL&=~0x01;

}

this is my code…i’m getting 2019 on terminal i/o of IAR compiler…What is this…how to convert this to voltage…

The equation is on page 17-4 of the MSP430x1xx Family User’s Guide. Since you are using Avcc as Vr+ and Avss as Vr- ( SREF_0 ), the equation reduces down to

Nadc = 4095 * Vin / Vr+

rearranging

Vin = Nadc * Vr+ / 4095 or

Vin = Nadc * Avcc / 4095 as Vr+ is Avcc

It looks like your code is overwriting your ADC12CTL0, ADC12CTL1 and ADC12MCTL0 registers as you are using the ‘=’ rather then ‘|=’ when setting the various options.

thank you gm,i replaced |= insted of =,now i’m getting 4095…as you mentioned ndc=4095*vin/vr+;

vin=3.3 and vr+=1.3 ,then finally i’m getting 10395…what is this?this is my measured voltage?but i applied 5.5 only then how come this?could u please solve this issue…

by

naz

What voltages are you applying to AVSS, AVCC and channel 0?

AVcc(Analog supply voltage positive terminal)-4.28v

Avss(Analog supply voltage Negative terminal)-0v

channel 0(A0)=5.5v

Thank yours reply gm.

by

naz

The maximum recommended voltage on DVCC and AVCC is 3.6V. Absolute maximum is 4.1, beyond which permanent damage can occur. Maximum voltage applied to any pin is VCC + 0.3V. You have exceeded all of these. I will be surprised if your chip has not been damaged. You really need to read the data sheets and user guides.

sorry gm…i think i did a mistake in measuring the voltage level.

AVcc-2.59,AVss=0,Dvcc=3.3,Dvss=0,input voltage channle A0=3.3.

Since the voltage that you are measuring is higher then your positive reference, the value that will be reported will be 4095 (0x0FFF).

hello gm,

i didn’t get your’s point.one thing sir i don’t fully about my development board,just i’m doing small small task.so tell me,now what i have to do?input channle o -voltage A0=3.3v ,this much only i’m giving,avcc and dvcc designed internally.please sir guide me on this

The ADC12 can only measure voltages between your negative reference (VR-, which is ground in your case) and your positive reference (VR+, which is AVCC in your case). To accurately measure a voltage on a input channel, you must ensure that the voltage will be between AVCC and ground.

It sounds like you need to use a voltage divider (2 resistors) to reduce the battery voltage to a value that can be read by the ADC.

Use resistor values that are high enough to minimise the battery drain, while low enough to minimise the error due to current drawn by the ADC input. If this is a problem, you could use an op-amp to drive the ADC input.

ya it’s correct,now it’s working properly,special thanks to gm.

Glad you got it working!