Could someone please assist me? My code for the buck-boost converter controller isn't working properly when I run it.

5 visualizzazioni (ultimi 30 giorni)
this is the Simulink model
  2 Commenti
Danikha Shyken
Danikha Shyken il 21 Ott 2023
Modificato: Danikha Shyken il 21 Ott 2023
Here is the code:
function [q1, q2, q3, q4] = buckBoostController(inputVoltage)
% Constants for duty cycle and delay values
dutyCycleBoost = [85.71, 81.82, 60.00];
delayBoost = [51.444, 65.448, 144.000];
dutyCycleBuck = 47.37;
delayBuck = 170.532;
% Define the battery voltage
batteryVoltage = 1.8;
% Check input voltage to determine the mode (Boost, Buck, or Battery Voltage)
ind = inputVoltage == [0.3, 0.4, 1.2]; % Avoid repeating "inputVoltage == [0.3, 0.4, 1.2]"
if any(ind)
% Boost Mode
dutyCycle = dutyCycleBoost(ind);
delay = delayBoost(ind);
q1 = 1;
q2 = dutyCycle(1) / 100; % Add (1) to clearly define size
q3 = 0;
q4 = 1 - q2;
elseif inputVoltage == 2
% Buck Mode
dutyCycle = dutyCycleBuck;
delay = delayBuck;
q1 = dutyCycle / 100;
q2 = 0;
q3 = 1 - q1;
q4 = 1;
elseif inputVoltage == batteryVoltage
% Battery Voltage Mode
q1 = 1;
q2 = 0;
q3 = 0;
q4 = 0;
% Optionally, you can set dutyCycle and delay for this mode if needed.
else
error('Input voltage is out of the specified range.');
end
end
Can someone please help me improve this code to make it work as intended?
Danikha Shyken
Danikha Shyken il 21 Ott 2023
Modificato: Danikha Shyken il 21 Ott 2023
In the code, I've already incorporated the calculated duty cycles and delays to enable the controller to operate automatically within an input voltage range of 0.3-2V. When the input voltage is either 0.3V, 0.4V, or 1.2V, the system will function in boost mode, and this is reflected in the MOSFET switching operations (represented by q1, q2, q3, q4). However, if the input voltage is 2V, the system will operate in buck mode. If there are no other sources available, the system will be powered by the battery that holds 1.8V. The desired output voltage is 1.8V.

Accedi per commentare.

Risposta accettata

dpb
dpb il 21 Ott 2023
Modificato: dpb il 21 Ott 2023
<We already told you> this was going to be a problem but you didn't pay attention...
if inputVoltage == 0.3 || inputVoltage == 0.4 || inputVoltage == 1.2
is very problematical in doing exact comparisons with floating point values;
and
ind = inputVoltage == [0.3, 0.4, 1.2]; % Avoid repeating "inputVoltage == [0.3, 0.4, 1.2]"
if any(ind)
has the same issue.
  6 Commenti
Danikha Shyken
Danikha Shyken il 25 Ott 2023
Modificato: Danikha Shyken il 25 Ott 2023
We already have a functioning automatic input selector, and its output is fed into the buck-boost converter controller as seen in the above figure. However, I think there's an issue with the controller code, particularly in the switching (q1, q2, q3, and q4) because the converter only outputs 0. If the input voltage falls below 0.3V, the battery is the only available source, providing 1.8V. On the other hand, if the input voltage exceeds 2V, the input selector outputs 2V, which is the upper bound of the available source (PZT). If the input voltage is 0.5V, it falls between the range of 0.4V to 1.2V. Since it's closer to 0.4V, the input selector will output 0.4V.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Thermal Management in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by