Author Topic: Constant current PWM  (Read 1887 times)

0 Members and 1 Guest are viewing this topic.

Offline ZeroResistanceTopic starter

  • Frequent Contributor
  • **
  • Posts: 585
  • Country: gb
Constant current PWM
« on: April 23, 2019, 06:08:16 am »
I desire to maintain a constant current through a load. The load could would be inductive or resistive.
The simple circuit would be in the  form of the attached image.

I am sensing current through R2 which would be around 0.1 to 0.3 ohm.

What kind of interface would I need in the box named "CIRCUIT" in the image to connect to the microcontroller (Arduino) ADC.

1. I was wondering if the low impedance of the current sense resistor would affect the ADC functioning.
2. Would a simple zener clamp just work out to protect the ADC pin from over voltage. My mosfet drain voltage could be between 12V to 50V.
3. Do I need a Op amp Buffer over there?
4. Some filter possibly to de-noise the current waveform?
5. For the algorithm would it as simple as switching the uC pin on then waiting for the current to rise over the set value and if the current crosses that value switch off the uC pin and wait  for the current to drop below a hysteresis value and switch the pin back on again.
Then this becomes some kind of psuedo PWM isn't it?
Or is there a pure PWM alternative to this, by Pure PWM i mean plain old duty cycle control of a fixed frequency signal?

Regards,
Zero
« Last Edit: April 23, 2019, 06:43:56 am by ZeroResistance »
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6202
  • Country: ro
Re: Constant current PWM
« Reply #1 on: April 23, 2019, 06:42:03 am »
Not enough specifications.  Depending of what you need to use it for, it may work, or it may not.
What is the destination of that circuit?

As shown there, it is a switched on/off circuit, there is no constant current.  If the load is OK with that, then go on, but if the load is sensitive and can not stand the max current, than a new design is needed, with the MOSFET working in the linear regime.
The box named "Circuit" can be a simple resistor.  There are internal protection diodes on the microcontroller pins.

About the amplification for ADC, apart from the default 5V Vref for the ADC, most of the Arduino type of boards have 1.1V internal reference, and also is possible to have an external reference voltage smaller than 1.1V, so an amplifier might be avoided.  Also, there is the oversampling trick, in order to increase the resolution of the ADC.  Again, depends of the precision and the speed specifications (that are missing from the initial description of your circuit) if there is enough time to do that, or not.

I did something very similar recently, a constant current discharger for AA batteries, in order to measure how much energy they really store.  Didn't used PWM, implemented a PDM instead (Pulse Density Modulation), because I needed adjustable resolution much bigger than an 8 bits PWM.  Used this technique for PDM:  https://hackaday.io/project/6356-delta-sigma-versus-pwm and implemented it with interrupts on an Arduino nano.

Making a digital control loop with a microcontroller (to keep your current constant) is a very complex task.  Sometimes it might not even be possible, depending on how good and how fast the control loop needs to stabilize the load current.

You didn't say the range of the current, and how fast should the whole loop stabilize.  Those are very important for digital control.  An analog current control loop will be much simpler to design, and more robust.
 
The following users thanked this post: ZeroResistance

Offline ZeroResistanceTopic starter

  • Frequent Contributor
  • **
  • Posts: 585
  • Country: gb
Re: Constant current PWM
« Reply #2 on: April 23, 2019, 06:47:56 am »
Not enough specifications.  Depending of what you need to use it for, it may work, or it may not.
What is the destination of that circuit?

As shown there, it is a switched on/off circuit, there is no constant current. 
Ok I corrected my question.
The load is inductive.
So the inductance would act like a damping mechanism to prevent fast changes in current.
The inductance would be around 100 to 200uH. Max current not more than 10A. I don't mind a minor ripple in the waveform say +/- 0.5A is OK.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19523
  • Country: gb
  • 0999
