Inconsistent Battery Reading under load - Page 1
Forum section: electronics / beginners

author: trilerian
author_rank: Regular Contributor
timestamp: February 04, 2024, 05:46:49 am
content: I have built a battery discharger for RC 1S/2S application. It has come a long way since I started this project and the unit does a lot of cool stuff, at least I think so. It uses pwm to discharge to a resistor bank, I have a pid controller setup in the code to maintain and get to the discharge rate. This is controlled by a 328PB mcu. The power source is a 12VDC server power supply. I am using an lm4132 external ref (A) to get as accurate ref for the adc as I can. The drift on this reference is 10ppm/°C, and the board itself gets pretty warm, so it does drift a little, but not a lot.So here is the issue... I have the code setup at a 10Hz sample rate, I average the 3 analog inputs 100x each, due to the pid controller oscillation this is necessary to get a close approximation of the output. When there is no load on the battery I get decent readings, at least decent enough to offset the read with consistency. But when I put a load on the battery, even if it is a straight value to the pwm out so no oscillation, I get a lower value return than I should. I have a bench top dmm (HP3478A) hooked to the leads of the battery and measuring the value realtime as I am also measuring with my mcu code. No load they read the same, with a load the mcu reads the value a bit lower than the dmm. This difference is directly proportional to the load as well. I have managed to write a simple equation to get correct for it, but nonetheless I am confused why it is there. The measurement is taken through separate wires than those that carry the current from the load. It doesn't matter which of my batteries I use, the value remains the same. I thought maybe this was some sort of internal resistance in the wires being used for measuring, so I tried different length wires, which give slightly different resistance for the wires. Same value needed to offset this "phantom" load. My only guess is this is somehow a function of the voltage dividers I am using. The voltage dividers are 10K, 5K1 and then a 1uF x7r capacitor for a filter. but the filter doesn't matter, this happens with and without the filter cap.Next question. What is the best way to set the voltage offset for the adc reading of the voltage? There are 3 ways that I can think of:1. Add or subract bits as necessary to the raw adc value. I do this currently.2. Change the VCC or Vref value to adjust for the offset. I have this in my code as a user input to "calibrate" the voltage with their equipment.3. Just add a float variable with an offset value.Thanks

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 04, 2024, 07:32:56 am
content: Can you add some numbers what you have? (How much voltage changes under what exact load, what exect batteries do you use, what wires for power lines, etc).

author: tooki
author_rank: Super Contributor
timestamp: February 04, 2024, 07:35:53 am
content: Without a schematic it’s kinda hard to guess what’s going on…

author: MrAl
author_rank: Super Contributor
timestamp: February 04, 2024, 09:16:33 am
content: Quote from: trilerian on February 04, 2024, 05:46:49 amHi,You may have to show how this is wired physically also, maybe with some pics.You should check the setup with a source other than what you are using now, if you haven't done that yet.Maybe a battery and a potentiometer to check the readings on the DMM and the ADC.It could be that the ADC is averaging differently than the DMM.Also, you could try a much larger capacitor to average the reading in an analog way rather than digital.To get the average over N readings, N=100 may not be high enough. You may have to go up much higher like 10000. With N=10000 and the cap much larger (like 100uf) you may see more equal results from both measurement techniques.

author: PlainName
author_rank: Super Contributor
timestamp: February 04, 2024, 09:39:52 am
content: Can you put a scope on the wires to see what noise, if any, you are getting? Could simply be that there is ripple which the DMM is averaging out differently to the MCU code.That was my initial thought when I saw 'PWM' and '10Hz'. But you say it happens also when there is no PWM. I would still want to put a scope on to be sure that there really isn't any at the pointy end.

author: Psi
author_rank: Super Contributor
timestamp: February 04, 2024, 09:47:11 am
content: I'm no battery charger expect, but all the hobby RC Lipo chargers i've used turn off charging/discharging for a second to do battery cell voltage checks.Then either restart charging/discharging or end it, depending on what that reading say about the battery.From memory they do this every 30 seconds or so.I can tell it works this way by watching the current on the LCD display, it periodically go to zero for a sec. And whenever the charge/discharge cycle completes it's always during this time. Never during actual charge/discharge. eg, battery charging is not considered 'complete' until all cells remain over 4.20V when charging is stopped.Perhaps the best approach to your problem of ADC error from the PID is just to not deal with the problem at all.

author: trilerian
author_rank: Regular Contributor
timestamp: February 04, 2024, 04:37:59 pm
content: Quote from: Vovk_Z on February 04, 2024, 07:32:56 amIt is not a high value. At 30A it is approximately a 120mV difference, like I said, it changes proportionally with the load and I code it out with the following:Code:voltageFull = ((Fvoltage * (ValueR1F + ValueR2F)) / ValueR2F) + (Icurrent / ulF);The part you are interested is the last part: (Icurrent / ulF). ulF = 250 in my code.Just to clarify, the pwm frequency is 490Hz, not changed from the default on the mcu. The sample rate in which I read all the calculations is 10Hz, 10x a second. The average that is taken is 100x on each input.So the calculations function averages the sensors 100 times and spits that out 10 times a second. I tried higher averaging without a sample rate, I just let the code loop as fast as it could, but this is a tft touchscreen and I needed to make the touch more responsive.The wires that carry the load from the battery to the discharger are 10awg wires, the voltage sensing is done on much smaller wires. Maybe 24awg.Scope output is a DC line. The noise in the reading is the same noise I get with nothing attached. I will admit I have a few things running and it picks up noise just being where it is.I have changed power sources from switched 14V and 12V to a 8.4V battery. No change in the output.I am adding a schematic, a 3d view of the schematic, a pic of the actual wiring, output from my scope after the voltage divider and filter, and output at the battery.This was a 10A load, the duty cycle is low at this load.

