Author Topic: adjustable 500mA bipolar current control for PCB trace electromagnet  (Read 3569 times)

0 Members and 1 Guest are viewing this topic.

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
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
Thanks!


Datasheets:
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
 
The following users thanked this post: ROT

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 20043
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #1 on: November 28, 2021, 06:40:19 am »
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.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 17638
  • Country: gb
  • 0999
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #2 on: November 28, 2021, 04:20:09 pm »
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.
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #3 on: November 28, 2021, 10:18:12 pm »
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?
 

Online NiHaoMike

  • Super Contributor
  • ***
  • Posts: 8400
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #4 on: November 29, 2021, 03:07:51 am »
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.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2305
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #5 on: November 29, 2021, 03:56:42 am »
According to google translate, that bridge has a rise/fall time of 0.5us, so with a load time constant of 1us, that's not going to work out very well regardless of what's controlling the bridge.  You might be able to drive it faster, but then the bridge is going to dissipate more power as it won't have time to fully turn on in any given cycle, and it might even blow up if it doesn't have built-in cross-conduction protection.  500mA at 5V is only 2.5W, so linear control wouldn't be that bad, as long as you're not concerned about battery life or something.  The simplest way to do linear control is with an op-amp closing the loop between the sense resistor and the drive transistor, you'll need to compensate it for the load inductance but that shouldn't be too hard since both the power level and the inductance are pretty low.  If you've got a DAC channel available on the MCU you can use that to drive the set point. 

Your idea of using a comparator to switch the coil current when it hits a setpoint could work, but it needs to be a fast comparator and a fast power stage to deal with your inductor's rise/fall time.  You can find pretty fast comparators and power stages with conveniently built-in control loops in switching converter ICs, which is basically what you're talking about building, but even those tend to top out at a couple of MHz which is on the edge of what you'd need here. 

Instead of adding inductance directly in series with the inductor, you could use that extra inductance plus some capacitance to add what amounts to a buck converter *in front* of the load inductor.  You could use an actual buck converter IC for this, and drive its feedback pin from the MCU to trim its output voltage to provide the desired current, or you could use the MCU's PWM to directly drive a half bridge that in turn drives the inductor, and rely on the current feedback to close the loop directly (you could also measure and control the intermediate voltage if you wanted to, could be a fun exercise).  The frequency here doesn't particularly matter, provided that the ripple at the point where you connect the load inductor is low enough for your needs and accounted for in your control loop filtering.  This would still be relatively efficient, if that matters to you.

One other gotcha here, that applies to a lot of these methods, is that it sounds like you want to be able to reverse the coil polarity, right?  If you're using a bridge IC to do that polarity control, and if whatever is controlling the coil current is outside of the bridge IC, then you have to make sure that your current setpoint always result in a voltage across the inductor and sense resistor that's above the minimum operating voltage of the bridge IC.  If the DCR of the inductor is 5R, and that IC has a Vmin of 1.7V, your minimum current ends up being something like 340mA.  The solution to this is probably to use discrete transistors instead of an IC.  This allows you to get rid of the UVLO that many of those ICs include because your gate drive signals can still be at a reasonable voltage to get good switching performance even if the voltage supply to the bridge is only a volt or whatever.  It may be more complicated/take more IOs to drive the discrete bridge, but if you're only using it to change polarity and not to regulate current via switching, then you can use jelly-bean logic level parts and just make sure to include a little bit of dead time when changing polarity. 
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #6 on: November 29, 2021, 05:57:41 am »
Great point about the 0.5us rise time in the h-bridge, no way to chop the current from the outside.

You're right that I need to be able to reverse the coil polarity, which is why I've been thinking I need an h-bridge.
The datasheet for this one suggests that the undervoltage lockout only applies to VCC:

[attachimg=1]

so high-side current limiting on the "VM" input should work, yeah?
That's what I was getting at with the comparator --- it wouldn't be driving one of the h-bridge inputs, but rather a high-side transistor controlling the flow of current into VM.
That said, I'm not sure about the particulars of a comparator vs. opamp and (MOS)FET vs. BJT in this application, and whether the shunt resistor should be on the high or low side of the entire h-bridge.

