Buck converter using Attiny84 (PWM frequency change)

Hi there,

I'm new here on forum and new in world of MCU's.

First of all, sorry for my bad english, im from Croatia.

I have an idea for buck converter and i want to use Arduino Uno for prototype and i already downoaded pwm.h library so i can easily change frequency to about 32 kHz without interrupting with delay() and other time related functions.

But when i finish my regulator i want to move it to another PCB and i want to use attiny84 because is cheap and have enough I/O pins for all functions that my converter will have.

Will PWM library work with Attiny84 or i will have to change PWM frequency by another way ?

Hi, welcome to the forum.

Which PWM library are you using ? You can give a link to it.
There are so many PWM libraries.

The ATtiny84 has almost identical timers inside. So either this library or another, I’m sure there is a library that does what you want.

Hi, and merry christmas.

Im using this one: http://forum.arduino.cc/index.php?topic=117425.0

If this doesnt work with attiny84 i was thinking about manually changing pwm frequency by setting prescaler of timer to 1 and setting pwm into phase correct pwm

You might have to check the datasheet and the code side by side. The ATtiny84 is close to the ATtiny85, but one of the differences is the timers.

Could you use the ATtiny85 ? that one is more or less compatible with Arduino : http://www.adafruit.com/product/1501

I don't think Attiny85 will do the job. There isn't enough pins :/

These are specs. of my converter:

Type: Non-sychronous CCM buck converter. Voltage input: 32V Voltage output: 0-24V Current limit: 2 or 3A depending on the inductor i have at home. Switching frequency: 31.4 kHz Current sensing: 3x0R27, 2W non-inductive resistors Temperature sensor: LM35DZ Optional: 12V fan for cooling.

Maybe even a LCD for displaying voltage and current and keypad in the future instead of potentiometer.

Even Attiny84 isn't enough :(

Best solution would be simply buying 328P, enough pins, enough memory, and all libraries are compatible.

With 16MHz crystal i will be able to achieve 32 kHz PWM.

It is always good to start with something that will work. When you build it with a ATmega328P, you can test the components and the circuit. Maybe for a next version you can try an ATtiny. The smd version of the ATmega328P is also very small.

The inductace (and the ferrite core material) can make it more or less efficient. Some ferrite cores are for low frequencies, other core material for high frequencies. With the wrong inductance, I think it is possible to drive a core into saturation, perhaps it is called different. If you use a diode, you could try a few types. The current resistors seem very large, is is possible to use a lower value ? Do you need 31.4kHz ? Perhaps you can try to find the optimum, it could be a few hundred kHz. The capacitor at the output needs to be low ESR. Or you can use a few capacitors parallel. Pulses of a few amps into a capacitor at 31.4kHz is something most capacitors don't like.

I agree with you, it's much better for me to use 328P, with that MCU there is always room for improvement :)

Don't worry, i have experience with switching regulators, i will calculate inductor value according to my needs, also i already have 220 uF 35V low-ESR capacitors from another project so i will use them at output.

Ferrite core i'm going to use is from ATX power supply, the one at the output filter. This core is good for buck inductor because it is distrubed gap core. I'm very limited in choosing inductor core so i decided to use the one from PC power supply.

Maybe is better to set frequency to 62500 Hz, 328P is capable of switching output at that frequency. Or is it possible to push it even more ?

Anyway, i think that core from ATX PC supply is able to opearte at 100-150 kHz ?

Also there is limited choice of low value non-inductive resistors in my shop... But i can put more of them in paralel, about 6 of them would be enough. Resistance would be about 45mOhm, and with 3A passing trough them would give me voltage drop of about 135 mV which 328P ADC is able to detect.

This is first version, without voltage feedback, current control and advanced functions.

I was thinking of intergrating PID library and voltage and current feedback.

Thank you so much for your help, and any advice is more than welcome :)

I build a voltage multiplier today, it can do a smashing 0.1mA ! http://forum.arduino.cc/index.php?topic=142097.msg2016503#msg2016503 Okay, serious now, I mention it because the toneAC library can do a few megaherz. It uses a hardware timer output of pin 9 and 10. And it can switch smooth from one frequency to another. Also the Arduino standard tone() function can do a few megaherz. If you look at the reference page, there might be a link to someone who tested it.

I don't know if the ferrite core for an output filer can do 100 or 150kHz. You would have to know exactly what kind of ferrite-compound is used.

Do you know those Class-D switching stereo amplifiers ? Some use 500kHz switching mosfets and a filter. I have one of those and I suspect they just dropped in an inductance. But at 500kHz not just any inductance can be used. That is probably why sound experts advice not to buy that one.

A voltage divider to measure the output voltage with the ATmega chip would be the first thing to do :) Maybe not as feedback for a PID yet, but it can be used to log the voltage to the serial monitor, very handy.

I used output filter core in about 8 or 9 buck converters with UCC3808 and SG3525, switching frequency was about 130 kHz, maximum frequency i used with that inductors was about 175 kHz, and there wasn't any problems :) they are running cold for well over 2 years now :) efficiency is about 82 to about 87%

I could try to buy some ferritte cores on ebay that will work on higher frequency. But for now i would like to experiment a little with the core i have. It's easy reprogram the MCU for higher frequency :)

For MOSFET i will be using IRFZ44N, i have couple of them lying around workbench

For now, i will just print voltage, current and maybe efficiency on the LCD :) along with some other messages.

