Constant current PWM - Page 1
Forum section: electronics / beginners

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: April 23, 2019, 06:08:16 am
content: I desire to maintain a constant current through a load. The loadcouldwould be inductiveor 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

author: RoGeorge
author_rank: Super Contributor
timestamp: April 23, 2019, 06:42:03 am
content: 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-pwmand 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.

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: April 23, 2019, 06:47:56 am
content: Quote from: RoGeorge on April 23, 2019, 06:42:03 amOk 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.

author: Zero999
author_rank: Super Contributor
timestamp: April 23, 2019, 09:55:23 am
content: 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.

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: April 23, 2019, 10:35:31 am
content: Quote from: Zero999 on April 23, 2019, 09:55:23 amThat'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 itI 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!

author: Zero999
author_rank: Super Contributor
timestamp: April 23, 2019, 11:06:34 am
content: 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.Dl8oMjsEauYIn 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/

author: RoGeorge
author_rank: Super Contributor
timestamp: April 23, 2019, 11:20:33 am
content: Well, I see the specs are different now. OK.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?

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: April 23, 2019, 11:42:02 am
content: Quote from: RoGeorge on April 23, 2019, 11:20:33 amWhat's an "analog stabilizer"?I need to control the position of a solenoid piston which depends on the current flowing thru' the solenoid.

author: filssavi
author_rank: Frequent Contributor
timestamp: April 23, 2019, 12:06:19 pm
content: 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

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: April 23, 2019, 12:26:46 pm
content: Quote from: filssavi on April 23, 2019, 12:06:19 pmHow 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.

author: Ian.M
author_rank: Super Contributor
timestamp: April 23, 2019, 01:22:56 pm
content: 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 (seehttps://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.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 23, 2019, 01:38:52 pm
content: 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.pdfChoose 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

author: MrAl
author_rank: Super Contributor
timestamp: April 23, 2019, 01:41:55 pm
content: 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.

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: April 23, 2019, 01:57:19 pm
content: Quote from: Ian.M on April 23, 2019, 01:22:56 pmHi 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 @MrAlThanks for your marvelous suggestions too!

author: Ian.M
author_rank: Super Contributor
timestamp: April 23, 2019, 02:43:12 pm
content: 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.

author: rstofer
author_rank: Super Contributor
timestamp: April 23, 2019, 02:58:13 pm
content: You can google for 'High side current sense amplifier'https://www.analog.com/en/analog-dialogue/articles/high-side-current-sensing.htmlWouldn'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.