I'm assuming that the amp will get driven into saturation during h-bridge dead-time / shutdown, but as long as it doesn't lock up there I'm hoping that won't be a problem.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 17638
  • Country: gb
  • 0999
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #7 on: November 29, 2021, 09:17:56 am »
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).
I don't see how you can do this, without more inductance. I haven't done any calculations, but if 100µH is sufficient and the resistance is 110 of the PCB coil, that's pretty insignificant and 0.10$ isn't expensive, unless the budge is extremely tight and you're making a large volume.

The only alternative is to use a linear Howland current pump and use smoothed PWM from the MCU, or an DAC output as the signal source.
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2305
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #8 on: November 29, 2021, 04:34:21 pm »
The datasheet for this one suggests that the undervoltage lockout only applies to VCC:

[attachimg=1]

so high-side current limiting on the "VM" input should work, yeah?
Ah, I missed that it has a separate Vm input, if that is truly able to operate all the way down to 0V then it should be fine, although I'd be skeptical of that without reading the rest of the datasheet. 

Quote
That's what I was getting at with the comparator --- it wouldn't be driving one of the h-bridge inputs, but rather a high-side transistor controlling the flow of current into VM.
That said, I'm not sure about the particulars of a comparator vs. opamp and (MOS)FET vs. BJT in this application, and whether the shunt resistor should be on the high or low side of the entire h-bridge.

A comparator is going to be better suited to chopping the power to the inductor, an op amp is better suited to linear regulation.  It looks like directly chopping the power supply to the load inductor isn't a viable option because of the low inductance, so if you wanted to do this with minimal parts and the easiest circuitry at the expense of efficiency, a linear solution with op-amp and transistor would probably be the way to go. 

Conceptually, there's not really a difference between low- and high-side current regulation, it's exactly the same topology just flipped upside down.  In practice, low side is usually easier because it allows your control signal (and optional readback signals) to be ground referenced, it's very easy to combine arbitrary load supply and control signal voltage levels, and you get more options in N-channel (low-side) FETs than in P-channel (high-side).  The downside to low-side is that your load is NOT ground referenced.  You can compromise a bit by doing low-side sensing and high-side drive, if the sense resistor is small enough then the load might be close enough to ground referenced for some applications.  FET vs BJT probably doesn't make a functional difference here, since the power is pretty low.

Since you want to have this H-bridge between the constant current driver and the load, you'll need to go high side on the drive at least, because the bridge still needs to receive ground-referenced logic signals.  If your sense resistor can be a low enough value it may still be fine to keep that on the low side of the bridge. 

Quote
I'm assuming that the amp will get driven into saturation during h-bridge dead-time / shutdown, but as long as it doesn't lock up there I'm hoping that won't be a problem.

A comparator will be fine with this, some op-amps take a bit of extra time to come out of saturation and you might need to be concerned about that depending on what your application can tolerate.  There are also some op amps with very limited differential input voltage ratings, so you'd need to make sure you don't accidentally pick one of those. 

With a linear constant current driver you generally do NOT want to EVER connect the load while the driver is active.  If the driver is set to deliver any amount of current while the load is disconnected, it will drive the transistor wide open attempting to get any current to flow at all, and connecting the load in that condition could give it a pretty big wallop before the loop recovers.  This can be avoided with additional circuitry to detect the voltage at the load terminal and disable the driver, although this might not really matter in your application.  At any rate, if you have the current setpoint and the bridge under MCU control, you can just make sure that you set the current to zero before switching the bridge around and avoid the whole problem. 

