# continuous battery monitoring during charging as well as discharging

#### viznu3391

Joined Dec 10, 2015
16
- Do the reading from the inverter and charger appear to be good..

- Disconnect the sensors one at a time and see what happens to the battery readings.
- inverter readings are coming fine.
- I'll try that.

Thanks

#### viznu3391

Joined Dec 10, 2015
16

Just use two resistors for a divider, no op amp needed.
I used just a voltage divider before and faced this problem. Then I added the low pass filter with an voltage follower. Still same results.

C:
void InitADC(void)
{
ADCON1  = 0x80;        // Make PORTA and PORTE analog pins
// Also, Vref+ = 5v and Vref- = GND
TRISA   = 0x2f;      // Make RA5, RA3, RA2, RA1, RA0 input
TRISE   = 0x07;        // Make RE0, RE1 and RE2 input
ADCON0  = 0x80;        // Turn on the A/D Converter
}

{
ADCON0 &= 0xc7;         // Clear Channel selection bits
__delay_ms(10);         // Time for Acqusition capacitor
// to charge up and show correct value
GO_nDONE  = 1;           // Enable Go/Done

while(GO_nDONE);        // Wait for conversion completion
}

double Measure_Volt(unsigned channel, double Volt_Ratio)
{
unsigned int i;
unsigned int  sample_Volt;
double sum_Volt = 0;
double Vavg;//,AvgCount;
for(i=0;i<50;i++)
{
sum_Volt += sample_Volt;
}
//AvgCount = sum_Volt / 50; //
sum_Volt = 0;
return Vavg;
}

void main(){
init_serial();
while(1){
///....................
bat_volt= Measure_Volt(AN4,1);      // #define AN4 4
//other codes for sending data
}
}
Moderators note : Use code tags for C

Last edited by a moderator:

#### Picbuster

Joined Dec 2, 2013
1,041
Connect variable voltage source to input.
Disable all functions and printf the ADC value and voltage calculated from it.
Repeat using de divider.

I hope that this gives you input solving the problem.

#### viznu3391

Joined Dec 10, 2015
16
Connect variable voltage source to input.
Disable all functions and printf the ADC value and voltage calculated from it.
Repeat using de divider.

I hope that this gives you input solving the problem.
ADC is working fine. My problem is when I connect inverter and charging circuit to the battery, pin that goes to the ADC is giving a constant value.

#### Lestraveled

Joined May 19, 2014
1,946
What are the results of your trouble-shooting efforts?? Talk to us.....

#### Picbuster

Joined Dec 2, 2013
1,041
I agree with lestraveled. measure and report we are not able to see what you do or don't.
Please check ground leads and resistors are they 100k and 10K. (not to worry I have resistor failure some times)
did you connect the variable voltage source to gnd and the 100K(high end)?
measure, as stated before by lestraveled, the chip adc input and change voltage from 0 to 5V what is your reading?

it should be : Vsource*10/(100+10)

#### Dodgydave

Joined Jun 22, 2012
10,695
Do you have a variable dc power supply 0-5V, what readings are you getting if you input the variable dc psu into the A/D pin?