Vary the duty of PWM signal using pause
조회 수: 2 (최근 30일)
표시 이전 댓글
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
댓글 수: 0
답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!