Assuming MCU control, I think I would be inclined to do something like the attached.  The two half-bridges shown here could be two halves of the existing bridge IC you have, the one on the right is used strictly to set the polarity, the one on the left is driven by PWM and forms a buck converter along with LBuck and CBuck.  The frequency of the buck stage doesn't really matter as long as the L and C values are chosen to suit, but higher frequency + lower L&C means faster loop response, but that only matters to the extent that your ADC can measure the load current fast enough.  Depending on the resolution and response time you need and the MCU you're using, you might want to run the PWM at a relatively low resolution and dither it so that you can run at a higher frequency.  Load current is measured as (VS1-VS2)/RSense and fed back into the loop driving the PWM in software.  Lots of MCUs these days have differential ADCs that could do that subtraction for you, but VS2 can probably be assumed to change slowly enough that could measure it less frequently and subtract it in the software loop.  Or you could skip measuring VS2 entirely if you decide that the resistance of the bridge and any fluctuations in Vcc are negligible for your purposes. 
« Last Edit: November 29, 2021, 04:37:44 pm by ajb »
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #9 on: November 29, 2021, 08:04:36 pm »
I don't see how you can do this, without more inductance.

Yeah, I don't think chopping (modulating the h-bridge on/off) is going to work given the low inductance of the load and the ~1us comparator response and h-bridge switching time. (Much less the 15us microcontroller ADC sampling time.)
The $0.10 SMD inductor I mentioned was just for ballpark, and they have max current ratings on the same order as my desired currents, so I'd need to make a little network of 'em.
It's maybe doable, but I suspect linear current control may be both cheaper and give less ripple.


ajb, thanks for your detailed thoughts! Responses inline:

Ah, I missed that it has a separate Vm input, if that is truly able to operate all the way down to 0V then it should be fine, although I'd be skeptical of that without reading the rest of the datasheet. 

What's the mechanism behind your skepticism?
That at low VM voltages the internal gate driver won't be able to open up the transistors?

if you wanted to do this with minimal parts and the easiest circuitry at the expense of efficiency, a linear solution with op-amp and transistor would probably be the way to go.

Yep, that's what I'm thinking as well.
I'll be duplicating this circuit a dozen times per board, so I'm hoping a cheap quad op-amp (LM324) driving BJTs will provide an inexpensive solution.

Since you want to have this H-bridge between the constant current driver and the load, you'll need to go high side on the drive at least, because the bridge still needs to receive ground-referenced logic signals.  If your sense resistor can be a low enough value it may still be fine to keep that on the low side of the bridge.

Yeah, a 1R sense between the h-bridge and ground would only raise it 500mV at my max current, which is well under the maximum allowed logic-low signal (0.3 * Vcc = 1.5V).

There are also some op amps with very limited differential input voltage ratings, so you'd need to make sure you don't accidentally pick one of those. 

Thanks for the heads-up.
The LM324 common mode max is Vcc - 1.5, so 3.5V in my application, which is fine since the sense would be low and the ADC output maxes at 3.3V anyway.
More interesting is that 3.5V is the max high swing, which means that this amp wouldn't be able to "turn off" a high-side PNP by bringing its base up to 4.3V (Vcc - 0.7).

If we use an NPN as a high side switch, then max current would be limited by the output voltage of the amp.
I.e., with a 5R load and the sense resistor and h-bridge Rdson contributing another Ohm we have a max current of (3.5V max output - 0.7V NPN base-emitter drop) / 6 Ohm = 460 mA.

Would I be asking for trouble using a high-side NPN BJT like this?

At any rate, if you have the current setpoint and the bridge under MCU control, you can just make sure that you set the current to zero before switching the bridge around and avoid the whole problem. 

Noted, this is great advice, thanks!

Assuming MCU control, I think I would be inclined to do something like the attached.

Thanks!
I want to make sure I calculate and understand the op amp + transistor current topology first, and then would love to compare your design.
(Which looks much better as it uses fewer components.)

I appreciate all this discussion, this is the first time I've had to design circuits like this and it's very helpful to hear from more experienced folks!
« Last Edit: December 01, 2021, 04:58:29 am by lynaghk »
 

Offline asdf336

  • Contributor
  • Posts: 11
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #10 on: November 30, 2021, 12:46:58 am »
As pointed out your sample rate doesn’t need to correlate to inductance but your switching frequency should.  Standard buck rule of thumb is about 40% ripple as determined by voltage, inductance and switching frequency.  ADC sample rate can be slower (but yes sync it to the pwm). 

Added L could help but isn’t it a clue that your pcb traces have too little L to begin with?

