Controlling a DC-DC Buck converter using Arduino

Hi all,

I made this DC-DC converter for my solar panel and was hoping to use the PWM output from the Arduino to control it. However, it doesn't seem to be working. I think the voltage from PWM output is not high enough to turn the MOSFET on. I am trying to step down 17V to 12V. When everything is connected I get a voltage of 3.5 on both output which means that the buck converter is not working as it should.

Here is the full circuit diagram.

|500x132

Totally unsuitable to use a microcontroller.

Use a chip designed for the purpose.

Can you recommend a chip?

Without voltage feedback that circuit is not a DC to DC Buck converter. It will only catch and hold the input voltage with no load on it. Why do you expect it to regulate the voltage? It is more like a sample and hold circuit as you have it.

Well that is the way it is shown in textbooks. The MOSFET switches on and off very quickly and the inductor and capacitor keep a steady flow of power to the load.

If this is not correct, can you tell me how to fix the circuit?

The IRF540 is not a logic fet, and therefore not really suitable for an Arduino.

You need feedback to keep the voltage constant.

Try a $1.50 buck converter from ebay. Leo..

I need to use the arduino as I am doing a project on comparing different mppt algorithms. The program on the arduino will increase or decrease the pwm duty depending on output power. I need to log the power data to measure efficiency of the algorithm using the arduino.

What type of logic fet would be suitable for this project?

Well, there are a number of complexities here.

Firstly, you are using a N-channel FET to perform "high-side" switching. This means that to drive the gate you need a pulse of 7 V more than your maximum input voltage, so you would need a driver circuit set up to do this.

Even if you were to use a P-channel FET to perform "high-side" switching, you would need another component to drive it as it would also have to switch the full input voltage.

If it were convenient to use a low-side switch, you would require a "logic-level" FET to switch directly from the Arduino which can only output just under its 5 V supply.

Given that the load (which you have bizarrely described as a LED strip but given it a resistance value which does not make sense at all) is in fact constant, then you may perhaps be able to stabilise the conversion ratio as long as the source remains fairly constant, as using a MCU (or computer in general) to control feedback is usually far too slow to be usable. Usable in the lab powered from a regulated variable power supply, perhaps not for a solar cell in a real situation which may be subject to rapid shadowing from foliage or birds etc.

The problem is L1 - this will almost certainly be a ferrite cored inductor, so it will saturate if the
current gets too high and become in effect a zero-ohm resistor. Bang!

SMPS’s need protection circuitry to detect over current and shutdown before the saturation
of the inductor caused destructive currents to flow - you cannot run them open-loop and expect
them to survive.