Re: Constant current PWM
« Reply #3 on: April 23, 2019, 09:55:23 am »
Current only flows in R2 when the MOSFET is on, so your circuit won't be able to sense the decay in current, when the MOSFET is off. If the resistance and inductance are fixed, then it's possible to calculate the decay from the current when the MOSFET is shut off and wait for that period, before turning it on again.

To sense the current in the inductor, the current sense resistor needs to be in series with it, which complicates matters: either move the inductor to the low side or the sense resistor to the high side. One simple but more expensive method is to use a Hall effect sensor to monitor the inductor current.

I wouldn't use an MCU for this. A comparator with hysteresis is all that's needed.
 
The following users thanked this post: ZeroResistance

Offline ZeroResistanceTopic starter

  • Frequent Contributor
  • **
  • Posts: 585
  • Country: gb
Re: Constant current PWM
« Reply #4 on: April 23, 2019, 10:35:31 am »
Current only flows in R2 when the MOSFET is on, so your circuit won't be able to sense the decay in current, when the MOSFET is off. If the resistance and inductance are fixed, then it's possible to calculate the decay from the current when the MOSFET is shut off and wait for that period, before turning it on again.

To sense the current in the inductor, the current sense resistor needs to be in series with it, which complicates matters: either move the inductor to the low side or the sense resistor to the high side. One simple but more expensive method is to use a Hall effect sensor to monitor the inductor current.

I wouldn't use an MCU for this. A comparator with hysteresis is all that's needed.

That's superb Zero999 and good catch!!! :-+ I don't know how I missed that!! it was right under my nose and I couldn't see it :palm:

I didn't quite get he hall effect sensor part. How would that work out. Would that mean measuring the magnetism in the inductor?

Good idea regarding the comparator too gives me some food for thought!!
With the comparator too would the current have to be sensed to ground and some kind of PMOS be used?
Many thanks!
« Last Edit: April 23, 2019, 10:49:17 am by ZeroResistance »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19523
  • Country: gb
  • 0999
Re: Constant current PWM
« Reply #5 on: April 23, 2019, 11:06:34 am »
In this context a Hall effect sensor is just a type of current transducer and should be kept as far away as possible, from any stray field generated by the inductor. The downside is increased cost.
https://www.google.com/search?safe=active&client=firefox-b&ei=3dy-XJCzLNmb1fAP0uafyAk&q=hall+effect+current+sensor&oq=Hall+effect+cur&gs_l=psy-ab.1.0.0l10.5025472.5029259..5030286...3.0..1.303.2031.8j8j1j1......0....1..gws-wiz.......0i71j0i131j0i67j0i131i67j0i10.Dl8oMjsEauY

In theory the inductor could be either on the high or low side. If you can find a comparator which can run with its inputs at the positive supply, then you can use that. Alternatively use a P channel MOSFET and put the sense resistor on the low side.

In any case, there will need to be some level shifting to control the MOSFET, which was covered in another one of your threads.
https://www.eevblog.com/forum/beginners/understanding-p-mosfet-drive/
 
The following users thanked this post: ZeroResistance

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6202
  • Country: ro
Re: Constant current PWM
« Reply #6 on: April 23, 2019, 11:20:33 am »
Well, I see the specs are different now.  OK.   :D

Also note, you can not move the coil on the GND side.  If you do that, then you will need 50V+Vg of your MOSFET of choice, in order to fully open the MOSFET.

The topology is different according to what you want to achieve.  It might be better to just use a dedicated analog stabilizer, hard to guess what you have in mind.  That is why I'm afraid I can not help you any further, unless you answer the question I already asked:  What is the destination of this circuit, as in what are you planning to use it for?
 
The following users thanked this post: ZeroResistance

Offline ZeroResistanceTopic starter

  • Frequent Contributor
  • **
  • Posts: 585
  • Country: gb
Re: Constant current PWM
« Reply #7 on: April 23, 2019, 11:42:02 am »
Well, I see the specs are different now.  OK.   :D