linear would be easier and better just less efficient.  Still 0.5A at 5V is only 2.5W.  I assume you could find power opamps in this range and use 2 to form a bridge driver (same concept as H bridge). 
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2305
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #11 on: November 30, 2021, 06:44:48 am »
Ah, I missed that it has a separate Vm input, if that is truly able to operate all the way down to 0V then it should be fine, although I'd be skeptical of that without reading the rest of the datasheet. 

What's the mechanism behind your skepticism?
That at low VM voltages the internal gate driver won't be able to open up the transistors?

Just that it's unusual for something like that to be specified down to 0V, because what application requires operation of an H-bridge at such low voltages? If it's truly specified that way, then that's kinda neat, I just didn't go through the trouble of translating enough of the datasheet to check. 

If you're doing a bunch of these channels per unit, there's another option that may become worthwhile.  If you can provide a bipolar power supply, then you can tie one end of each inductor to the midpoint (typically ground, but you could also use a split positive supply, in which case your midpoint would be Vcc/2), and drive the other end positive or negative without needing a full bridge to swap the polarity.  You can use the same basic op-amp constant current driver idea, with a couple of changes.  You'll need to add a second transistor to the output of the op-amp to form a half bridge, or optionally use a power op-amp that can provide enough current to drive the load directly.  The current sense resistor will need to be on the fixed side of the load, and your current setpoint signal will now be positive for current in one direction and negative for current in the other direction, and you can transition from one polarity to the other as smoothly as you like.

If you only had one of these channels then it likely wouldn't be worth the trouble of providing the required power supply to do this (if you don't already have it), but with a dozen or so channels it starts to make more sense.  You can also apply the same basic idea to the circuit I showed above, just eliminating the half bridge on the right side.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 17638
  • Country: gb
  • 0999
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #12 on: November 30, 2021, 12:22:56 pm »
I don't see how you can do this, without more inductance.

Yeah, I don't think chopping (modulating the h-bridge on/off) is going to work given the low inductance of the load and the ~1us comparator response and h-bridge switching time. (Much less the 15us microcontroller ADC sampling time.)
The $0.10 SMD inductor I mentioned was just for ballpark, and they have max current ratings on the same order as my desired currents, so I'd need to make a little network of 'em.
It's maybe doable, but I suspect linear current control may be both cheaper and give less ripple.
Does this have a bipolar, or single power supply?

One way to do this is with a Howland current pump, which can be made to work with either a single, or dual power supply. See links below:
https://www.ti.com/lit/an/snoa474a/snoa474a.pdf

https://www.eevblog.com/forum/projects/high-voltage-safety-and-design-considerations/
https://www.eevblog.com/forum/projects/need-help-with-bi-directional-constant-current-source-(100ma)/
https://www.eevblog.com/forum/projects/30a-precision-current-source/

The pain old op-amp + pass transistor can also be used, but it needs a dual supply, to get positive, as well as negative currents. If you only have a single supply, a rail splitter could be used, or an H-bridge connected to the output, to change the polarity of the current.


https://e2e.ti.com/blogs_/b/powerhouse/posts/how-to-generate-current-sources-and-sinks-of-arbitrary-magnitude
https://electronics.stackexchange.com/questions/129609/how-does-this-constant-current-sink-actually-work
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #13 on: December 01, 2021, 01:31:23 am »
Here's what I've got for the linear current + h-bridge topology:

[attach=1]

+ P-MOSFET selected because it can dissipate 1.5W
+ LM324 output only goes up to 3.5V, so I'm pulling up with a resistor so P-MOSFET can be closed; will this bother the amp?
+ RC low-pass filter to smooth 3.3V PWM control signal from MCU.
+ 3 Ohm sense resistor network so amp can better detect low current signals

Total cost is about $0.40 per channel, 1 PWM pin (current), 1 GPIO (direction).

amp datasheet: https://datasheet.lcsc.com/lcsc/1809051220_STMicroelectronics-LM324DT_C71035.pdf
MOSFET datasheet: https://datasheet.lcsc.com/lcsc/1810171817_Alpha-&-Omega-Semicon-AO3401A_C15127.pdf

This would all be running from a 5V single-sided supply.