author: trilerian
author_rank: Regular Contributor
timestamp: February 04, 2024, 07:06:24 pm
content: I did another measurement, reading the voltage at the voltage divider during a test. Voltage at the divider matches the raw code for the voltage under a load. So this is a difference it what is read at the divider vs what is read at the battery. As I posted in my OP, the original design did not have a filter cap and had the same issue.Someone posted something about RMS but it looks like the post is gone now. But if the meter is in DC coupling, why would it measure RMS? Also I have compared results on both of my DMMs, the 3478A and a Siglent SDM3055. They are the same.

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 04, 2024, 08:45:45 pm
content: Quote from: trilerian on February 04, 2024, 04:37:59 pmBatteries and wires have some internal resistance. 120 mV / 30 A = 4 mOhm, this is not too much. I don't see much inconsistency here.Possibly, you may want to use a four-wire measurement circuit instead of two wire? I mean you may want to add two additional wires for voltage measurement purposes only which don't carry large currents, in addition to the main power lines?

author: trilerian
author_rank: Regular Contributor
timestamp: February 04, 2024, 09:22:23 pm
content: Quote from: Vovk_Z on February 04, 2024, 08:45:45 pmThis is a 4 wire measurement. The current carrying leads are separate, much bigger wires. Also this isn't IR of the battery or the wires, I can see and calculate those. This seems to be from the voltage divider that is measuring the voltage, not current.

author: radiolistener
author_rank: Super Contributor
timestamp: February 04, 2024, 09:25:03 pm
content: Mesaured battery voltage depends on battery internal resistance Rs and load resistance Rl.Load resistance includes resistance of the load and resistance of the ADC or DMM used for measurement.These two resistance Rs and Rl make voltage divider, so the voltage will depends on exact values of Rs and Rl.If you're trying to measure voltage with connected load which resistance can vary it leads to variable voltage reading...

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 04, 2024, 09:50:59 pm
content: Quote from: trilerian on February 04, 2024, 09:22:23 pmI'm looking at your circuit diagram now (but have not investigated your PCB yet) and I have a question: do you have the same the only one GND both for the power Bat- line and for your voltage divider GND? I suspect those are the same GND (connected together) so basically you don't have a 4-wire measurement (but rather a 3-wire). If so then the voltage drop you see is a voltage drop on a Bat- power wire.

author: trilerian
author_rank: Regular Contributor
timestamp: February 04, 2024, 10:24:28 pm
content: Quote from: Vovk_Z on February 04, 2024, 09:50:59 pmYes, there is a shared ground plane between the voltage dividers and the battery ground, which is also shared with the power source of the device. I don't understand what mean by a voltage drop on the battery (-). Wouldn't the ground be 0V due to having a battery share the ground?So if this is the case, how do I confirm this. What do I need to measure to verify it? I have tried different leads that have different resistance due to wire length and size but the difference in the values remain the same.I'm going to put together another board that uses different values on the voltage dividers to see if that changes the measurements.

author: floobydust
author_rank: Super Contributor
timestamp: February 04, 2024, 10:45:06 pm
content: Where is MCU pin 21? It should be right at the analog GND for a Kelvin connection.

author: trilerian
author_rank: Regular Contributor
timestamp: February 04, 2024, 11:31:48 pm
content: Pin 21 is grounded to the gnd plane, there is also a 100nF x7r decoupling capacitor.Also, here is a closeup pic of the battery lead. There is a sensor wire along with the current carrying wires to each terminal,

author: floobydust
author_rank: Super Contributor
timestamp: February 04, 2024, 11:44:41 pm
content: OK, I wondered because pin 21 is not on your schematic symbol, I would add it. Can we see the PCB backside? I'm wondering if there are big slices in the ground pour and you have something grounded in the wrong spot.Checking where the two critical voltage inputs are: (+) to the voltage divider resistor, and (-) to the MCU, REF, divider resistors to see if that could be picking up a voltage drop.

author: trilerian
author_rank: Regular Contributor
timestamp: February 05, 2024, 12:07:01 am
content: Here you go. I was hoping not to have to post how awful my routing is... This is only my 3rd pcb design, I was thinking of paying someone to route this mess for me once I got the final design done.First pic has both top and bottom runs. 2nd pic is only the bottom. There is a long break made by the temp sensor, that is actually not on my board I am working on. That was added because I added the external ref and had to run VIN of the temp sensor off the voltage ref output instead of the board VCC. On the board I am testing, that is a big jumper soldered from the decoupling capacitor on the ref and the temp sensor VIN pin. But even on my previous design where I was not using an external ref, this was still an issue.

author: Manul
author_rank: Super Contributor
timestamp: February 05, 2024, 05:38:14 pm
content: Quote from: Vovk_Z on February 04, 2024, 09:50:59 pm^ This. You want either to completely separate the grounds, or use a difference amplifier with appropriate gain (1/2, 1/3 or whatever you need) instead of voltage divider.

author: trilerian
author_rank: Regular Contributor
timestamp: February 05, 2024, 06:20:17 pm
content: Quote from: Manul on February 05, 2024, 05:38:14 pmWhat do I have to do to completely separate the grounds? Do you mean to make the voltage divider gnd not be a part of the ground plane? Just run it back to the gnd pin? But if the gnd pin is attached to the gnd plane, wouldn't it still be part of the same gnd?

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 05, 2024, 06:30:03 pm
content: Look at 'differentialdifference amplifier'. You may find it exactly what you need instead of voltage divider. And it may have less then 1 amplification ratio. I mean it may have ratio exactly as your divider but it can help separate your grounds.

