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

6 Ansichten (letzte 30 Tage)
this is the Simulink model
  2 Kommentare
Danikha Shyken
Danikha Shyken am 21 Okt. 2023
Bearbeitet: Danikha Shyken am 21 Okt. 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 am 21 Okt. 2023
Bearbeitet: Danikha Shyken am 21 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 21 Okt. 2023
Bearbeitet: dpb am 21 Okt. 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 Kommentare
Danikha Shyken
Danikha Shyken am 25 Okt. 2023
Bearbeitet: Danikha Shyken am 25 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Thermal Management finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by