# Controlling High Currents with Microcontroller

Discussion in 'Microcontrollers, Programming and IoT' started by user112358, Oct 30, 2014.

1. ### user112358

3
0
Oct 30, 2014
I would like to deliver a more or less continuous range of currents up to 3 A to a ~5 ohm load. Our power supply is a 6 V or 12 V NiMH battery, and we would like to be able to use an Arduino Mega to control the current (in the 0 to 3 A range) that is supplied. What's the best way to go about something like this?

2. ### Gryd3

4,098
875
Jun 25, 2014
If you want to control the current supplied, this won't be a simple switch...

Additionally, if you want to push 3A through a 5Ω load, you will need a supply of greater than 15V or will need a boost voltage converter.
What kind of electronics experience do you have?

3. ### Anon_LG

453
117
Jun 24, 2014
GRYD3 You stolen what I was going to say about the current! For 3A you could use a relay or a power transistor. The power from the arduino is going to have to go through amplification before the relay coil though in order to activate it, also with the power transistor the current gains are not very high, you are also going to need to go through amplification before feeding into one.

The calculations for current:
6 volts/5ohms= 1.2 amps
12 volts/5ohms= 2.4 amps

4. ### Gryd3

4,098
875
Jun 25, 2014
Ninja'd!

Additionally, the op could PWM to supply a specific voltage to the load. If the load has a known stable resistance of 5Ω, it's only a matter of a little math to figure out the duty cycle that will result in the desired current. This would not be ideal if the load's resistance changes though...

5. ### Anon_LG

453
117
Jun 24, 2014
Gryd3 likes this.
6. ### hevans1944Hop - AC8NS

4,630
2,159
Jun 21, 2012
Don't forget that the OP, @user112358, wants a continuously variable range of current from zero to about 3 A to his 5 Ω load. How about a pulse width modulator connected to a boost supply that delivers 15 V? It could vary both the duty cycle and the pulse repetition rate, charging an output capacitor to deliver the necessary current. Vary the duty cycle until some minimum current is produced at a fixed PRF (ordinary PWM) and then, at that duty cycle, begin to decrease the pulse repetition rate to approach zero current. Should be a "piece of cake" to program an Arduino Mega to do that. Advantage: practically zip for power dissipation. Disadvantage: some increased ripple at lower currents because of the variable decreasing pulse repetition rate.

I don't know of any other way to reach zero output with a PWM. Some circuits just turn the PWM output off, instead of lowering the PRF, after reaching a minimum threshold. It is then turned back on again when the difference between actual output (filtered) and the command value reaches another threshold. This can have a pulsing, or strobe, effect on the output which may be undesirable. You could also implement a hybrid approach, where a linear circuit operates at very low current outputs and the PWM takes over at some intermediate current and continues to bear the load until maximum current is reached.

7. ### (*steve*)¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥdModerator

25,500
2,840
Jan 21, 2010
if you have a triangular (or sawtooth) compared to a variable voltage then all you need to do is to ensure that the variable voltage can get to below and above the range of the ramp voltage to ensure that you have 0% and 100%.

Most circuits that can't get to 0% or 100% employ a variable duty cycle oscillator where it becomes impossible to charge or discharge the capacitor in zero time.

hevans1944 likes this.
8. ### hevans1944Hop - AC8NS

4,630
2,159
Jun 21, 2012
I was thinking that with a fixed PRF the pulse-widths could never be zero-width, but you are correct that comparing a ramp against a setpoint to generate the pulses would do the job. Thanks for the tip. I should have remembered this.

9. ### BobK

7,682
1,688
Jan 5, 2010
Since they would be generated by a micro, the pulse can certainly go from 0 to 100%.

Bob

10. ### hevans1944Hop - AC8NS

4,630
2,159
Jun 21, 2012
So, I guess we are all agreed that a PWM, driven from a boost switching supply to provide 15 volts across a 5 ohm load or 3 A output current, would provide the OP with a solution that could be implemented with a simple Arduino Mega controller... anybody here actually done this? I have both an Arduino and a Raspberry PI at home, but sadly have not taken the time to learn how to use either one. Maybe later this year...

11. ### Anon_LG

453
117
Jun 24, 2014
I agree with the above solution, does anyone else have any objections?

Oh and off topic from the OP you should learn how to use the Arduino, you can effectively plug this in, upload the program and run with the
Arduino but with the raspberry pi it involves configuring a file to run the script, as well as this the raspberry pi is much pickier with its power supply and I would say C is by far the more straightforward language of the two. The Pi does have its advantages but for IO and ease of use the Arduino is preferable.

12. ### Gryd3

4,098
875
Jun 25, 2014
You can program the Pi with C
I do agree that the arduino would be much easier to get up and running.
The Pi can be programmed with a mirage of languages, but is trickier to get up and running.
I have both, and am currently using the pi as a very small web-based development linux box.

13. ### hevans1944Hop - AC8NS

4,630
2,159
Jun 21, 2012
Whoa! Program a Pi with C? And probably have to learn to use Linux too, eh? Does anyone remember Scotty, in Startrek IV: The Voyage Home, picking up a computer mouse and trying to give it voice commands? This movie was made in 1986! Surely a Raspberry Pi can understand my spoken instructions by now! <sigh>

Well, I guess the Arduino takes the prize for being "friendly" to hardware geeks. So, I think I will try that first (eventually). Does it have an assembler? Or do I have to use C? I know, RTFIM (read the fine instruction manual)...

14. ### Gryd3

4,098
875
Jun 25, 2014
The pi can be programmed in bare-metal, or can be loaded with an OS.
Once an OS is present you can 'program' it with scripts, or compiled binaries. You are welcome to write the scripts in php, java, bash, or sh... etc. any supported language will do. Same thing with your binary... as long as it can be compiled to the proper target architecture, you can use any language you want. The tricky part about the pi is the initial setup. It's not quite as easy as plugging in a USB port. If you skip programming it bare-metal, you can remotely log-in to the OS and update your program at any time over a network connection, or plug in a usb KB and monitor and work right on the pi. It's less of a 'microcontroller' and more of PC programming with access to hardware pins.
... I should also mention that you can get the Pi to work with voice prompts It just takes a little coding.

15. ### hevans1944Hop - AC8NS

4,630
2,159
Jun 21, 2012
Let me get back to you on that... after I do some homework.

And... "a little coding"? Ain't no such thing. Coding always grows to fit the available execution space.

16. ### user112358

3
0
Oct 30, 2014
I'm not exactly sure where to find a PWM like what you're describing... any suggestions?

17. ### BobK

7,682
1,688
Jan 5, 2010
All of you may be convinced, but I am not.

The OP has not stated what the load is. For some loads, PWM is appropriate, for others it could be disastrous.

Bob

18. ### user112358

3
0
Oct 30, 2014
Yeah, the load is pair of Helmholtz coils... I was thinking I'd have to use some kind of filter, but I'm not sure exactly how that would work. Is there some sort of voltage converter whose output could be adjusted in proportion to a PWM signal from the Arduino? We've tried an op amp (OPA548 I think) but it dissipated a lot of power and went into thermal shutdown after about a second of operation.

19. ### Gryd3

4,098
875
Jun 25, 2014
Can't you just filter the PWM output?

20. ### BobK

7,682
1,688
Jan 5, 2010
At that point, you might as well throw in an inductor and have a switching power supply. In fact, that is probably the best solution.

Bob