As for switching audio amps im trying to avoid them, i don't now, i like old fasion AB class amps with big heatsinks and toroid transformers :)

Very nice. You have done more with it than I did.

Thanks, i was always interested in power electronic, and now is time to go from analog to digital electronics :)

I'm taking baby steps, from basic buck converter to fully operational benchtop PSU :)

First i must find old PSU to tear it down so i can recycle components :)

I will use 20X4 character LCD for displaying output voltage, current and power, and some other messages like efficiency and output overload...

I have some notes, that might be worth mentioning:

The ATmega chip can do 40mA according to the datasheet, but 20mA is the normal maximum value. In most cases a logic-level mosfet is used with a resistor between the ATmega chip and the gate. That makes it slow of course.

So you need a mosfet driver chip for higher frequencies. I forgot the type, but I used a mosfet gate driver with mosfets combined with bipolar transistors for an extra blast of current into the gate.

The ATmega can measure voltages with the 5V as reference or an internal 1.1V. If you use a 7805 to power the ATmega chip, and that is 5% inaccurate, also the measured voltages with be 5% inaccurate plus the inaccuracy of the ATmega chip itself. So I often use the internal reference of 1.1V, but because the voltages are lower, it is more for signal shift due to ground currents.

And you need averaging a lot in the code. When reading an analog value, there is noise anyway. So you need to average a number of samples to get a stable value.

For a bench power supply, you might use a voltage reference, because the internal 1.1V of the ATmega chip depends on the temperature.

A fun thing to do is to use a DC-DC converter and use an Arduino inject current into the feedback with only a few resistors. Suppose 8 pins of the Arduino chip are used with different resistors (or resistor network). Each pin can be high or low or disabled (floating). That means 3 possibilities per pin to inject/draw current from the feedback to control the output voltage.

Thanks :)

I was thinking about totem pole mosfet driver, and i think that is the driver you cant remember :P

That or special MOSFET driver in DIP form, like IR or UCC, i think i have some UCC at home :) It's 3A peak driver. That is more than enough for one IRFZ44N MOSFET

So external voltage reference ? Should good. old TL431 do the job ?

I need 5V power supply for MCU, 12 to 15V power supply for MOSFET driver. And external voltage reference of 5 V or should i use lower voltage like 3.3 or 2.56V ? or even 1.1 V

I think the TL431 is in the same range as the internal 1.1V reference. That is why I bought a LT1019-2.5V recently. Without any adjustment it has an accurate voltage. But I have not used it yet.

An external reference of 5V is not possible, it might be higher than the VCC of the ATmega328P. You can start with the internal 1.1V. http://arduino.cc/en/Hacking/PinMapping168 The actual voltage can be measured at the Aref pin, it could be perhaps 1.085V. Use that in the calculation in the sketch.

With an external reference, the analogRead() function may not be used before the analogReference( EXTERNAL) is called, or else there is a shortcut between the internal and external reference.

The default reference is the 5V VCC of the ATmega chip itself. That is easy to use. The internal 1.1V reference is more accurate. For reading an analog value the voltage of the reference has little influence on the result. As long as the reference itself is good.

If your ATmega chip doesn't driver leds or other things, you can use a 7805 without heatsink or and LDO. However, if you want a display at 5V with backlight, the 7805 might get too hot when the input is 12V. I often use a DC-DC converter.

I will search for some more accurate voltage reference, but until then i will use internal 1.1V reference.

I have 7805 on my thermometer with LM35 and Attiny84 powering mcu and lcd and its running pretty much cold :) input voltage is 15V, current draw is about 30 to 40 mA.

Im searching for old supply now so i can take components from it

I was playing with internal reference and voltage mesurment and i was very happy with results :)

i compared several measurments:

UNI-T UT203: 4.32V 3.205V 2.756V 1.602V Arduino voltmeter: 4.317V 3.204V 2.754V 1.602V

Im planning to buy some precision resistors for voltage divider, and if you have reccomendations for precise voltage reference ?

REF194 or similar http://www.digikey.com/product-search/en/integrated-circuits-ics/pmic-voltage-reference/2556223?k=ref194

With 1V voltage reference, 10 bit ADC from 328P and 0.1 ohm current shunt i could measure current from 10 mA, and that is more than enough for me :)

Voltmeter range would be up to 40V

For efficiency measurment i will need two current shunts and two voltage dividers, one for input, one for output.

I found some Dale current shunt resistors, 0.1R 1% tolerance and about 5 or 10W each

I savlaged two dale WSR-3 current resistors :)

each is 0.1 ohm, 3W, and with 3A trough them they will disipate 0.9W of heat.

Is it possible with toneAC library or SoftPWM library to generate PWM of higher frequency and adjustible DC ?

as i can see toneAC uses PWM of the MCU to generate tone of variable frequency, but at 50% dc

The timers inside the ATmega328P can do almost everything. Have a look at the datasheet to see what kind of PWM modes are possible. Even if you don't understand it, it can be useful to know what kind of things can be done. Perhaps someone wrote a library to do what you want.

The toneAC is not a PWM library, it is purely to make sound. (It does some PWM trick to be able to have some kind of volume control).

A PWM mode does lower the output frequency. Suppose an 8-bit timer is used, with 8-bit PWM, then the resulting frequency will be 256 times (or 128 ?) lower.

The standard PWM Arduino function analogWrite() is about 500Hz, but it can be set to a higher frequency. But not very high.