The Howland pump is interesting, but seem like it might get complex / expensive for 100mA--500mA currents.
I'd also need to up my analog noise / SPICE modeling skills significantly =D

The bipolar supply idea is also quite interesting.
Say it's +/- 5V and have an op amp powered by these rails.
How would I generate the control signal if the microcontroller PWM is always between 0--3.3V?
« Last Edit: December 01, 2021, 05:02:19 am by lynaghk »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 17638
  • Country: gb
  • 0999
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #14 on: December 01, 2021, 09:07:01 am »
Here's what I've got for the linear current + h-bridge topology:

[attach=1]

+ P-MOSFET selected because it can dissipate 1.5W
+ LM324 output only goes up to 3.5V, so I'm pulling up with a resistor so P-MOSFET can be closed; will this bother the amp?
+ RC low-pass filter to smooth 3.3V PWM control signal from MCU.
+ 3 Ohm sense resistor network so amp can better detect low current signals

Total cost is about $0.40 per channel, 1 PWM pin (current), 1 GPIO (direction).

amp datasheet: https://datasheet.lcsc.com/lcsc/1809051220_STMicroelectronics-LM324DT_C71035.pdf
MOSFET datasheet: https://datasheet.lcsc.com/lcsc/1810171817_Alpha-&-Omega-Semicon-AO3401A_C15127.pdf

This would all be running from a 5V single-sided supply.

The Howland pump is interesting, but seem like it might get complex / expensive for 100mA--500mA currents.
I'd also need to up my analog noise / SPICE modeling skills significantly =D

The bipolar supply idea is also quite interesting.
Say it's +/- 5V and have an op amp powered by these rails.
How would I generate the control signal if the microcontroller PWM is always between 0--3.3V?
That will most likely oscillate and be very difficult to stablise, because the feedback is taken from the drain. If you use the LM324, which won't work with its inputs close to the positive rail, it must be an N-channel MOSFET/BJT with the feedback taken from the source/emitter.

Ignore my bipolar comment. The circuit I posted, will only either work as a sink, or source. It can't do both, even with a bipolar supply. :palm:

How many channels do you need?

 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 1501
  • Country: gb
  • Recovering Electrical Engineer
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #15 on: December 01, 2021, 12:36:35 pm »
Here's high current high speed bipolar CCS 2A/V dont forget the heatsinks![attachimg=1]


 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 17638
  • Country: gb
  • 0999
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #16 on: December 01, 2021, 01:26:21 pm »
Here's high current high speed bipolar CCS 2A/V dont forget the heatsinks![attachimg=1]
That's a good idea: make a Howland current pump from an instrumentation amplifier.

I strongly recommend adding some emitter resistors, otherwise during power-on, C1 will rapidly charge, causing a large current to flow through X2 & X3, which might damage them.

 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 20043
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #17 on: December 01, 2021, 06:27:28 pm »
Uhhh... that cap probably makes the thing unstable anyway, or something.  If you must have stable voltage at the op-amp pins, do a bootstrap supply with cascodes, zeners to the bases, and bypass it there (or better yet don't, because emitters don't appreciate bypass caps either -- and they should have low enough impedance to satisfy the amp already).  Otherwise -- particularly if it has adequate CMRR from the supply pins -- it should be fine strung between nodes, for the same reason.

Other than that, yeah, the general form is a traditional flying/floating/bootstrapped op-amp with power stage driven through its power pins.  Also mind thermal stability, such circuits (complementary open-collector mirrors or whatever) tend to run away easily.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #18 on: December 01, 2021, 07:22:05 pm »
That will most likely oscillate and be very difficult to stablise, because the feedback is taken from the drain. If you use the LM324, which won't work with its inputs close to the positive rail, it must be an N-channel MOSFET/BJT with the feedback taken from the source/emitter.

Hmm, I was following ajb's suggestion from earlier to do a high-side switch.
I don't think an N-channel won't work because when larger currents are flowing the load will have a 5+ Ohms and the LM324 won't be able to keep the N-channel's gate voltage high enough to stay open.
Situation would be worse for a BJT.

Re: oscillation, it's not obvious to me where the phase offsets are being introduced in my circuit, much less how to calculate them.
Conceptually, is the issue the capacitance of the mosfet gate?
(I found this long explanation which I'll study later; open to any suggestions for reading material on this: https://electronics.stackexchange.com/questions/358605/gain-of-opamp-circuit-with-current-output)

I have a few hesitations about the Howland solution:

1. I don't have a split supply, so would need to (learn how to) design one
2. I'm not sure how to shift a 0-3.3V PWM control signal to one centered at 0V
3. an instrumentation amplifier plus BJTs sufficient to source/sink 500mA of current per channel seems like it'll get expensive

If the op amp + mosfet linear regulation solution isn't workable, my inclination would be to try ajb's buck topology idea.
For that I just need to find a surface mount inductor capable of handling 500mA.
And learn how to do all of the calculations, of course =D
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 17638
  • Country: gb
  • 0999
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #19 on: December 01, 2021, 10:54:49 pm »
That will most likely oscillate and be very difficult to stablise, because the feedback is taken from the drain. If you use the LM324, which won't work with its inputs close to the positive rail, it must be an N-channel MOSFET/BJT with the feedback taken from the source/emitter.

Hmm, I was following ajb's suggestion from earlier to do a high-side switch.
I don't think an N-channel won't work because when larger currents are flowing the load will have a 5+ Ohms and the LM324 won't be able to keep the N-channel's gate voltage high enough to stay open.
It depends on the gate threshold of the MOSFET.

Quote
Situation would be worse for a BJT.
Why do you think that it would be worse for a BJT? On the contrary, a BJT would be better, as it turns on at only 0.7V, rather than a few volts for a MOSFET. The only issue is the base current might be too much for an LM324 to drive, but a Darlington pair would fix that.


Quote
Re: oscillation, it's not obvious to me where the phase offsets are being introduced in my circuit, much less how to calculate them.
Conceptually, is the issue the capacitance of the mosfet gate?
(I found this long explanation which I'll study later; open to any suggestions for reading material on this: https://electronics.stackexchange.com/questions/358605/gain-of-opamp-circuit-with-current-output)
If the feedback is taken from the emitter of a BJT, in the circuit I posted, there's no extra voltage gain. The inverting input of the op-amp sits a base-emitter voltage drop below the op-amp's output. If the feedback is taken from the collector, or drain, the feedback voltage will change a lot, for a tiny change in the op-amp's output. The op-amp is not designed to be stable, with an extra gain stage in the loop. The op-amp will be designed so its gain is below 1, when the phase shift exceeds 180o, to prevent oscillation and adding an extra gain stage within the loop, boosts the gain, causing it to oscillate.

Quote
I have a few hesitations about the Howland solution:

1. I don't have a split supply, so would need to (learn how to) design one
2. I'm not sure how to shift a 0-3.3V PWM control signal to one centered at 0V
3. an instrumentation amplifier plus BJTs sufficient to source/sink 500mA of current per channel seems like it'll get expensive

If the op amp + mosfet linear regulation solution isn't workable, my inclination would be to try ajb's buck topology idea.
For that I just need to find a surface mount inductor capable of handling 500mA.
And learn how to do all of the calculations, of course =D
1) It can be bridged.
2) No problem. Filter it to an analogue signal of 0V to 3.3V and connect the negative input of the Howland pump to half 3.3V.
3) It depends on your budget. I doubt an instrumentation amplifier IC would cost that much more than the current sense amplifier IC you're using.
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #20 on: December 02, 2021, 01:48:22 am »
Thanks a ton Zero999!

You're right about the BJT, I was thinking about the voltage drop but forgot that the same applies to the MOSFET and its threshold is larger.

What you said about op-amp feedback makes a ton of sense as well --- try and keep extra gain out of the feedback loop when possible.
Presumably the less gain overall, the less gain above unity at 180 degree phase, so no oscillation.
Thanks for walking through that example with the circuit you posted earlier.

Driving a darlington pair, hmm.
With two darlington diode drops we'd have a max voltage at the emitter of 3.5 V - 1.2 V = 2.3 V, which with a 6 Ohm load resistance means current would limited to about 400 mA.

