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)
Test =1;% Test variable for debugging
td = 0;
persistent throttleNew; % static variable to identify change in input
uNew = 0;
uOld=uNew; %throttleOld variable to identify the previous position
PWMA=0; %Pulses tothe 1st switch
PWMB=0; %Pulses tothe 2nd switch
elseif((uOld~=uNew)&& (uOld < uNew)) %identify any change in input and if change happens
PWMA=0 ; %Switch the 2n
pause(td); % determines the duration for which 2nd switch is on
PWMA = 1;