I have the following Simulink model : DC/AC Half-Bridge Inverter, that uses an PWM block (inside the Green Frame) to generate the switching signals to the IGBTs, The From block (inside the Red frame) accepts a signal from the PWM using the Goto block, then passes it as output to the IGBTs.
I'm trying to build a custom PWM using Matlab code :
clc;
close all;
clear all;
t=0:0.001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
if (m(i)>=s(i))
pwm(i)=1;
elseif (m(i)<=s(i))
pwm(i)=0;
end
end
plot(t,pwm,'-g',t,m,'--r',t,s,'--b');
grid on;
ylabel('Amplitude');
xlabel('Time index');
title('PWM Wave');
axis([0 1 -1.5 1.5]);
Here is the result of the plot :
My Question :
I know that t contains the time values and pwm contains the pwm values, So i want to know how to "somehow" redirect those Data from the Matlab code, through the From Block into the IGBTs so i can use them as switching signal ?
The are multiple ways to do this, but the easiest is to just use a From Workspace block as a direct replacement for the PWM Generator (2 Pulses)
block.
Run your MATLAB code to define the variables in the MATLAB Workspace, and (assuming your G1_1
and G2_1
signals are the negation of each other) use [t(:) pwm(:) ~pwm(:)]
as the block's Data parameter.
Note also, that you don't need the loop in your code:
pwm = (m >= s);
or if you need them to be doubles rather than logical then
pwm = double(m >= s);