Hey guys,
I am a total newb when it comes to reading analog inputs so I was hoping to get some help here.
My goal is to monitor the battery level being supplied to my circuit and then send out an alert when the level gets low.
What I've got so far is a POT connected between VSS and RB1 and I am printing out the value through the USART to a terminal app on my laptop.
With a fresh battery at 3.7v, I can turn the 500k POT and get an output ranging from around 8 to 240..When I pull the pin to GND I get a 0 and when I pull it up to VCC I get 255. All seems good so far..
But then when I connect a nearly dead battery (around 3.2 volts) I am getting hte same readings..
Confused... What am I missing here?
I am a total newb when it comes to reading analog inputs so I was hoping to get some help here.
My goal is to monitor the battery level being supplied to my circuit and then send out an alert when the level gets low.
What I've got so far is a POT connected between VSS and RB1 and I am printing out the value through the USART to a terminal app on my laptop.
With a fresh battery at 3.7v, I can turn the 500k POT and get an output ranging from around 8 to 240..When I pull the pin to GND I get a 0 and when I pull it up to VCC I get 255. All seems good so far..
But then when I connect a nearly dead battery (around 3.2 volts) I am getting hte same readings..
Confused... What am I missing here?
Code:
ANSELB = 0x20; //select RB1 as input (AN11)
while(1){
ADCON0 = 0x2F; // start ADC watching AN11
while (ADCON0 == 0x2F);// wait for conversion to complete
DisplayVolt = ADRESH; //store ADC input value
sprintf(outputBuffer, "battery: %d;\r\n", DisplayVolt);
WriteString(outputBuffer); //result is same regardless of battery level
}