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

4 ビュー (過去 30 日間)
this is the Simulink model
  2 件のコメント
Danikha Shyken
Danikha Shyken 2023 年 10 月 21 日
編集済み: Danikha Shyken 2023 年 10 月 21 日
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 2023 年 10 月 21 日
編集済み: Danikha Shyken 2023 年 10 月 21 日
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.

サインインしてコメントする。

採用された回答

dpb
dpb 2023 年 10 月 21 日
編集済み: dpb 2023 年 10 月 21 日
<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 件のコメント
Danikha Shyken
Danikha Shyken 2023 年 10 月 25 日
編集済み: Danikha Shyken 2023 年 10 月 25 日
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.
Danikha Shyken
Danikha Shyken 2023 年 10 月 25 日
I'm hoping you can help me in fixing the controller code.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSwitches and Breakers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by