If you use an air-cored inductor (which cannot saturate), then, yes, in theory you just use the
duty-cycle to control the voltage ratio (in practice losses mean very poor voltage regulation, and
air-cored inductors are huge (think some the size of a coke can using 200 grammes of copper).

Basically real-world inductors are not in any way ideal and you cannot treat them as such, you have
to worry about things like saturation and thermal run-away.

Apart from the above excellent suggestions, any MPPT controller needs a feedback loop to provide some kind of input to the controlling device to control the PWM ratio. If you are trying to maximise the output power, then there must be some method of measuring it.

All other considerations aside, of which there are many, no one has yet mentioned the MOSFET’s internal diode, I notice. And guess which way it’s pointing…

Even when the MOSFET is off, the diode will still conduct.

So I don’t know why the output only measured 3.5V. Perhaps the solar panel was in the shade, allowing the 20 ohm??? load to pull the voltage down to 3.5V?

If the panel is truly 17V, 2A, (34W), and the load really is 12V, 20 ohms, (constant 20 ohms, for LEDs?, as Paul__B pointed out), the only thing in beteen is the MOSFET’s internal diode, about an 0.8V forward voltage drop at this current, so I would expect much more than 3.5V output.

This is yet another example of why the internal diode should always be drawn on a MOSFET. It’s too easy to forget that it’s there.

@myster619, it IS NOT shown that way in textbooks at all. (None worth reading, anyway. :slight_smile: )

I’ve attached the ‘true’ diagram of the relevant part of the circuit.

Edit: I think that Grumpy Mike was nearest, in calling it a ‘sample and hold’ circuit, but it’s not really even that. It’s more of a rectifier with an L-C filter.

MOSFET internal diode.JPG

I forgot to mention. There are two Voltage & Current sensors on input and output of the circuit connected to the Arduino to calculate the powers. The program decides whether to increase or decrease the duty cycle depending on the output power. This is the feedback I think you guys are wondering about.

The 40W solar panel has Voc = 21.6V and Isc = 2.58A The Vmp = 17.2V and Imp = 2.33A

I bought a logic level FET IRL540 and replaced the previous one. I get a 0V output when the input is on Drain and output on Source. There are conflicting texts everywhere regarding whether Source is input or output.

When the input is connected to Source and output to Drain, I get an output of about 12V and the input is also about the same which means it is just a short circuit which cuts the voltage to 12V because of the load and the buck is not working. I am expecting the input to be 17-19V and output to be 12V. The strange part is when I turn the Arduino off, it still turns on the LED strips with the latter connection.

The internal diode is built in the MOSFET so I don't think it could be big problem.

The LED strip is 12V, 7.2W which equates to 0.6A and 20 ohms.

Hope this helps.

myster619:
I forgot to mention. There are two Voltage & Current sensors on input and output of the circuit connected to the Arduino to calculate the powers. The program decides whether to increase or decrease the duty cycle depending on the output power. This is the feedback I think you guys are wondering about.

The 40W solar panel has Voc = 21.6V and Isc = 2.58A
The Vmp = 17.2V and Imp = 2.33A

I bought a logic level FET IRL540 and replaced the previous one. I get a 0V output when the input is on Drain and output on Source. There are conflicting texts everywhere regarding whether Source is input or output.

When the input is connected to Source and output to Drain, I get an output of about 12V and the input is also about the same which means it is just a short circuit which cuts the voltage to 12V because of the load and the buck is not working. I am expecting the input to be 17-19V and output to be 12V. The strange part is when I turn the Arduino off, it still turns on the LED strips with the latter connection.

The internal diode is built in the MOSFET so I don’t think it could be big problem.

The LED strip is 12V, 7.2W which equates to 0.6A and 20 ohms.

Hope this helps.

Where do I start? You said “When the input is connected to Source and output to Drain, I get an output of about 12V and the input is also about the same”.
That’s in direct conflict with what you said in your first post, but closer to what I would expect.
Is that result with your LED panel connected? Noticeably, you wanted 12V out and you have it, with only the backward MOSFET and the inductor in series with the load.

Can you please show your ‘complete’ circuit, with all Arduino connections, including your voltage and current sensing? Not just the connection to the MOSFET gate. We’re left to imagine what you’re doing.
Are you connecting your Arduino ground to the buck converter ground?

From what I can see, (and imagine), you still have other problems to contend with, and the full circuit will make it much easier to help you.

Edit: You said:-

When the input is connected to Source and output to Drain, I get an output of about 12V and the input is also about the same which means it is just a short circuit and the buck is not working. I am expecting the input to be 17-19V and output to be 12V. The strange part is when I turn the Arduino off, it still turns on the LED strips with the latter connection.

This is to be expected because the MOSFET’s diode will conduct whether or not the Arduino is connected when the source is connected to the circuit’s input.

And you don’t need to draw a fancy schematic on the computer - just draw a reasonably neat labelled schematic on paper and scan it then attach it to a reply. That’ll be fastest. :slight_smile:

Too hard to draw the complete circuit. Basically the sensors (red square) have In+, In-, Out+, Out- and three analog signal outputs. One is placed in between the solar panel and Cin and the other between C2 and Led strip. The three analog signals are for voltage, current and ground which are connected to the Arduino Analog inputs.

I do have the Arduino ground connected to the buck converter ground.

The LCD reads

Vin, Iin, Pin Vo, Io, Po

Open picture in a new tab for larger picture.

|500x281

myster619: Too hard to draw the complete circuit.

So you're working on a circuit that complicated without drawing a schematic for yourself? Even I wouldn't do that. And if it's "too hard" for you to do such a simple thing, it's too hard for me to bother helping further, except to say one more thing.

I do have the Arduino ground connected to the buck converter ground.

Since the Arduino is connected to the buck converter ground, you need to re-think everything. See Paul__B's post #7. For the Arduino to successfully switch an N-channel MOSFET in this configuration, even using your new logic-level MOSFET, it would need to be capable of supplying a minimum of 2V more than the solar panel output voltage. You obviously have absolutely no idea what you're doing, or how the basic components work.

I used the schematic I provided in the first post.

This is the full schematic that I drew up for you Steve.

|500x400

I didn't know that the Vgs had to be 2V above the Vds. I thought the MOSFET would be controllable by a 0-5V continuos pulse.

When the mosfet is "on" the gate has to be 5volt higher than the source (and drain).

So the Arduino has to be able to deliver 26volt pulses...

myster619:
I used the schematic I provided in the first post.

This is the full schematic that I drew up for you Steve.

I didn’t know that the Vgs had to be 2V above the Vds. I thought the MOSFET would be controllable by a 0-5V continuos pulse.

Sorry to sound so rude before, but I was just calling it as I saw it. (I get a bit blunt sometimes. :slight_smile: )

That diagram is fine - we don’t need the LCD and other stuff, just the things relevant to the buck converter.

Short of adding a ‘high-side’ driver which would need to generate a voltage higher than that of the solar panel, the best thing is probably to use a P-channel MOSFET, with it’s source connected to the input, drain to the inductor, a pullup resistor from gate to the +Vin, then a transistor pulling the gate low to turn it on.
I just tried to upload a small diagram from one of my recent circuits, but am having PC trouble and need to reboot first. I’ll upload it shortly.

Well, my PC problem persists after rebooting, but I’ll sort it out later.

This is the MOSFET setup I was describing, (attached), with values that should work OK. You can drive the transistor base with an Arduino, and as long as the frequency isn’t exceptionally high the 270 ohm pullup resistor should turn the MOSFET off fast enough.
If you use a different MOSFET to the one I’ve drawn, make sure it has a nice, low ‘Rds on’ value. (Even lower than the MOSFET shown would be better, but in my circuit I was switching a lower current so 0.2 ohms was fine.)

Edit: And note that with a P-channel MOSFET, the source connects to the input, and the internal diode points in the right direction.

P-channel.JPG

OldSteve: a transistor pulling the gate low to turn it on.

I didn't understand this bit. What do you mean? Do you think you can draw a schematic for connection?

If I choose to use the N channel logic level MOSFET, how can I fix it? Do I have to get a driver? Can I use a driver chip for this? Otherwise can I connect a lead from solar voltage in series with the gate voltage to make it greater than Vds? I plan to use a frequency of 490kHz.