Driving LEDs

Table of Contents
Copyright (C) 2021 Miodrag Bolic
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details <https://www.gnu.org/licenses/>.
This code was developed by Miodrag Bolic for the book PERVASIVE CARDIAC AND RESPIRATORY MONITORING DEVICES: https://github.com/Health-Devices/CARDIAC-RESPIRATORY-MONITORING
% Changing the path from main_folder to a particular chapter
main_path=fileparts(which('Main_Content.mlx'));
if ~isempty(main_path)
%addpath(append(main_path,'/Chapter2'))
cd (append(main_path,'/Chapter6/LED'))
addpath(append(main_path,'/Service'))
end
SAVE_FLAG=0; % saving the figures in a file

LED control

clear_all_but('SAVE_FLAG')
Vin(:,1)=0:0.0001:1; %time;
Vin(:,2)=0:0.0001*5:5;
model_name = 'LEDControl';
open_system(model_name)
% Set Simulation Mode the parameter in PWM to "Average"
set_param('LEDControl/PWM','pwm_or_av','2');
%m = sdo.getParameterFromModel(model_name, 'PWM');
simOut = sim(model_name, 'CaptureErrors', 'on');
Warning: Matching "Goto" for "From" 'LEDControl/LED W/From1' not found
Warning: Matching "Goto" for "From" 'LEDControl/LED W/From3' not found
Warning: Matching "Goto" for "From" 'LEDControl/LED W1/From1' not found
Warning: Matching "Goto" for "From" 'LEDControl/LED W1/From3' not found
figure
plot(simOut.voltage_in.Data*100/5,simOut.Power_out.Data*1000)
xlabel('Duty cycle (%)', 'FontSize', 10)
ylabel('Radiant power (mW)', 'FontSize', 10)
title('LED average radiant power vs. PWM duty cycle')
annonation_save('b)',"Fig6.12b.jpg", SAVE_FLAG);
figure
clear_all_but('SAVE_FLAG')
Vin(:,1)=0:0.0001:1; %time;
Vin(:,2)=2;
model_name = 'LEDControl';
% Set Simulation Mode the parameter in PWM to "PWM"
set_param('LEDControl/PWM','pwm_or_av','1');
simOut = sim(model_name, 'CaptureErrors', 'on');
Warning: Matching "Goto" for "From" 'LEDControl/LED W/From1' not found
Warning: Matching "Goto" for "From" 'LEDControl/LED W/From3' not found
Warning: Matching "Goto" for "From" 'LEDControl/LED W1/From1' not found
Warning: Matching "Goto" for "From" 'LEDControl/LED W1/From3' not found
figure
subplot(211),
plot(simOut.current_out.Time(1:2000), simOut.current_out.Data(1:2000)*1000)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Forward current (mA)', 'FontSize', 10)
title('PWM current through the LED vs. time')
subplot(212),
plot(simOut.current_out.Time(1:2000), simOut.Power_out.Data(1:2000)*1000)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Radiant power (mW)', 'FontSize', 10)
title('LED radiant power')
annonation_save('a)',"Fig6.12a.jpg", SAVE_FLAG);
exportgraphics(gcf,"Fig6.12a.jpg", 'Resolution',600)
% plot(-simOut.diode_out.Data,-simOut.current_out.Data*1e6)
% xlabel(' Reverse Voltage (V)', 'FontSize', 10)
% ylabel('Reverse Light Current (µA)', 'FontSize', 10)
%
%
% clear all
% Irr1(:,1)=0:0.01:10; %time
% Irr1(:,2)=10; % irradiance
% Vin(:,1)=0:0.01:10; %time;
% Vin(:,2)=-5:0.01:5;
% simOut = sim('photodiode', 'CaptureErrors', 'on');
% hold on
% plot(-simOut.diode_out.Data,-simOut.current_out.Data*1e6)