author: Manul
author_rank: Super Contributor
timestamp: February 05, 2024, 06:31:52 pm
content: Quote from: trilerian on February 05, 2024, 06:20:17 pmMaybe more accurate would be to say that Bat- must not be connected to divider GND. I haven't studied your design, so I don't know, maybe it's hard to do. As I said, you can use difference amplifier as a second option.

author: trilerian
author_rank: Regular Contributor
timestamp: February 05, 2024, 07:22:02 pm
content: I'll redesign with a differential amplifier. Just to make sure, use the differential op-amp and not an analog comparator?EDIT: Also, I assume I will want to filter the input to the differential op-amp and not the other way around, filtering the output?

author: Manul
author_rank: Super Contributor
timestamp: February 05, 2024, 07:34:43 pm
content: Quote from: trilerian on February 05, 2024, 07:22:02 pmSimple op amp with 4 resistors making up difference amplifier. You probably want rail to rail output and input.

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 05, 2024, 07:34:50 pm
content: I guess I misspelled a name ot the amplifier. There is a difference between a difference amplifier and a differential amplifier, and TS needs difference amplifier as everybody stated (except me).Upd.: I've seen a lot of fully differential amplifiers (with differential output too), that's why I guess it is better to use here a term 'difference amplifier' which don't have to have differential output typically.

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 05, 2024, 07:38:11 pm
content: Quote from: trilerian on February 05, 2024, 07:22:02 pmYou definitely don't need a comparator instead of opamp.And I'm not sure you need a filter.

author: trilerian
author_rank: Regular Contributor
timestamp: February 05, 2024, 07:52:01 pm
content: Quote from: Vovk_Z on February 05, 2024, 07:38:11 pmFilter is for the pwm frequency of 490Hz. The literature I am reading on the difference amplifier says it has a gain of 1, so the output will be up to 4.2V, 8.4V - 4.2V. I need it down to less than 4.096V since that is the top end of my LM4132 reference I a using.

author: Manul
author_rank: Super Contributor
timestamp: February 05, 2024, 08:36:35 pm
content: Quote from: trilerian on February 05, 2024, 07:52:01 pmYou can set gain of less than one, you can set any arbitrary gain just by choosing ratio of resistors. You want filter at the output: series resistor and capacitor to ground. Don't put filter at the input (or feedback path), unless you know very well what you are doing, because you risk ruining CMRR or something else bad. CMRR might or might not be important, but better stay on safe side unless you know for sure. Also I suggest to use 1% resistors or better for the same reason.

author: trilerian
author_rank: Regular Contributor
timestamp: February 06, 2024, 11:51:47 pm
content: Quote from: Manul on February 05, 2024, 08:36:35 pmSo I need to pick an op-amp to start with. Presumably one with high impedance so I can run high value resistors to it? What value resistors should I be looking at here? 100k, higher? Bandwidth, while that is listed as an important doesn't seem like an issue with the adc of the 328P being 125kHz. What does seem to be an issue is the output current, I see a lot of these over 40mA. So I need to make sure I stay under 40mA, right, 328P input current limit on a pin is 40mA? Although a filter on the output may take up some of that?So, I need 2 or can I do a 2 channel op amp? And it is fine, I assume, to use the junction between the +/- for the cells in series to measure from. One going from + to the junction, the other going from the junction to -? I have no issue measuring from the junction to - now, so I assume it is fine, and probably will work better than subtracting. Although in its own way that is what it is doing, lol.Would something likehttps://www.mouser.com/datasheet/2/268/MCP6496_Data_Sheet_DS20006758-3078050.pdfwork? Better choice available?Thanks

author: trilerian
author_rank: Regular Contributor
timestamp: February 07, 2024, 02:12:18 pm
content: I added the attached to my schematic. If I understand what I have read I will create a ratio of R3/R1. R3=10k, R1=11K5 (not sure on these values).Then this will measure the difference between the + and - inputs. + will be 4.2V (highest) and - will be 0. There are 2 channels to measure both cells. The output then has a lowpass filter with cutoff of 31Hz to make the output a DC line from the 490Hz pwm. I'm still not sure on my choice of op-amp. I would appreciate feedback on this.Thanks

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 07, 2024, 04:48:33 pm
content: Quote from: trilerian on February 06, 2024, 11:51:47 pmI guess you have to look at power supply voltage available for your opamp (that's first restriction). And consider input voltage range.If you want to measure voltage from zero then look for opamps who can work rail-to-rail, at least for input ('RtoR Input ').

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 07, 2024, 05:07:22 pm
content: Quote from: trilerian on February 07, 2024, 02:12:18 pm

author: trilerian
author_rank: Regular Contributor
timestamp: February 07, 2024, 06:14:37 pm
content: Quote from: Vovk_Z on February 07, 2024, 05:07:22 pmAre 1% resistors good enough, or should I use 0.5 or 0.1%? I generally get the 1% for most parts, but kind of feel this is a more important component to get really close on values, but mainly for the math. I can measure these on my 4 wire meter to get actual values.What I am curious about is how the input impedance of the resistors affects the output? The 328P like less than 10k on the adc pins. So if I have a 10K/12K divider essentially on the input that is 5455, if that is transferred to the output plus the 5K1after the output, would put be just above the 10K. But there is the filter cap that may help a bit too.EDIT: Also reading through the data sheet it says the VDD needs bypass capacitors. I don't see any values given for the bypass. Should 100nF be ok?

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 07, 2024, 08:34:21 pm
content: 1) rated resistor accuracy depends on you. You may use 1% but select them manually with DMM, or use 0.1 % and select manually with good DMM too. The difference is that with 1 % initial accuracy you definitely have to select identical but with 0.1 % initial accuracy they might be good enough without additional selection. And you don't need 4-wire ohmmeter to measure 10 k resistors (just usual 4-5 digit DMM).2) Output impedance of your diffamp is 5k1 for DC, and less for AC because of a capacitor. If ig is too much - use another opamp as buffer.3) 100 nF is typically ok for opamp bypass until other is clearly stated.

