Electronics > Projects, Designs, and Technical Stuff

adjustable 500mA bipolar current control for PCB trace electromagnet

(1/7) > >>

I'm experimenting with magnetic actuators and have had success generating a magnetic field using a motor driver to push 500mA through a copper wire in series with 5 Ohm power resistors to limit the current.

I'd like to modulate this current, so I came up with the following design (schematic attached delow): High-side current into an h-bridge IC is read by a current sense amplifier and 0.1 Ohm shunt resistor, fed into a microcontroller ADC, which modulates the PWM duty cycle into that h-bridge.
(I believe this is how the fancier current-limiting motor drivers work internally.)

I'm running at 5V and max 500mA current, using cheap parts that can be assembled quickly by JLCPCB (Hence the Chinese h-bridge datasheet.)
Given the relevant component specs:

amp bandwidth is 210kHz
microcontroller ADC sample time is 16us (60 kHz)
h-bridge max PWM freq is 250 kHz

I think I should be able to have a few kHz control loop no problem.
However, I've never designed this kind of thing, so figured I should ask for advice / warnings / suggestions for new players like myself =D

amp: https://datasheet.lcsc.com/lcsc/1811021124_Texas-Instruments-INA180A2IDBVR_C192764.pdf
h-bridge: https://datasheet.lcsc.com/lcsc/2008171535_Bardeen-Micro.-BDR6122T_C724035.pdf
microcontroller: https://www.st.com/resource/en/datasheet/stm32f401cc.pdf

With a nearly whole dynamic range (i.e., 500mA nominal, but short-circuit is only a bit more at 1A), there should be little if any price to pay for getting the output stuck on, or for missing out on momentary peaks or whatever, so it's a good learning environment for the controls -- who cares if it's badly compensated, or oscillating, at first; you have all the time in the world to adjust it to perfection.

This contrasts with SMPS, where the price for failure of a digital control might be 10 times or more fault current into an ill-conditioned (e.g. low resistance or shorted) load, or peak voltages causing breakdown of switching devices.  More care is needed in that case; and one can develop experience in a simpler environment like this. :-+

60kHz sample rate means a maximum bandwidth of 30kHz (and something to do with aliasing beyond that), and the load should be 1st order (R + L) so the loop can run basically as fast as it can given the sample rate (a controller time constant of a couple samples) to give a 2nd order overall response.  Set up for doing input step response testing, and adjust parameters until it looks right.

It's not apparent what inductance you're working with; a "PCB trace magnet" doesn't sound very high, maybe a few hundred uH if that?  This has an L/R time constant of say 200uH/5Ω = 40us, a mere ten cycles at the switching frequency -- or far fewer at lower frequency or if the inductance is much less.  If the ratio is too low, you're basically just switching it on and off all the time, not controlling it as such, and the slower feedback loop certainly won't be able to do anything about that.

BTW if you haven't already planned it, sync the ADC and PWM, say every 4th cycle start an acquisition -- or sooner preferably but I'm guessing you can't run the ADC that fast (ATMEGA?), so run it as fast as spec allows.


Needless to say, this won't give a smooth current, but pulses.

It should be fairly easy to change it to give a fairly smooth DC, without having to dissipate lots of power in a resistor.

Replace the 5R series resistor, with an inductor and put the sense resistor in series with the PCB trace. Now the PWM will be smoothed by the inductor and the current sense amplifier will see the current, through the coil, rather than the power supply and it will use a fraction of the power.

Thanks for the responses y'all!
Tim, 100% agree that this is a friendlier project to learn on compared to a switched mode power supply =D

I hadn't considered inductance at all, and it's actually even worse --- similar PCB trace "coils" have inductances as low as 1--10uH.
Call it 5 uH, so with the fixed 5 Ohm resistance our time constant is 1us, which means the STM32 microcontroller's ADC sampling time won't be fast enough to provide meaningful feedback.

I could slow the coil rise times by adding more inductance (I can't remove the 5 Ohm resistance, btw, that'll be from the long, thin PCB trace "coil" --- sorry if I was confusing earlier, the power resistors were just stand-ins for trace resistance while breadboarding with copper wires).
However, based on my shopping around SMD power inductors, it'd take a few to sufficiently slow things down, which would add both to the BOM cost and coil resistance ($0.10, 100 uH, 0.5 Ohm per inductor).

What if instead of trying to do closed-loop current control through the microcontroller, I handled it with analog circuitry controlled via DAC (PWM + low-pass filter)?

E.g., LM393 comparator (1us response time) chopping a high-side P-MOSFET based on DAC output and voltage across low-side shunt (1 Ohm) underneath the h-bridge?
The h-bridge would then be controlled by plain GPIO rather than PWM, since current control would be handled by this comparator chopper.

Though a 1us response time comparator may be too slow also.
Perhaps I can use the microcontroller ADC and DAC to drive a MOSFET in its linear region?

The average current isn't going to change much for a given duty cycle, mostly it will vary as a result of the resistance changing due to thermal effects, a relatively slow process. You can use a high PWM frequency and check/correct the average current at a much slower rate.


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version