Also note, you can not move the coil on the GND side.  If you do that, then you will need 50V+Vg of your MOSFET of choice, in order to fully open the MOSFET.

The topology is different according to what you want to achieve.  It might be better to just use a dedicated analog stabilizer, hard to guess what you have in mind.  That is why I'm afraid I can not help you any further, unless you answer the question I already asked:  What is the destination of this circuit, as in what are you planning to use it for?

What's an "analog stabilizer"?
I need to control the position of a solenoid piston which depends on the current flowing thru' the solenoid.
 

Offline filssavi

  • Frequent Contributor
  • **
  • Posts: 433
Re: Constant current PWM
« Reply #8 on: April 23, 2019, 12:06:19 pm »
the easiest thing you can do is to use low side sensing, low side switching and put the load circuit in series with the inductor,

if you can’t do that, you have to use high side switching that is more difficult as you need a isolated power supply for the gate and level translation for gate signals (depending on the desired edge rate that can be easy or very hard)

In any case you need to move the sense resistor in series with the load, as in the shown circuit you are shorting the load with the sense resistor and when the mosfet is ON no current will pass through the load
 

Offline ZeroResistanceTopic starter

  • Frequent Contributor
  • **
  • Posts: 585
  • Country: gb
Re: Constant current PWM
« Reply #9 on: April 23, 2019, 12:26:46 pm »
the easiest thing you can do is to use low side sensing, low side switching and put the load circuit in series with the inductor,