Hard to beat on price, though, 7 channel darlington array for $0.20, much cheaper than a MOSFET.

Re: Howland, an instrumentation amp per channel would be much more expensive than the 1/4 of a $0.13 quad LM324.

Of course, all this is probably more expensive than ajb's inductor + PWM solution, still thinking about that one...
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 17638
  • Country: gb
  • 0999
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #21 on: December 02, 2021, 10:40:30 am »
Thanks a ton Zero999!

You're right about the BJT, I was thinking about the voltage drop but forgot that the same applies to the MOSFET and its threshold is larger.

What you said about op-amp feedback makes a ton of sense as well --- try and keep extra gain out of the feedback loop when possible.
Presumably the less gain overall, the less gain above unity at 180 degree phase, so no oscillation.
Thanks for walking through that example with the circuit you posted earlier.
Looking back at the circuit, there's another error: the op-amp inputs are the wrong way round. The MOSFET is in common source configuration, meaning that it's an inverting amplifier, so as the op-amp's output voltage drops, the voltage on U1 increases, causing the functions of the op-amp's inverting and non-inverting inputs to reverse.
https://www.eevblog.com/forum/projects/adjustable-500ma-bipolar-current-control-for-pcb-trace-electromagnet/msg3846563/#msg3846563

Quote
Driving a darlington pair, hmm.
With two darlington diode drops we'd have a max voltage at the emitter of 3.5 V - 1.2 V = 2.3 V, which with a 6 Ohm load resistance means current would limited to about 400 mA.

Hard to beat on price, though, 7 channel darlington array for $0.20, much cheaper than a MOSFET.

You didn't say how many channels you needed.  A Darlington array can't be used for more than one channel, because the emitters are commoned. You could use one Darlington array for the two transistors on lower side of the H-bridge, with the bases connected to diodes on the op-amp's output, to implement current limiting. You also need to check the power dissipation. If you opt for an array, it would be advisable to connect several channels together, to spread the power dissipation.


Quote
Re: Howland, an instrumentation amp per channel would be much more expensive than the 1/4 of a $0.13 quad LM324.

Of course, all this is probably more expensive than ajb's inductor + PWM solution, still thinking about that one...
Using a switched mode configuration is definitely a good idea. I will save power and won't generate so much heat.
 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 1501
  • Country: gb
  • Recovering Electrical Engineer
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #22 on: December 02, 2021, 10:51:36 am »
I have used it with out stability issues being apparent.
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #23 on: December 02, 2021, 06:12:10 pm »
Good catch on the Darlington array, I was looking only at the individual unit schematic and didn't realize the array connected both the COM *and* the emitter E terminals of all the units in the array.

I read up more on LC and buck circuits yesterday so will have a go at PWM modulation for that approach, will post a schematic here later with a SPICE simulation, assuming I can figure out one of the free packages (LTSpice or Micro Cap).
 

Offline lynaghk

  • Contributor
  • Posts: 13
  • Country: us
Re: adjustable 500mA bipolar current control for PCB trace electromagnet
« Reply #24 on: December 03, 2021, 04:59:20 am »
Turns out Micro-Cap is pretty cool. I managed to cook up a simulation of ajb's buck bridge idea.

I modeled the h-bridge IC using an IRF9540 and IRF540 (picked arbitrarily from the extensive catalog in Micro-Cap) and am driving with a 250kHz PWM signal as per the IC's recommended max.

PWM will be driven by a 16-bit counter on an STM32 running at 84 MHz.
Maybe timers are limited to 42 MHz?
Can't recall, but either way I'll have sufficient resolution for the PWM duty cycle for a 250kHz signal.

The chart shows multiple PWM duty cycles with the current (red) and corresponding 12-bit ADC reading to be expected.
With the 3 Ohm sense resistor I'm only using about half of the ADC's dynamic range, but I'd rather lose small-current resolution in favor of making sure I can get up to the 500mA max current in the event that the PCB traces get manufactured with a few extra Ohm of resistance.

I chose the 4.7uF and 100uH values arbitrarily.
Aside from making sure the SMD inductor can handle 500mA of current, anything else I should take a look at here when selecting components?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf