ad space

Automatic Power Supply Control Buck Converter with Arduino

Efficient power conversion is essential in modern electronics, and buck converters are widely used to step down DC voltages. This article demonstrates how to achieve automatic power control of a buck converter using Arduino, leveraging Fast PWM mode and a feedback control loop.


Understanding PWM Modes: Fast PWM vs Phase-Correct PWM

Pulse Width Modulation (PWM) is a key technique in controlling power delivery. Arduino offers multiple PWM modes, including Fast PWM and Phase-Correct PWM:

  • Fast PWM:

    • Known for high-frequency operation, reducing ripple voltage and ensuring faster response in power control.
    • Learn more about Fast PWM in Arduino in this comprehensive Fast PWM tutorial.
  • Phase-Correct PWM:

    • Provides symmetrical waveform generation but operates at a lower frequency.
    • Discover Phase-Correct PWM and its applications in this in-depth guide.

To configure Timer settings for your Arduino project, use this Arduino Timer Calculator.


Circuit Diagram

Arduino Buck Converter

The circuit involves a PWM Controller which is Arduino in this case. One can set the target output voltage like 5V in this tutorial via software programming or via potentiometer dynamically to set the target voltage, a feedback system for voltage regulation, and a power transistor for output control.

Parts List:

  • Arduino Uno (or similar)
  • 2N3055 Power Transistor
  • 2x10kΩ Potentiometer
  • 10kΩ Resistor (Base pull-down)
  • 1kΩ Resistor (Base current limiter)
  • 5.6V Zener Diode
  • Inductor (100µH)
  • Capacitor (47µF)
  • 12V DC Power Supply

Circuit Operation

1. Target Voltage Setting

  • The potentiometer connected to the Arduino’s A0 pin sets the desired output voltage (e.g., 5V).

2. Feedback Mechanism

  • A feedback pin (A1) samples the output voltage, scaled via a voltage divider to remain within the Arduino ADC’s 0–5V range.

3. PWM Control

  • A PID controller in the Arduino compares the target voltage with the feedback voltage and adjusts the PWM signal on pin 9.

4. Transistor Regulation

  • The 2N3055 transistor regulates current through the inductor and capacitor, maintaining steady output voltage.

Video Demonstration

See how the Automatic Power Supply Control Buck Converter with Arduino works in the following video.

Calculations

Voltage Divider for Feedback

To scale the output voltage to the Arduino ADC range, the formula is:

Vfeedback=Vout×R2R1+R2V_{feedback} = V_{out} \times \frac{R_2}{R_1 + R_2}

For Vout=5V, we can choose resistors R1R_1 and R2 to ensure that VfeedbackV_{feedback} stays within the Arduino ADC's 0–5V range. For example:

  • Choose R1=10kR_1 = 10k and R2=4.7kR_2 = 4.7k to get a feedback voltage VfeedbackV_{feedback} close to 5V.

So, the feedback voltage is:

Vfeedback=5V×4.7kΩ10kΩ+4.7kΩ3.13VV_{feedback} = 5V \times \frac{4.7k\Omega}{10k\Omega + 4.7k\Omega} \approx 3.13V

This ensures that the feedback stays within the allowable range of 0–5V for Arduino's ADC input.V_{feedback} \leq 5V

Inductor and Capacitor Selection

Inductor Value:

L=(VinVout)×VoutIload×f×VrippleL = \frac{(V_{in} - V_{out}) \times V_{out}}{I_{load} \times f \times V_{ripple}}

Where ff is the PWM frequency and VrippleV_{ripple} is the allowed ripple voltage.

Capacitor Value:

C=Iloadf×VrippleC = \frac{I_{load}}{f \times V_{ripple}}

Implementing PID Control

For precise regulation, PID tuning is crucial. Learn how to fine-tune PID parameters KpK_p, KiK_i, and KdK_d in this detailed PID tuning guide on How to Tune PID Parameters.

The following is code for the Arduino based PWM controller for the above shown Buck Converter design.


// Pin definitions
const int pwmPin = 9;          // PWM output pin to MOSFET
const int potPin = A0;         // Potentiometer pin for target voltage
const int feedbackPin = A1;    // Feedback voltage input

// Constants
const int maxPWM = 511;        // Maximum PWM value for Timer1 (TOP is 511 for ~31.25kHz)
float maxTargetVoltage = 5.0;  // Max target voltage set by potentiometer
float feedbackScale = 2.5;     // Scale factor for feedback voltage (adjust based on voltage divider)
float vRef = 5.0;              // Arduino ADC reference voltage
float kp = 50.0;               // Proportional gain
float ki = 5.0;                // Integral gain
float kd = 1.0;                // Derivative gain

// Variables
float integral = 0.0;
float previousError = 0.0;

void setup() {
  // Configure Timer1 for Fast PWM at ~31.25 kHz
  pinMode(pwmPin, OUTPUT);
  TCCR1A = _BV(COM1A1) | _BV(WGM11);  // Non-inverting mode, Fast PWM
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);  // Fast PWM, no prescaler
  ICR1 = 511; // Set TOP value for ~31.25 kHz frequency

  // Initialize Serial Monitor for debugging
  Serial.begin(9600);
}

void loop() {
  // Read target voltage from potentiometer (0-5V scaled to 0-maxTargetVoltage)
  int potValue = analogRead(potPin);
  float targetVoltage = (potValue / 1023.0) * maxTargetVoltage;

  // Read feedback voltage (scaled by voltage divider)
  int feedbackValue = analogRead(feedbackPin);
  float measuredVoltage = (feedbackValue / 1023.0) * vRef * feedbackScale;

  // Calculate error
  float error = targetVoltage - measuredVoltage;

  // PID control calculations
  integral += error * 0.01; // Accumulate integral term (loop interval ~10ms)
  float derivative = (error - previousError) / 0.01;
  int pwmValue = kp * error + ki * integral + kd * derivative;

  // Constrain PWM value to valid range
  pwmValue = constrain(pwmValue, 0, maxPWM);
  OCR1A = pwmValue; // Set PWM duty cycle

  // Update previous error
  previousError = error;

  // Debugging output
  Serial.print("Target Voltage: ");
  Serial.print(targetVoltage);
  Serial.print(" V, Measured Voltage: ");
  Serial.print(measuredVoltage);
  Serial.print(" V, PWM Value: ");
  Serial.println(pwmValue);

  delay(10); // Small delay for stability (10ms loop interval)
}

Exploring Advanced Topics

  • PWM Switching Power: Understand how to choose the right PWM switching power for your design by reading this essential article on PWM switching PWM Switching Power Techniques.

  • Enhanced Voltage Regulator Designs: Learn more about advanced voltage regulators in this step-by-step guide on Enhanced Voltage Regulator with Arduino.

  • Various Buck Converter Designs: Explore different buck converter designs and their applications in this comprehensive guide on Various Buck Converter Designs.

  • 555 Timer Buck Converter Design: Discover how to design a buck converter using a 555 timer in this in-depth tutorial on 555 Timer Buck Converter Design.

  • Design a Buck Converter with Arduino: Learn how to design an Arduino-based buck converter with detailed instructions in this Arduino Buck Converter Design tutorial Design a Buck Converter with Arduino.


Conclusion

By utilizing Arduino's Fast PWM mode and integrating a feedback control loop, you can design an efficient and precise buck converter. For further optimization and advanced features, explore the resources linked throughout this article to enhance your knowledge and improve your project.

Post a Comment

Previous Post Next Post