Vary the duty of PWM signal using pause

조회 수: 2 (최근 30일)
Chirag Goyal
Chirag Goyal 2021년 9월 28일
댓글: Chirag Goyal 2021년 9월 28일
There are two switches in the system. Normally switch 1 is ON. But when there is a sudden change in the input, the duty of the second switch should be varied proportional to the change. I am using pause() function to vary the ON time of second switch. Below is the code which I have done.
But the problem I am facing is the ON time is the same irrespective of change in input. Is there something wrong in the written logic?
function [PWMA ,PWMB,Test]= fcn(u)
PWMA=0;
PWMB=0;
%td=0;
Test =1;% Test variable for debugging
persistent td;
if isempty(td)
td = 0;
end
persistent throttleNew; % static variable to identify change in input
if isempty(uNew)
uNew = 0;
end
t_info();
function t_info()
uOld=uNew; %throttleOld variable to identify the previous position
uNew=u;
if ((uOld==0)&&(uNew==0))
PWMA=0; %Pulses tothe 1st switch
PWMB=0; %Pulses tothe 2nd switch
Test =2;
elseif((uOld~=uNew)&& (uOld < uNew)) %identify any change in input and if change happens
td=(uNew-uOld)*10;
disp(td)
% tic
% while(td>0)
%if(toc>=td)
%for i=0:0.0001:td
PWMA=0 ; %Switch the 2n
PWMB=1;
pause(td); % determines the duration for which 2nd switch is on
Test =3;
% end
%end
% td=(uNew-uOld)*10
else
% pause((uNew-uOld)*10)
PWMA = 1;
PWMB=0;
Test =4;
end
end
end

답변 (1개)

VBBV
VBBV 2021년 9월 28일
t_info(u);
function t_info(u)
Pass the input variable to the function call t_info
  댓글 수: 5
Chirag Goyal
Chirag Goyal 2021년 9월 28일
Second switch should be ON for (uNew-uOld)*10 seconds. How to do this ?
Chirag Goyal
Chirag Goyal 2021년 9월 28일
According to my code, I am using pause (uNew-uOld)*10 ) after making PWM=1

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by