# Trying to build a buck converter using Raspberry Pi & INA219

#### jmcca

Joined Jul 9, 2021
4
Hello guys,

First of all this may contain a lot of errors, both gramatically and scientifically. I'm going to try and explain the best I can do the difficulties I'm having. I'm open to everything you may say so I can get a better understanding on my project.

I'm trying to do a project in which I use a Raspberry Pi with a buck converter to decrease a 12V input into 3.7V to charge a Lithium battery. I'm using duty cycle (at 100 kHz) to control the voltage. In the end the main goal of the project is to build a solar MPPT tracker, but for now I'm only trying to make it work with a fixed DC supply voltage.

I'm using 2 INA219, one at Vin (which is measuring the voltage accurately, same value as multimeter) and another one at Vout. Now, before placing the battery on the circuit I made calculations to obtain the duty cycle D = Vout/Vin, which gave me around 31%, to decrease from 12V to 3.7V. However when I was testing it, I used a 470 ohm resistor at the end instead of the battery, and the circuit achieved 3.7V at 54% duty cycle. Then I teste with the battery (I waited until the duty cycle decreased the voltage to 4V for it to be safe connecting the battery, and once I connected the battery voltage reading on INA219 dropped to 2.2V, which then makes the raspberry pi raise the duty cycle to around 75% to reach the 3.7V. Now my questions with that are:

- As it raises the duty cycle, voltage raises too, and if I take the battery out of the circuit, the multimeter reading raises to almost 9V, which means the battery is receiving 9V? Or I am confusing everything?

- The current raises to values above 1A, which doesnt damage the battery (it can charge to 1.8A - https://www.fellotech.com/1800mah-3-7v-li-polymer-battery-103450-with-ul-certificate_p202.html), but the MOSFET I'm using (IRFZ44Z) gets dangerously hot, is it normal and can I do anything to help it?

- I tried not only limiting the voltage (under 4.15V), but also the current under 350mA, which solved the heating problem on the MOSFET, and in fact the battery actually charged, it reached 4V after around 2h (was at 3.6V initially). However I don't know if the procedure I did was safe? If the data I'm taking was right? (probably not as by limiting the current to 350mA, multimeter was reading 4V and INA219 was still at 3.8V).

- With that I understand that the load at the end affects the current, duty cycle and voltage, but I can't understand how exactly it affects, and how can I make the calculations to preview how they'll be affected?

Ok, I'm sorry, I know so this is problably sounding confusing. I don't have much experience on eletronics, but it's an area that I like and would like to improve. I've searched all over google for answers, but everytime I read a new paper about this I get bit more confused. I'd appreciate it a lot if you guys could give me some tips or give some papers that I can read to better understand whats happening.

Thank you!