Sunday, August 16, 2015

How to control LM2596 buck-converter with microcontroller

Every now and then someone asks on different forums if there is an way to control cheap LM2596 modules with an Arduino or another microcontroller. I decided to demonstrate one solution that might be basic electronics for some, but still many don’t know about.

Those buck converters will change the output voltage to make the feedback pin, connected to the output via a voltage divider, become 1.25V or so. If feedback is higher, output gets lower and vice versa. If one changes the ratio of resistors in voltage divider, output voltage will change. This is usually done by turning a trimmer resistor with a screwdriver. That is good enough for many applications where voltage will be set only once, but sometimes there is a need to adjust the output voltage more frequently.

External voltage can pull the feedback pin’s voltage higher or lower when applied to it through a resistor. That would make a summer circuit where output voltage of buck converter and external voltage are inputs and output is junction which connects to the feedback pin connects. That external voltage can be generated with just about any microcontroller. Microcontroller generates PWM signal, which is smoothed with RC low pass filter and then buffered with an operational amplifier configured as a voltage follower. Thanks to Hackaday’s Al Williams for pointing this out: I didn’t remember to mention this clearly enough in the video: Circuit shown in this demonstration needs to have really stable power supply for the microcontroller, as the PWM signal’s amplitude depends on the power supply. So any changes on power supply’s voltage will affect the amplitude of the generated voltage and therefore the buck-converter’s output voltage.

In my demonstration the PWM-signal’s maximum voltage and therefore maximum signal generated is 5V. When buck converter’s maximum output is set high enough (lets say 12->V) adjustable resistor’s (which is one between output and feedback) resistance will be relative high compared to the resistance of buck converter module’s fixed resistor (which is 330ohm in this case). Therefore when trying to adjust converter’s output to zero or as low as possible with microcontroller, the output voltage’s effect to voltage on feedback pin will be marginal. Therefore we just need to figure out resistor for voltage divider that divides 5V to 1.25V, where lower resistor is 330 ohm. That is simple task: R = (5V * 330ohm - 1.25V * 330ohm)/1.25V = 990ohm

When everything is connected, maximum output of the buck converter can be set by generating 0V with microcontroller and then adjusting the trimmer on the buck converter board to achieve the desired maximum output voltage.

Before using this in any real application, ripple and noise performance as well as stability should be tested further.

Thursday, June 11, 2015

How to hack into computer’s I2C bus

Few weeks ago I added GPIOs to ESP8266 module by soldering few wires. This time I’m “adding” an I2C bus to my laptop by just soldering some wires!

Back in 2006 I saw an wiki-page on lm-sensors -website (This one!) describing that one could tap into the PC’s I2C bus via the memory module. Back then I hadn’t soldered any SMD stuff and I decided using a parallel port was better way to interface with I2C devices.

Years later parallel ports kinda disappeared and I2C devices didn’t. Interfacing I2C devices though USB-port needs a USB to I2C adapter or a microcontroller that acts like one. But that costs a dollar or maybe even few dollars and uses one USB-port! There must be cheaper way to do it. I remembered the old wiki-page and decided to try it out with more modern memory module. I had plenty of DDR2 SO-DIMM modules, so I decided to try with one of those. The specific module had 24c021 EEPROM/Supervisor chip. It’s like 24c02 with some extra features (which aren’t relevant to this hack). Pinout was available in the datasheet and I was ready to go.

I had LM75 -temperature sensor on my table, so I tested the hack with that one. I soldered few wires, installed software to test the hack (i2c-tools and lm-sensors) and it was time to test if I could access the temperature sensor. I was able to read data from the sensor and lm-sensors detected it. Just to make sure the detected lm75 was actually the one I added, I run lm-sensors every second and touched the sensor to see that the temperature reading started to go up. It works!

I’ve seen some hacks where people have added USB-enabled microcontrollers inside laptops to add something like LEDs or sensors, but those hacks will use an USB-port. This hack doesn’t disable any featuress, but just adds new ones.