author: Manul
author_rank: Super Contributor
timestamp: February 07, 2024, 09:04:51 pm
content: Quote from: trilerian on February 06, 2024, 11:51:47 pmI don't know what exactly you mean by high impedance op amp. I suppose you want resistors something like 30k and 10k (will give you gain of 1/3). Not too low, not too high. Bandwidth is not important, I would choose an op amp which has low current consuption and has good price. Faster ones often need more current and are pricier.Output current is completely irrelevant. Your thought process here is completely wrong. 40mA limit is for 328P output. Input is really high impedance, so there is almost no current. You just need to make sure to not exceed ADC input voltage range. But if op amp is powered from same supply as 328P, that is impossible. For instance, it would be a danger to power op amp from 12V, while feeding it's output directly to MCU input which is powered from 5V.Quote from: trilerian on February 07, 2024, 02:12:18 pmSchematic is wrong. Remember: amplifier always usesnegativefeedback. So feedback from output must go toinvertinginput.Quote from: trilerian on February 07, 2024, 06:14:37 pm1% is minimum, but should be enough. Mainly it affects two things: accuracy of gain and CMRR. I don't think you need high CMRR in this aplication. And for accuracy, I don't think that you will gain much more by going 0.1%. Calculate or experiment.Quote from: trilerian on February 07, 2024, 06:14:37 pmNothing on the input gets transfered to op amp output. Op amp output (in closed loop) always has very very low impedance. So only 5.1k of the output filter. Yes, you can say that ADC likes less than 10k, but 10k is not resistance, it's impedance. Filter cap has way enough low impedance.Op amp bypassing is generally based on op amp bandwidth and frequency band of interest. In your case I would go more than 100n, like 1uF or more, for sure can't hurt.Actually after reading your posts, Istronglysuggest you prototype before producing a PCB.

author: trilerian
author_rank: Regular Contributor
timestamp: February 07, 2024, 09:38:54 pm
content: Quote from: Manul on February 07, 2024, 09:04:51 pm

author: trilerian
author_rank: Regular Contributor
timestamp: February 08, 2024, 12:32:23 am
content: Quote from: Manul on February 07, 2024, 09:04:51 pmI wasn't sure how high of values to choose for the input resistors, but it seems it doesn't matter much. The only real thing that matters is the gain. I need to be under 4.096V, I am using an external reference for the ADC, so while 5V won't hurt the pin, anything 4.096V and above just reads 1023. So my choice of resistors are 11K5, 10K.At a max input of 4.35V this should reduce it to ~3.8VQuoteI updated my schematic and attached.QuoteThank you

author: trilerian
author_rank: Regular Contributor
timestamp: February 08, 2024, 03:00:37 am
content: I would like to bring back the subject of grounding the battery in this circuit. Is this actually needed? Using the difference amplifier there isn't a need for the batt - to be grounded, or at least I don't think so. It will measure the difference between V1 and V2 no matter how far above ground V2 is. If I am following what I have read, the summing point is a virtual gnd created in the inverting amplifier, so the inputs are 0V. Although I am a little confused how there isn't current flowing when the voltage is being dropped to 0. But... The point is I don't think the battery - needs to be connected to ground to measure the voltages here. So what about the battery - being connected to ground for discharging? The mosfets gates are controlled by the microcontroller, when the gates turn on a circuit is completed from the Batt - to the Batt + through an external resistor bank. I am failing to see the need for a gnd reference here. The current sensor is a hall sensor, so it isn't directly measuring the voltage of the battery, the voltage sensing isn't grounded to the battery, which I think is the point there. Although the op amp itself is grounded.I am attaching my full schematic again, with the difference amplifier update. I would very much appreciate some clarity on the grounding. If the battery - needs to connect to the ground plane, and why?Thanks

author: Manul
author_rank: Super Contributor
timestamp: February 08, 2024, 09:09:53 pm
content: Batt- should be grounded, how else the circuit will close? Actually why would you put that current sensor (and fuse!) on the low side in series with mosfet source? That's awkward at best, may cause problems at worst. Put them to the high side. And draw schematic in a way, that n-ch mosfet source faces down, drain faces up. It's really confusing to read the way it is.

author: trilerian
author_rank: Regular Contributor
timestamp: February 09, 2024, 12:55:08 am
content: Quote from: Manul on February 08, 2024, 09:09:53 pmGoing back to the start of the project. A device was given to me to reverse engineer since the original maker wasn't making them anymore and wouldn't respond communication attempts. So I did my best to reverse engineer the project with some help from this and other forums. The lowside current sensor and fuse was pulled directly from his design. Where I differ from the original design is I am using pwm to open the gate of the fets and allow current to pass between the external resistor bank and the battery. The fets are not sinking current, well except for their IR, they are just connecting drain to source which connects the resistor bank. I could place the current sensor and fuse between the Batt+ and one of the load terminals. But back to the ground question. I still fail to see why the Batt- has to be grounded to the rest of the circuit. This seems isolated to me. I know for certain if the fets were not involved, if I was just connecting the battery to the resistor bank with the current sensor to measure the current, it would work without the battery being grounded to the circuit. I have this setup with a dyno using the same style current sensor. The dyno was purchased from a company, I didn't build it.Now, all that said... I found out today, that the original designer decided to release a V2. Maybe he found out I was making one, who knows. But regardless, I'm not going to be able to release this before he does, so I am going to go back to the drawing board and redesign this properly. At this point it is now for me and I want to build it right. I bought a couple of huge linear mosfets to start with and I am going to move this off of the 328P and onto an esp32 or an stm32. The mosfets I bought are IXTK90N25L2, which are pricey. There is a lot of stuff I will have to change, but I am going to keep the difference amplifier. I may be building this for the next year, lol. But I am enjoying learning how to do it and that is worth all the money and time I have and will put into it.Moving to the ESP32 is for twofold reasons, one, my program space is at 97% with the 328P and there was still more I wanted to add. And, to force myself into another MCU since I have only been using the 328P so far.

