Current sense with micro, and battery heater

A project log for LiFePO4wered/ESP32

ESP32 IoT core board with flexible power and flexible communications

Patrick Van OosterwijckPatrick Van Oosterwijck 08/28/2019 at 15:230 Comments

I got a FRDM-KL27Z development board to be able to test some things in the design before committing to them in a PCB layout.  Initially I had intended to use this to build and verify the complete charge buck converter, but that was before I realized I need a proper gate driver.  I am no @greg davill, you won't see me put together a dead bug prototype with 0.5 mm pitch QFNs under a microscope.  So a complete charge converter prototype won't happen before the PCBs are made.

But, I decided the dev board would still be useful to do some testing of the ADC for current sensing.  One of the reasons I chose the MKL17Z64VFM4 is because when I was designing the custom project this is based on, I liked the built-in ADC and reference of the MK02FN64VLF10 I was using for that project and found I could do current sensing directly with the micro using the differential 16-bit ADC inputs.  I decided I should verify whether this chip worked as well for the purpose.

Battery heater decisions

Surprisingly, the need for ADC data came out of the need to settle on a particular implementation for the battery heater driver.  I am driving the heater from the battery voltage in this design.  The idea is to again make things more automatic and easier for the user.  In the #LiFePO4wered/Solar1, I drive the heater from the incoming voltage.  The downside is that no MPPT happens, the heater has to be carefully designed to not overload the solar panel and make the voltage collapse.  In this board I want to power the heater from the battery (much more predictable), and supplement as much power from the external input as available.  I also want to use the solar power most efficiently, so MPPT is desirable for the heater power.  Instead of building a completely separate MPPT converter for this purpose, I'm using the charger MPPT converter and divert all available power to the heater up to the point where all power comes from the input.

There are two topologies I considered:

  1. Heater connected to battery ground, driven by an external voltage.  This requires the board to drive a voltage to the heater.  Just using a MOSFET to switch this voltage isn't safe, the output needs to be properly protected so I would preferable be using a load switch.
  2. The other option is to connect the heater to the battery's positive terminal, and pull the other end to ground from the circuit.  I looked hard to find low side load switches with integrated current limiting, but for the life of me I couldn't find anything suitable.  If anyone has suggestions I'm all ears.  So this would most likely be implemented as a MOSFET with thermal fuse.  I'm not a fan of thermal fuses, they are kind of sloppy.

In topology 2, you can see a single current sense resistor.  It's the battery current sense, but it can also measure the heater current.  More correctly: it can measure whether the heater driver is diverting all power from charging the battery to heating the battery.  We may not know what the current is exactly, but we know when the battery current is zero and can implement something in the MPPT control loop to maintain this.

In topology 1, you can see two current sense resistors.  One is to measure the battery current, the other measures the heater current.  It is necessary to add the second current sense resistor because the battery current sense provides no visibility into the heater current, we sense the current whether it flows through the battery or the heater.  The upside is that we still know the absolute current value.  We can build a control loop to make the heater current match the battery current.  The downside is that we need another current measurement, and it is a high side current measurement (near supply voltage).  This means we have to use a differential ADC channel for this.

Testing the ADC

"Remember kids, the only difference between screwing around and science is writing it down." — Adam Savage

Current sensing near either ground or supply is always potentially problematic.  The datasheet of the micro doesn't specify the common mode range of the differential ADC channels.  It depends on the actual circuitry implemented in the chip how well measuring near ground and supply works.  That's why it needs to be tested.  The voltage across the battery current sense resistor can actually be positive (charging) or negative (discharging) with reference to ground.  Of course, it's a tiny voltage of only 30 mV or so, but still, not all input stages can handle signals near ground, near supply or both.

I started screwing around with the dev board two days ago, but I saw some interesting/weird things that made me decide I needed to actually collect data and write it down (science!).  That's what I did yesterday.

Here are the results:

In the top table I measured differential input near ground and supply, with either input pin tied to the power rail, and with zero, positive and negative input relative to the power rail.  I also tested a single ended channel (referenced to chip ground) for comparison.  Because I have only two differential inputs, if I choose topology 1, I will need to use a single ended input for the current coming in to the charge converter, so I need to know how well it works.

The offset indicates the difference between what the micro measured and measurements taken with my 121GW meter.  Noise PP is the worst peak-to-peak noise on the raw measurements over 100+ readings.

Currents in the table are based on a 20 milliohm current sense resistor.  This value is a compromise to get usable readings for 1.5 A charge current range while not burning too much power, and is still subject to change.  Higher values give better readings but reduce efficiency, so a good balance has to be found.  20 milliohm is just a starting point to be able to reference the numbers to real life application data.

In the second table, I check how well the data can be offset compensated by taking a baseline at 0 V (zero current through current sense) and using that to compensate the raw readings.

Some thoughts on the data:

Actionable information:

I will have to think about this some more, but I'm currently favoring topology 3.