Go Down

Topic: Voltage Divider Sensors (Read 432 times) previous topic - next topic

RealWedge

Apr 11, 2016, 07:49 pm Last Edit: Apr 11, 2016, 08:39 pm by RealWedge Reason: Update
 
Good Evening.

This is my first post here so hopefully no mistakes. I've been having a lot of trouble implementing a charge code successfully. The code that I'm using prints the values of Analogue inputs to the serial monitor. The circuit I'm using is for charging a LiFePO4 pack with a nominal voltage of 13.2V and 50AH. The Arduino uses PWM to control the charge, I have a voltage divider at the source and another at the battery which are used for comparison in the charge conditions. The code itself I reverse engineered from a Solar Charge Controller, coding is not my strong point.
 
 I can't seem to find why, but as soon as I switch on the source, the values at the voltage sensors are reasonably accurate but a little unstable. However they start to decrement and continue to do so. It's very frustrating and I'm kind of stumped. I'm putting a Voltage of 14-20V at the source. The dividers provide a save voltage of between 2-3V to the analogue pins. I'm pretty sure my ADC calculations are accurate. I can't move forward to connecting the actual batteries if I can't get stable readings.

The code and a circuit diagram are attached. Anyone with any suggestions or with past experience of such problems please leave me some feedback.

Using a Multimeter the voltage dividers have constant and expected values.

I,m using an Arduino Uno with the Atmega328.


RealWedge

I created the two voltage dividers of the circuit only onto a separate bread board and still
the values decrement towards zero. I also tried running a different code from an earlier
project and those ADC values on the serial monitor also decremented towards zero.

Do I need to replace the micro-controller?

jremington

#2
Apr 12, 2016, 05:08 pm Last Edit: Apr 12, 2016, 05:17 pm by jremington
There are many errors in the schematic. Q4 has no base bias current and will never conduct, GND1 and GND2 need to be connected for the analog readings to make sense, the battery voltage is wrong, the IRF9530 P-channel MOSFET may be connected backwards, etc.

Other than that, for any number of reasons (typos, code errors, integer division, integer overflow, etc.) the program probably isn't doing what you expect.

The usual debugging procedure is to sprinkle "print" statements throughout the program, so that  you can check that variable values make sense during operation.

MarkT

You have GND1 and GND2.  The analog voltage readings have to be w.r.t. GND2.

The output of your opto coupler is doing nothing.  This is not the diagram of a working circuit.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

RealWedge

   The schematic is just intended as a visual representation. The actual circuit is not an exact replica, multisim didn't have the relevant libraries. The two grounds are just to show that the optocoupler is not infact using the same ground as the rest of the circuit. I'm using the arduino to ground the optocoupler. By using a multimeter I get the expected values at the voltage dividers, I will add a clearer schematic soon.

   But even when I built a simple divider on its own I still have the same problem. I've just borrowed an Arduino Mega and it didn't resolve the issue, so I guess the problem is not the uno. The code compiles fine, there are no errors, it displays all information as required except for the voltage decrements towards zero. So the Arduino thinks that the Voltage is decrementing but the multimeter tells me it is perfectly constant. If it was a typo I imagine I'd get an error. I will look into sprinkling as advised. Thanks all tips are a massive help cause this wall ain't getting any smaller.


MarkT

No point posting nonsense - post the actual circuit you are actually using if you want actual answers
relevant to the actual hardware!  What else do you expect?  Mind-reading?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

RealWedge

The schematic that the circuit was built by is attached, the only change was 18K instead of 20K for the bottom resistor in the dividers. The battery is not yet connected as I don't want to risk damaging them or the arduino. For the moment I'm using a 10 Ohm heat sinked power resister to safely imitate a load.

Go Up