author: trilerian
author_rank: Regular Contributor
timestamp: February 09, 2024, 03:58:27 am
content: So, interesting tidbit about this circuit as well. I asked awhile back how to implement reverse polarity protection for the battery. I asked what would happen if I plugged the battery in backwards. I think someone said something about a full bridge rectifier. And then the "just use polarity plugs", which I was doing already. But the battery connections are 5mm bullets and they can get plugged in accidentally. So one fine day in the middle of the night, I decided to see what happens if you plug the battery in backwards. Well, nothing popped. My current sensor sensed current in the opposite direction of normal use, I am using a bi directional sensor. I know it sensed in the opposite direction because the analog reading was below 512 instead of above. Now, obviously the load has to be plugged in for it to happen, without the load plugged in, you are just touching the positive of the battery to the ground of the circuit, and nothing will happen because there is no ground for current to flow. Back to the reverse polarity. When I connected it in reverse the mosfets heated up a lot faster than normal, so it is still bad, but it didn't blow anything up. So this is another reason why I think the battery doesn't have to be grounded to the rest of the circuit. When it was connected in reverse polarity and current was flowing it didn't affect the rest of the board.I am attaching a couple of pics of the actual board. I have drawn on the top side pic. When the mosfet is turned on current flows (old belief) from the higher potential (+), through the load and to the LOAD pad on the pcb, this is via stitched to the pad on the bottom which is connected to the drain of the mosfet, from there is goes through the mosfet and to the source which is on top of the pcb, through the fuse then the current sensor and finally to the lower potential (-) of the battery. I seperated the drain and the source on the top and bottom of the pcb because the amount of current the traces carry can be up to 45A. According to a chart I looked at, I needed 30mm traces for 40A and a 30°C temp rise. I didn't know how to accomplish that except to put one of the traces on the bottom. I chose the drain on the bottom because the source has the fuse.Despite the design flaws, this device actually works pretty well. And to alert the user of reverse polarity plug in, the screen flashes all red and in big white letters it says battery backwards, it flashes for 1 second at a time until the reverse polarity issue has been fixed, or the mosfets burn up and current flow stops. I'm using the reverse current flow as the condition to flash the screen. I do have proper reverse polarity protection via a mosfet on VIN as well, but when that is plugged in backwards, nothing happens or turns on.

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 09, 2024, 09:49:21 am
content: Quote from: trilerian on February 09, 2024, 03:58:27 amIt'll take some time to fully burn a MOSFET into nothing. Most semiconductors make a short circuit when they die, so you'll still have a path for a current. And still, a leftover (burned textolite, etc) is conductive. So there is a risk of overheating a battery and a battery fire.If short circuit current is limited by a resistance of an additional resistive load within a rated battery current limits then ok.(When you apply an opposite voltage to the closed MOSFET its body diode starts to conduct a current. That's why you see hot MOSFETs).

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 09, 2024, 11:20:37 am
content: I may be totally wrong here so I'll leave my coat on to be able to make a quick escape but... looking at the 3rd picture you posted you are bundling the load and sense wires? I wouldn't be surprised if that is where your problem originates

author: trilerian
author_rank: Regular Contributor
timestamp: February 09, 2024, 01:56:44 pm
content: Quote from: PA0PBZ on February 09, 2024, 11:20:37 amI don't think I am. The sensor wires are completely separate from the load wires starting at the connectors. The consensus is that somehow the voltage dividers and the battery gnd both being connected to the ground plane causes the difference I see. I'm not sure how that exactly works. But I was told it wasn't a true 4 wire connection because of the voltage divers ground, it was more of a 3 wire connection. The fix is to use a difference amplifier instead of the voltage divider to measure the voltage with. I have now designed that into the circuit. This essentially eliminates the voltage sense leads being connected to ground, except through the battery ground.Now I am trying to understand why the battery - needs to be connected to the pcb ground.When going through the current flow of the design, I don't see any current from the battery needing to go through the pcb ground. It is limited to the specific traces used for the battery circuit. The only reason I can think that the battery ground would need to be connected to the pcb ground is if the batt- needs to be at the same potential as the pcb lower potential. Which is this case I don't think it needs to be. Voltage sensing of the battery is being done with a difference amplifier. After my reading on those the input to the divider is theoretically zero, and the output ends up being a potential difference between the inverting and non inverting leads. The current sensor doesn't care about the ground connection of batt-, and I don't think the mosfets do either, when their gates turn on, current flows from the higher potential to the lower potential.Quote from: Vovk_Z on February 09, 2024, 09:49:21 amThat is where the fuse is supposed to come in. If the mosfet internal shorts and gets stuck closed the voltage drop across the load will cause a current around 70-80A. The fuse is a schurter 50A fast blow fuse, although I'm not quite sure how long that is supposed to take to blow. I will admit the safety features need more work. For one, the fuse would never blow if this were a 1S lipo, and if a 2s lipo is discharged enough, it wouldn't supply enough voltage under the load to create over a 50A current flow either. This is another reason why I am going to change this to the linear fet sinking the current. If the fet creates an internal short there is no load at all for the battery to go through and it is a true short. Current theoretically goes infinite and the fuse should blow.

author: Manul
author_rank: Super Contributor
timestamp: February 09, 2024, 03:02:01 pm
content: Quote from: trilerian on February 09, 2024, 01:56:44 pmYou are still insisting, that ground is not needed. To be frank, your schematic is drawn horribly. The purpose of schematic is to make all relations between components and circuit blocks as clear as possible. Yours fails at that. Well drawn schematic makes even a complex design easy to perceive, bad schematic obfuscates even the most obvious and simplest circuits. I believe because of that schematic you have (kinda self-inflicted) confusion. See the image attached. Battery and load is in series, so you can connect them in two different ways. If you call circuit on the right "not connected to ground", ok, that's fair. I agree, technically speaking, it's not connected to ground. But the circuit on the right has a potential issue, that the battery common mode voltage is flying up and down when mosfet is switching. That will introduce extra and totally unjustified common mode noise to you kelvin sense wires. So the normal way of connecting things is left side circuit.Now I will redirect your question back to you , why Batt- needs to be connected to circuit ground?

author: trilerian
author_rank: Regular Contributor
timestamp: February 09, 2024, 06:05:27 pm
content: Quote from: Manul on February 09, 2024, 03:02:01 pmI wasn't insisting that the Batt- didn't have to be grounded. I was asking why it needed to be because I didn't understand why it needed to be. The whole conversation started with this is an issue due to the grounding of the 4 wire connection and Batt-, essentially being a 3 wire connection. Which I still don't understand, but there is a whole world of electronics that I don't understand. Sometimes you just fix what someone tells you to fix. But in light of the issue, I am trying to understand why Batt- needs to be grounded. This makes no difference in whether or not I add the difference amplifier. I think the difference amplifier is a more elegant solution to a voltage divider and want to incorporate it. I'm just looking for understanding, that is all.Also, sorry about my schematic, I'll just leave it as I am a beginner, posting in the beginner forum, and will make bad mistakes and draw bad schematics. All I can do is try to improve on them as I learn more.EDIT: And I really do appreciate the help, and will go back and try to update my schematic.

author: Manul
author_rank: Super Contributor
timestamp: February 09, 2024, 08:45:43 pm
content: Sorry for being a little harsh. You know, they say good teaching should involve either jokes or harshiness, then things sink into head much better. I guess I'm out of jokes today. Sort of like "I have come here to chew bubblegum and kick ass. And I'm all out of bubblegum."Quote from: trilerian on February 09, 2024, 06:05:27 pmTake a look at picture 1. Battery, positive and negative wires with their own resistance and a load at the end. The reason you don't measure 10V at the load is becausebothpositive and negative wire have voltage drop (~100mV on each). So if you need accurate voltage measurement, that sucks.You say alright, I will add independent sense wires right at the battery to avoid issue with power wires droping voltage under load. Picture 2. Works like a charm. Even though sense wires also have resistance, but the current is zero, so no voltage drop. It is litterally like measuring right at the battery terminals with a multimeter.Now because of circuit implementation youjoinends of power negative wire and sense negative. Picture 3. Note that what you get is essentially power negative wire and sense negative wirein parallel. Two wires in parallel is essentiallyonewire! So load current now also flows through negative sense wire, it has voltage drop and you have measurement error.Quote from: trilerian on February 09, 2024, 06:05:27 pmThis comes from the fact that you use a directly driven mosfet for switching. Imagine for a moment that you use a relay instead. In a relay control coil and contacts are isolated. So you can drive the relay with your MCU and relay contacts are floating relative to MCU ground. Their are independent, not referenced to anything else. It would work very nice, just slow and contacts would burn with time.So you use a mosfet. Mosfet is controlled by the votage between gate and source. So you connect source to ground (0V) and switch voltage at gate. Nice. But notice that mosfet source terminal is used both for controlandas one of it's "contacts" (continuing relay analogy, another "contact" is drain). So you have no isolation. So anything what mosfet is switching is inevitably referenced to the circuit which controls it.There are isolated mosfet driving options. Those include using gate drive transformer, optocoupler, solid state isolated gate driver (last two require isolated power supply to power the isoltage side). If you implement something like that, you have floating mosfet switch. But don't do that, that's unjustified and too complicated for the task.

author: trilerian
author_rank: Regular Contributor
timestamp: February 10, 2024, 12:38:35 am
content: Quote from: Manul on February 09, 2024, 08:45:43 pmThank you for that explanation. I did not think of the negative sense wire being in parallel as I didn't think there should have been current running through the ground planeQuoteAnd thank you again, that makes sense.I'm going to mull this over a bit more, and I'll probably have more questions. But that does help clear that up a little.Thank you

author: trilerian
author_rank: Regular Contributor
timestamp: February 20, 2024, 01:18:40 am
content: The op amp circuit is not working at all.I am going to try to explain what voltages are where and I have made some screenshots, but they are kind of bad...Channel 2, (channel 1 inverting input not connected, non inverting is connected since it is the junction between the 2 cells). Channel 2, place low potential probe on a ground, connect ground of battery to the circuit as well because there is a potential difference. Ok. With the high potential probe, measure the non inverting input before any resistors (battery ground). 0V - Ok, good. Measure the inverting input before any resistors, cell 1. 3.85V - ok, good, storage charge. Measure non inverting at op amp channel 2 input. 3mV. Hmm, this should still be zero... Ok, measure inverting op amp channel 2 at input. 1.79V. And measure channel 2 output, 3.17mV.The op amp I chose is:MCP6497T-E/SNhttps://www.mouser.com/datasheet/2/268/MCP6496_Data_Sheet_DS20006758-3078050.pdfI am completely lost...I'm going to try to figure out how to use ltspice and see if it can help. But I am lost.Thanks

author: Manul
author_rank: Super Contributor
timestamp: February 20, 2024, 04:41:43 pm
content: I think you have your input polarity wrong going into difference amplifier. Non inverting (+) input branch must be connected to the positive side of your battery, inverting (-) must be connected to negative side (I mean, relative potential). Man, you need to always double check these things. Easiest is probably to just rewire the cable.

author: trilerian
author_rank: Regular Contributor
timestamp: February 20, 2024, 05:15:29 pm
content: Quote from: Manul on February 20, 2024, 04:41:43 pmSo higher potential goes to the non inverting, and lower potential goes to the inverting inputs? The inverting input has the feedback and the non inverting has the divider to gnd?I have attached a schematic of the part to verify.Thanks

author: trilerian
author_rank: Regular Contributor
timestamp: February 20, 2024, 05:54:13 pm
content: I flipped the inputs just to test, and that does make it work... But now I am even more curious. Measuring the high potential on the pin gives half the voltage. Voltage divider, so that makes sense. Measuring the voltage on the inverting pin gives half the voltage as well. Which if the output is the full voltage would make sense. Right, the inverting essentially is a voltage divider from the Vout to the low potential. If the resistors are the same value, half of Vout. Interesting. I realize there is a lot more to it, and I have watched a few videos and read a few articles on this now. But this is the way my brain is processing it...

author: trilerian
author_rank: Regular Contributor
timestamp: February 20, 2024, 09:50:21 pm
content: I cut some traces and soldered in jumpers. Now both sides are working. I had to remove the resistor from the output filter, but leaving the cap still seems to get rid of the pwm frequency, so... Stable voltage on the outputs and all the way up to the pins on my microcontroller, but the adc is fluctuating a lot more. Will have to track that down.

author: trilerian
author_rank: Regular Contributor
timestamp: February 20, 2024, 10:04:26 pm
content: And, as a follow up. All that work and it solved nothing. Voltage under load still reads about 0.01V lower than either of my bench DMMs.

author: Manul
author_rank: Super Contributor
timestamp: February 20, 2024, 11:19:25 pm
content: Quote from: trilerian on February 20, 2024, 09:50:21 pmYou can't remove filter resistor, it may lead to op amp instability and oscillation. It's a must for most op amps.Quote from: trilerian on February 20, 2024, 10:04:26 pmAre you serious? 10mV lower than bench DMM? That's actually a very good result you got there. DMM is a precision instrument, your circuit is not.

author: trilerian
author_rank: Regular Contributor
timestamp: February 20, 2024, 11:55:54 pm
content: Quote from: Manul on February 20, 2024, 11:19:25 pmNot the feedback resistor. The low pass filter resistor after the op amp.QuoteI understand that. And I need to do some more testing, but I originally started this thread because of that issue. Voltage under load was 10mV less than what my DMM read. At least at the battery terminals. I coded out the error, but it was proportional to the current, luckily it was just a simple slope. But if I change the load resistance, the values change, so I was hoping to fix that.EDIT: Hah, I started this thread with a 100mV difference, now I am down to 10mV. Well, that is 10x better, lol. Ok, I will do more testing to confirm results, and if it stays at 10mV, I can live with that.

author: Manul
author_rank: Super Contributor
timestamp: February 21, 2024, 12:11:03 am
content: Quote from: trilerian on February 20, 2024, 11:55:54 pmYes, the low pass filter resistor! You CAN'T remove THAT.Quote from: trilerian on February 20, 2024, 09:50:21 pmStable only because your DMM is averaging and integrating. In reality your op amp is most likely oscillating. That's why adc is fluctuating. Put back the low pass filter resistor!Quote from: trilerian on February 20, 2024, 11:55:54 pmYou stated like 120mV or something. Well, 10mV in 4 volt range is like 0.25%. That's GOOD. Come on, think about that, you have only 10bit ADC, your resolution is 4mV, plus ADC likely has some offset, ADC is sampling single ended, not differential, layout not perfect, maybe some small ground level shifts, plus op amp offset, gain error, plus maybe some other errors. That's very good what you got. Real engineering is not like math on a paper where everything is perfect. Otherwise engineers whould have no job, only mathematicians would.

author: trilerian
author_rank: Regular Contributor
timestamp: February 21, 2024, 01:57:02 am
content: Quote from: Manul on February 21, 2024, 12:11:03 amWait, the low pass filter isn't in any of the designs I saw online. And when I have that in, it decreases the output to 0.7V instead of 3.4V.I am attaching a pic of the schematic and arrows pointing the resistors I have removed.

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 21, 2024, 06:31:05 am
content: I would try to use at least 22-47 R there. But as you know look at the resulting voltage drop. Seems you ADC is consuming a lot of current. You may play with different capacitances there too. And you may add opamp buffer/filter instead of pure passive. But 10 mV error is pretty fine for existing simple solution.

author: Manul
author_rank: Super Contributor
timestamp: February 21, 2024, 09:17:46 am
content: Quote from: trilerian on February 21, 2024, 01:57:02 amSimple to remember: most op amps can't drive capacitive loads. Capacitor on the output of op amp generally is big no-no. With series resistor it's ok, because then the op amp "sees" a resistor, not capacitor, or at least "less" the capacitor, "more" the resistor.Your filter with 5k1 is a good filter, keep it. If you see such a voltage drop with series resistor in, than something is hugely wrong. Maybe capacitor is cracked, maybe ADC is half fried or something else. Is it so on both channels?

author: trilerian
author_rank: Regular Contributor
timestamp: February 21, 2024, 01:39:02 pm
content: Quote from: Manul on February 21, 2024, 09:17:46 amOk, that makes sense. I can remove the capacitor too and see what it looks like on my scope. I can also try other values for the low pass. But yes, it has the big voltage drop on both channels. This filter works fine without the op amp setup.EDIT: Alright, nevermind. I must have had something wrong. I put the resistors back in and it is fine.

author: trilerian
author_rank: Regular Contributor
timestamp: February 22, 2024, 06:39:29 am
content: I have another question . This is related to the input conditions of the op amp. It states that neither input voltage can exceed Vdd-Vss. In my case that is 5V. Technically, cell2 of the lipo positive side is up to 8.6V above ground due to it being in series. However, there is the voltage divider on the non inverting input. So does that mean the input only sees the divided voltage? If I measure the voltage at that node it is fine, and I just want to make sure I am not stressing the max ratings.

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 22, 2024, 08:07:46 pm
content: There are two modes or two states which you may want to investigate to be sure: steady state and transients (when power-up and outboard external).You are fine with steady state mode because as you see you have a voltage divider. And it is not so obvious with all types of transients. You may quite in a simple way look at power-up transients with an oscilloscope, I guess. And it is much more variants what you may get from external world (like battery loose contacts and any other possible outer influence.

author: Jwillis
author_rank: Super Contributor
timestamp: February 22, 2024, 09:14:05 pm
content: Arbitrary changing resistors on an opamp is'nt going to get you far. Know what gain you want. From the looks of it you are looking at a 2 gain for each opamp. so each resistor needs to be measured to give exactly 2 gain for each opamp. You work this out a non-inverting design formula. So for a 2 gain Re 1,3, 5,and 6 need to be measured and matched to give a precise gain.Another problem is the Input Offset Voltage. The MCP6497 has an input Offset Voltage of -1.6mV min and +1.6mV max, That's a span of 3.2mV, which is quite a bit. That then is multiplied by the gain. Then that error is multiplied again because your using 2 opamps to give a finale result. Compounding errors.Do you know what the actual Input Offset Voltage of each opamp?The The MCP6497 has no Offset trim built in, so that has to be done externally. By being able to trim the offset and having a precise gain you can guarantee that the output will be correct.

author: trilerian
author_rank: Regular Contributor
timestamp: February 23, 2024, 12:35:43 am
content: Quote from: Vovk_Z on February 22, 2024, 08:07:46 pmOk, I will check power up, connecting and disconnecting with my scope, so long as it doesn't go over Vdd-Vss, i should be good?Quote from: Jwillis on February 22, 2024, 09:14:05 pmI do know what I want, and I chose resistors to get the gain I want... R1 and R2 are 11K5 and R3 and R4 are 10K. This is what I am looking for. Drop up to 4.35V to below 4.096V. 4.096V is my ADC reference. I am using 0.1% resistors, and still matching them.Is there a mathematical way of determining the input offset, or is that just do some measurements? As of right now, the measurement is within 3mV for both channels added together, and since I am using a 10 bit ADC, I'm not getting more accurate than that. Well, without oversampling at least.

author: helius
author_rank: Super Contributor
timestamp: February 23, 2024, 02:58:06 am
content: A lot of advice about optimizing the circuit, but have you researched if you are just seeing normal battery voltage delay?Lithium and lithium-ion cells have passivation covering the plates, and this causes voltage to dip and then recover when they are put under load.

author: trilerian
author_rank: Regular Contributor
timestamp: February 23, 2024, 04:39:28 am
content: Quote from: helius on February 23, 2024, 02:58:06 amWell that is interesting. I will have to look into that as well. How long would this delay happen for?Quote from: trilerian on February 23, 2024, 12:35:43 amI checked this out on my scope and on my SDM3055 in fast mode. I never saw the voltage go over 3.8V after the divider. I performed quite a few manual tests and it just goes to 3.8V right away. I tested at 2Hz sample rate and faster sample rates. Attached is a screenshot of the scope output. I tapped the plug to the terminal a few times to make sure I wasn't missing anything.

author: Vovk_Z
author_rank: Super Contributor
timestamp: February 23, 2024, 11:50:34 am
content: Quote from: trilerian on February 23, 2024, 04:39:28 amSeems fine to me. In general, when you have at least several kOhms between any opamp input and any potential harm source those several kOhms (11 k in your example) work as good enough resistance to make any possibly harmful opamp input current low enough (less than 1 mA), if it will arise somehow. Typically that is a quite safe current which must not harm typical opamp input.So, this may be it ('Good enough for Australia').

author: trilerian
author_rank: Regular Contributor
timestamp: February 27, 2024, 07:27:20 pm
content: Got a new question, on the same subject, but not this design. I opened up a premium charger/discharger to see how it handles the voltage sensing. Looks like it is using components marked "E23", which after a search come up as biased resistor built-in transistor. The inputs from the cells go into the transistors and the outputs go straight to the mcu. And nothing it seems to take care of the grounding issue... Would this still be considered a 4 wire? Also, this is dividing the voltage, or reducing the voltage on the output, I understand that it can act like a regulator on the output, just not sure how that is calculated. All the cells use the same part, one for each cell.