Arduino Buck-boost converter 2010/12/08Posted by Michael in 2JZduino.
[Edit: Previously posted as a “charge pump”, I was corrected by a reader this circuit is actually a buck-boost converter…]
If you’ve ever needed a negative voltage source for components connected to your Arduino, you might find this post helpful.
I built a simple buck-boost converter circuit powered by the Timer2 Compare Match Output Unit available on the ATMega 1280 (Arduino Mega). The effort was part of troubleshooting related to the simulated crank sensor output. I thought the stock ECU might need a voltage below ground to prevent noise from triggering extra zero-crossings, but this turned out to not be the problem. So I discarded this as part of my circuit design but it was a breadboard exercise worth sharing.
First, note that I believe this interferes with the PWM functionality of the Arduino environment. If you use other functions that reference Timer2, this will break them.
On the Arduino Mega the Compare Match Output Unit can be configured to toggle the value of pin 10 (port B4) at a particular frequency through hardware (i.e consuming zero processor cycles). My charge pump design is configured for an input voltage that switches between 0 & 5V every 0.4ms.
DDRB = B00010000; // B4 (pin 10) is an output TCCR2A = B01000010; // Toggle OC2A on Compare Match, CTC mode TCCR2B = B00000011; // Timer2 prescaler = 1/32 OCR2A = 0xC8; // Compare Match @ TCNT2 = 200, occurs every 200*32/16MHz = 0.4ms
Below is a schematic for the converter circuit, drawn in LTspice. V1 is Arduino Mega pin 10 (OC2A output). R2 limits the current out of the Arduino. When the output is ON L1 (47mH & 82 Ohm) is energized, and when the output switches OFF, L1 pulls current from C1 (100 uF) through D1 while it discharges. C1 is what stores the negative voltage. R3 is the load consuming this negative voltage. It’s shown as 1k Ohms, but the circuit will maintain -0.5V for R3 values as low as 220 Ohms. For high impedance loads, the circuit will generate approx. -2.7V.
The voltage at C1 vs. time as simulated in LTspice is shown in the graph below (R3 = 1000 Ohms).
And that’s it. 4 lines of code and 4 components to generate a negative voltage.