How do we achieve all these 3 things together? This was the exact intent of the circuit given in the first post. However the sense current turns off with the Mosfet as Zero999 rightly pointed out.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Constant current PWM
« Reply #10 on: April 23, 2019, 01:22:56 pm »
High side sensing is a lot easier than high side switching.  Move R2 to above L1 but within the L1, D1 loop and the interrupted current sensing problem goes away.  That should be simple enough to do as long as the rail is under about 70V with an 'over the top' OPAMP (see https://www.analog.com/media/en/reference-design-documentation/design-notes/dn533f.pdf ), otherwise isolated sensing will be required.

With 100uH of inductance and 50V across it during the 'PWM' on time, ignoring its resistance, the dI/dt is 500000, so to maintain a ripple current of 0.5A pk-pk, the on time resolution must be of the order of 1us.  This is too fast for software control on an affordable MCU, so the switching controller must be implemnted in hardware.   It should be possible using a Microchip PIC with a CLC (configurable logic cell) or with any other MCU that has configurable  autonomous logic, comparators, and some means of setting precision analog comparator thresholds, but on an AVR based Arduino, there's no configurable logic and I don't believe the 16 bit PWM module is versatile enough or fast enough to handle the required function, so an external hardware control loop to drive the MOSFET will be required.
« Last Edit: April 23, 2019, 01:53:22 pm by Ian.M »
 
The following users thanked this post: ZeroResistance

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6202
  • Country: ro
Re: Constant current PWM
« Reply #11 on: April 23, 2019, 01:38:52 pm »
This kind of application seems to be needing a SMPS where the coil is also the load.  I wouldn't put the microcontroller to stabilize the current.  Instead, let the stabilization to be done by an analogical circuit, and use the microcontroller just to set the desired current.

This poster has most of the possible topologies of SMPS:  https://www.techpowerup.com/articles/160/images/switching_reglation_topologies.pdf 

Choose one that suits the application and the type of MOSFET available, then see at the bottom of the table which dedicated IC to do the stabilization part.  If more details are needed for the design, TI has a handbook for that, https://www.ti.com/seclit/ug/slyu036/slyu036.pdf
 
The following users thanked this post: ZeroResistance

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1438
Re: Constant current PWM
« Reply #12 on: April 23, 2019, 01:41:55 pm »
Hello,

There is a relationship between the current vs time in R2 and the current vs time in the inductor, but you probably dont want to be bothered by that so a different setup is probably best.  All you have to remember is since you want to sense current in the inductor, you need to have the sense resistor in series with the inductor itself.  You'll still probably end up having to average that reading however because the current usually is not constant.  It depends on the value of the inductor and the PWM frequency.  With f=5kHz and L=100uH however the ripple current will be quite high, so high in fact that it may end up in discontinuous operation which is probably not what you want.
 
The following users thanked this post: ZeroResistance

Offline ZeroResistanceTopic starter

  • Frequent Contributor
  • **
  • Posts: 585
  • Country: gb
Re: Constant current PWM
« Reply #13 on: April 23, 2019, 01:57:19 pm »
High side sensing is a lot easier than high side switching.  Move R2 to above L1 but within the L1, D1 loop and the interrupted current sensing problem goes away.  That should be simple enough to do as long as the rail is under about 70V with an 'over the top' OPAMP (see https://www.analog.com/media/en/reference-design-documentation/design-notes/dn533f.pdf ), otherwise isolated sensing will be required.

With 100uH of inductance and 50V across it during the 'PWM' on time, ignoring its resistance, the dI/dt is 500000, so to maintain a ripple current of 0.5A pk-pk, the on time must be of the order of 1us.  This is too fast for software control on an affordable MCU, so the switching controller must be implemnted in hardware.   It should be possible using a Microchip PIC with a CLC (configurable logic cell) or with any other MCU that has configurable  autonomous logic, comparators, and some means of setting precision analog comparator thresholds, but on an AVR based Arduino, there's no configurable logic and I don't believe the 16 bit PWM module is versatile enough or fast enough to handle the required function, so an external hardware control loop to drive the MOSFET will be required.

Hi some amazing deductions! The "over the top" op-amp sounds good too. However I don't have one in my tool box at the moment.
How about a op-amp controlled current source driving a mosfet in closed loop. The uc would then only need to feed in the set point. I had tried that few weeks ago however the op-amp used to oscillate sometimes. Is there a way to stabilize the op-amp.

@Rogeorge and @MrAl
Thanks for your marvelous suggestions too!
« Last Edit: April 23, 2019, 02:24:34 pm by ZeroResistance »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Constant current PWM
« Reply #14 on: April 23, 2019, 02:43:12 pm »
That will work if you compensate the feedback loop properly but, at 10A  load current and 50V supply voltage, there's going to be a lot of dissipation in the MOSFET.  You'll probably need several, which must be rated for linear operation, to handle the  worst case peak dissipation, and each will need its own control loop, (OPAMP + sense resistor) with a common control voltage to provide the current setpoint.   Its either going to need a *BiiiiiiiiiiG* heatsink for passive cooling or fan cooling.    Around 100W per heatsink is easily achievable with commodity CPU coolers, which fits in well with typical MOSFET package dissipation limits.

However I believe a linear solution is the wrong way to go about it.   

* Do you need extremely fast control of the solenoid  current? 

If not, putting a low resistance 1mH choke with a  saturation current  >10A in series with it would go a long way to tame the PWM control requirements as it would reduce the max dI/dt by slightly over an order of magnitude, reducing the required on time resolution accordingly.  If you can adequately model the solenoid, it would be possible to run it open loop from a MCU PWM output, and get approximate current control with acceptable ripple, then run a much slower software control loop to tweak the open loop setpoint for precise control.

If its got to handle different solenoids with no user intervention to set parameters it gets somewhat more complex, and if it cant exercise the solenoid to determine the parameter on startup, it becomes rather challenging.
 
The following users thanked this post: ZeroResistance

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Constant current PWM
« Reply #15 on: April 23, 2019, 02:58:13 pm »
You can google for 'High side current sense amplifier'

https://www.analog.com/en/analog-dialogue/articles/high-side-current-sensing.html

Wouldn't you know it, the app note talks about solenoid control.

Personally, I would see if the mechanics of the situation wouldn't accommodate a linear actuator.  No excess power dissipation, simple stepper motor control and a number of ways to implement position feedback.
 
The following users thanked this post: ZeroResistance


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf