Write a Matlab script file that creates a graph of the 555 IC timer output as sh
ID: 2249100 • Letter: W
Question
Write a Matlab script file that creates a graph of the 555 IC timer output as shown below.
Operation of the 555 Timer:
The output of the 555 timer is controlled by the charge on the external capacitor connected to the 555 timer. The ouput is equal to 5V when the capacitor is charging and 0V when the capacitor is discharging.
The capacitor voltage begins the charging process with a value of (1/3)*Vs where Vs is the source voltage connected to the 555 timer. The charging continues until the capacitor voltage exceeds (2/3)*Vs . While the capacitor is charging, the capacitor voltage (Vc) in volts can be found using the equation below.
Vc = (1/3)*Vs + (2/3)*Vs*( 1 – e-(Tc)/(Rc*C) )
Tc = time elapsed since charging began in sec
Rc = Charging resistor in ohms
C = capacitance in farads
Once the capacitor voltage exceeds (2/3)*Vs it begins to discharge. It continues to discharge until the capacitor voltage falls below (1/3)*Vs . While the capacitor is discharging, the capacitor voltage (Vc) in volts can be found using the equation below.
Vc = (2/3)*Vs*( e-(Td)/(Rd*C) )
Td = time elapsed since discharging began in sec
Rd = discharging resistor in ohms
Have the user input the values shown below in the sample output from the command window.
Define the Time Constant as ((Rc + Rd)/2)*C in your program. Use a time increment (dt) such that your vectors for time and voltage will have at least 1000 values stored in them.
Explanation / Answer
%-------Matlab script file that creates a graph of the 555 IC timer-------%
%-----The values of Rc, Rd and C are not given in the problem, so let us assume that Rc=Rd=1MOhm and C=1 micro Farad------%
Rc=1e6; Rd=1e6; C=1e-6;
%----The time constant Tc----%
Tc=((Rc+Rd)/2)*C;
%-----Let us consider Vs=1(say), as it is a constant and for the purpose of plotting in matlab we need a constant number, so take any constant value----%
Vs=1;
%------Compute the cu-off voltage for charging and discharging----%
V_cutoff_charging=(2/3)*Vs;
V_cutoff_discharging=(1/3)*Vs;
%----Initiate the charging time and discharging time to zero initally as nothing is started------%
tc=0; td=0;
%-------Initiate the values of time Capacitor Voltage and Output Voltage of the timer atleast 1000 samples as specified in the problem-----%
num_samples=1000; step_size=0.001*Tc/num_samples;
t=0:10000000;
Vc=zeros(1,size(t,2));
Vout=zeros(1,size(t,2));
%-----Initiate the value of capacitor voltage at t=0 as Vs/3 as it is given in the problem-----%
Vc(1)=Vs/3;
%------Now Loop over all the time samples to get the voltage of the capacitor-----%
%-----The voltage of the capacitor depends on its previous value------%
%-----If it is greater than the charging cut-off voltage, it starts discharging----%
%-----And if if lesser than the discharging cut-off voltage, it is starts charging----%
charging=1;
discharging=0;
for i=2:size(t,2)
if((Vc(i-1)<=V_cutoff_charging) && charging==1)
Vc(i)=(1/3)*Vs+(2/3)*Vs*(1-exp(-tc/(Rc*C)));
Vout(i)=5;
tc=tc+step_size;
if(Vc(i)>=V_cutoff_charging)
td=0; charging=0; discharging=1;
end
elseif(Vc(i-1)>=V_cutoff_discharging && discharging==1)
Vc(i)=(2/3)*Vs*exp(-td/(Rd*C));
Vout(i)=0;
td=td+step_size;
if(Vc(i)<=V_cutoff_discharging)
tc=0; discharging=0; charging=1;
end
end
end
plot(t,Vc); title('Capacitor Voltage');
figure, plot(t,Vout); title('Timer Output Voltage');
%----PROGRAM ENDS---%
Please comment if any clarification is needed.
Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.