Vary the duty of PWM signal using pause

1 visualización (últimos 30 días)
Chirag Goyal
Chirag Goyal el 28 de Sept. de 2021
Comentada: Chirag Goyal el 28 de Sept. de 2021
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

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by