I asked a previous question about whether a series resistor would be adequate for limiting the current for battery charging:

Limit battery charging current with simple resistor?

For some background: I'm charging a single NiMH cell and I'm going to control charge termination with an MCU by monitoring cell voltage and temperature. I'm doing this because I want more control than dedicated charging ICs provide.

So, I just need a way to limit charging current. I'll be charging at a maximum rate of 200 mA and had planned on just using a series power resistor as mentioned in the above question. However, I'm a bit worried about heat generation, as I have a narrow (1 cm) PCB in an enclosure. I plan to thermally couple the resistor to a USB connector as a makeshift heat sink, but I'm still a bit nervous. Would it be better to limit my voltage to something like 2-3 V with PWM first and then use a lower-value resistor to limit current? I'm using a load switch as shown below:

enter image description here

The second resistor (91 Ω) resistor shown is for an additional slow charging option. It's the heat generated by the 22 Ω resistor that I'm concerned about.

Would it better to use PWM to limit the voltage first? Would I then need an RC circuit to smooth the output? I'm also a bit worried about noise that PWM might introduce to my design, which has several analog sensors and a radio module.

I could alternatively use a switching regulator to limit the current, but again, I'm a little worried about noise.

  • 3
    \$\begingroup\$ Fail-safe is another consideration. PWM has the advantage of efficiency, but a firmware bug or a hardware crash due to external interference may cause microcontroller going out of control, leading to overcurrent. Resistors have heat dissipation and waste energy, and must be properly sized with adequate ratings. If the heat dissipation is high, the size can be large. But this has the advantage of fail-safe. However, risk can also be mitigated via firmware by watchdog timer and by using (built-in) hardware peripheral instead of software PWM bitbanging. It's up to you to make the judgement call. \$\endgroup\$ Dec 20, 2022 at 18:14
  • \$\begingroup\$ I hadn't considered that. Thanks! \$\endgroup\$ Dec 20, 2022 at 18:21

1 Answer 1


Would it be better to limit my voltage to something like 2-3 V with PWM first and then use a lower-value resistor to limit current?

Yes, but not just PWM. To reduce power loss you need to add an inductor in series, and a flyback diode to keep current going during the PWM off period. This will lower the effective voltage proportionally with very little loss, and the resistor will drop less voltage and waste less power. However as the voltage is less the charging current will vary more as the battery charges.

To maintain a constant current as battery voltage rises you could measure the voltage across the resistor to determine the current, and vary the PWM ratio to get it where you want. You could then use a single low value resistor (which is now just a 'current sense' resistor) to allow charging at both low and high currents without changing resistors, with higher efficiency and less heating.

If the battery isn't powering something that shares a common ground with the USB supply then you can put the sense resistor at the negative end of the battery and measure voltage directly between it and ground. This avoids the hassle of differential measurement.

The circuit would look something like this:-


simulate this circuit – Schematic created using CircuitLab

In operation the MCU slowly increases PWM ratio while monitoring the average battery current. When it goes above the desired value the MCU reduces the PWM ratio until current goes below the desired value, when it increases the PWM ratio again. This negative feedback loop maintains a 'constant' average charging current.

L1 controls the rate of current change according to the inductance formula:- $$\frac{di}{dt} = -\frac{V}{L}$$

With L1 'bucking' 3.8 V (difference between 5 V and 1.2 V) with its inductance of 470 μH, current would rise from zero to 200 mA in 24.7 μs. When PWM is applied the current increases and decreases as the PWM wave turns on and off, creating a triangle wave.

With a PWM frequency of 50 kHz (20 μs period) and ratio of 33% (6.6 μs on, 13.4 μs off) after about 50 PWM cycles the current will have 'walked' up to an average of 200 mA, with a triangular ripple of 50 mA. If battery voltage rises to 1.5 V the PWM ratio must be raised to 39% to maintain 200 mA.

Note that voltage drop across the current sense resistor (R3) will not affect the battery voltage reading, because you will turn PWM off and wait for the voltage to stabilize before measuring it.

Would I then need an RC circuit to smooth the output?

The battery itself will smooth the output. However a capacitor placed close to the inductor may help to reduce EMI by reducing the switching loop area.

  • \$\begingroup\$ Great, thank you! I may just try the resistor first to see if the heat is indeed too high, in which case I'll try your PWM circuit. \$\endgroup\$ Dec 21, 2022 at 18:53
  • \$\begingroup\$ I realize it's been a while, but I may try this circuit, because my resistor setup does generate a bit more heat than I'd like. Could you explain to the purpose or R1 above? My concern is that my MCU is 3.3V and not 5V tolerant. Does that affect whether the transistor will work as shown? \$\endgroup\$ Jun 20, 2023 at 0:06
  • \$\begingroup\$ R1 ensures that the MOSFET is turned off until the MCU runs your code and turns PWM output on (most MCUs set their I/O pins to input mode at startup). Plenty of MCUs are available that can run on 5V. If you must use a 3.3V only MCU then either pre-regulate the power supply down to 3.3V with a switching regulator, or put a level converter between the PWM output and FET Gate and a voltage divider between the battery and ADC 'volts' input. \$\endgroup\$ Jun 20, 2023 at 6:21
  • \$\begingroup\$ Thanks-- I like your idea of pre-regulating the power with a switching regulator, and I think I'll do that. Would the same FET work with 3 V input? \$\endgroup\$ Jun 20, 2023 at 16:34
  • \$\begingroup\$ Yes. It has 2.5V rated Gate drive. \$\endgroup\$ Jun 20, 2023 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.