Bode plot of LDO (TI / Octave) - Page 1
Forum section: electronics / beginners

author: hsn93
author_rank: Regular Contributor
timestamp: January 26, 2021, 10:03:41 am
content: hi,my knowledge in the math behind control theory is very low.. i probably dont know what im doingbut here goes the questionim taking this document and trying to get the result of bode plot using gnu octavehttps://www.ti.com/lit/an/slyt194/slyt194.pdfso im trying to generate the first bode plot in this document by my self:here is my octave code:Code:clc; clear all; close all;pkg load control;#https://www.ti.com/lit/an/slyt194/slyt194.pdfC_load = 10 ;#uFR_esr= 2; #ohmRo_pmos= 65 ; #ohmC_bp= 0.5; #uFR_oa= 300000; #ohmC_pmos= 0.0002;#uF# gainsGain_fb =0.36;Gain_pmos =8;Gain_ea= 56.2;Pole_1 = 1/(2*pi*(Ro_pmos+R_esr)*C_load*10^-6)Pole_2 = 1/(2*pi*R_esr*C_bp*10^-6)Pole_3 = 1/(2*pi*R_oa*C_pmos*10^-6)Zero_1 = 1/(2*pi*R_esr*C_load*10^-6)s = tf('s');spole1 = (1+s/(2*pi*Pole_1));spole2 = (1+s/(2*pi*Pole_2));spole3 = (1+s/(2*pi*Pole_3));gloop = (1+(s/2*pi*Zero_1))/(spole1*spole2*spole3);Gain_openLoop = Gain_fb * Gain_pmos * Gain_ea * gloop;bode(Gain_openLoop)or image for syntax highlighting:and my result bode plot:clearly i notice the following:the dc open loop grain is correct .. but then the gain rises in my code while its less in TI documentation.i thought this is related to open loop / closed loop .. so i tried bode(Gain_openLoop/(1+Gain_openLoop)) which failedso where do you see my mistake .. ?------------------------------------------------update:since i didnt touch octave/matlab for long time i just did small low pass filter bode plot:Fc = 1/(2*pi*R*C) = 1/(2*pi*10k*100nF) = 159HzT(f) = w0/(s+w0) <--- from wikipediaw0 = 999;Gain_openLoop = 999/(s+999);[mag, pha, w] = bode(Gain_openLoop, [0:10^4]);[crap, fc_index]= min(abs(mag-(1/sqrt(2))));fc = w(fc_index)/(2*pi)this return me standard low pass filter bode response, with correct values .. fc = 159

author: hsn93
author_rank: Regular Contributor
timestamp: January 26, 2021, 11:20:12 am
content: i just figured it out ..z1 = 1+(s/(2*pi*Zero_1));gloop = z1/(spole1*spole2*spole3);Gain_openLoop = Gain_fb * Gain_pmos * Gain_ea * gloop;there missing parenthesis ..should i delete the post ?

author: Terry Bites
author_rank: Super Contributor
timestamp: January 26, 2021, 11:53:54 am
content: Keep this post up.Its educational. Knowing what goes wrong helps you get it right next time.

author: rstofer
author_rank: Super Contributor
timestamp: January 26, 2021, 06:05:41 pm
content: Works in MATLAB after substituting '%' for all '#', adding 'grid minor' and 'shg' statements as last lines of code and editing the code as indicated in Reply 1. And comment out that 'pkg load control' statement.Very important example problem!Code:clc; clear all; close all;% pkg load control;% https://www.ti.com/lit/an/slyt194/slyt194.pdfC_load = 10; % uFR_esr = 2; % ohmRo_pmos = 65; % ohmC_bp = 0.5; % uFR_oa = 300000; % ohmC_pmos = 0.0002; % uF% gainsGain_fb = 0.36;Gain_pmos = 8;Gain_ea = 56.2;Pole_1 = 1/(2*pi*(Ro_pmos+R_esr)*C_load*10^-6)Pole_2 = 1/(2*pi*R_esr*C_bp*10^-6)Pole_3 = 1/(2*pi*R_oa*C_pmos*10^-6)Zero_1 = 1/(2*pi*R_esr*C_load*10^-6)s = tf('s');spole1 = (1+s/(2*pi*Pole_1));spole2 = (1+s/(2*pi*Pole_2));spole3 = (1+s/(2*pi*Pole_3));z1 = 1+(s/(2*pi*Zero_1));gloop = z1/(spole1*spole2*spole3);Gain_openLoop = Gain_fb * Gain_pmos * Gain_ea * gloop;bode(Gain_openLoop)grid minorshg

author: hsn93
author_rank: Regular Contributor
timestamp: January 27, 2021, 05:36:40 am
content: thanks manhere is my final version thenCode:clc; clear all; close all;isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0;if isOctavepkg load control;% graphics_toolkit('gnuplot') %if requiredend% https://www.ti.com/lit/an/slyt194/slyt194.pdfC_load = 10 ;#uFR_esr= 2; #ohmRo_pmos= 65 ; #ohmC_bp= 0.5; #uFR_oa= 300000; #ohmC_pmos= 0.0002;#uF%---- gainsGain_fb =0.36;Gain_pmos =8;Gain_ea= 56.2;%---- poles and zerosPole_1 = 1/(2*pi*(Ro_pmos+R_esr)*C_load*10^-6)Pole_2 = 1/(2*pi*R_esr*C_bp*10^-6)Pole_3 = 1/(2*pi*R_oa*C_pmos*10^-6)Zero_1 = 1/(2*pi*R_esr*C_load*10^-6)%---- transfer functions = tf('s');spole1 = (1+s/(2*pi*Pole_1));spole2 = (1+s/(2*pi*Pole_2));spole3 = (1+s/(2*pi*Pole_3));z1 = 1+(s/(2*pi*Zero_1));gloop = z1/(spole1*spole2*spole3);Gain_openLoop = Gain_fb * Gain_pmos * Gain_ea * gloop;%---- plotfstart = 1;fend = 10^8;w0 = 2*pi*fstart;w1 = 2*pi*fend;[mag, phase, w] = bode(Gain_openLoop, [w0:20*2*pi:w1]);mag_db = mag2db(mag);f = w/(2*pi);ax = plotyy (f,mag_db, f, phase, 'semilogx', 'semilogx');legend(["mag"; "phase"])grid on;grid minor;shgxlabel("Frequency (Hz)");ylabel (ax(1),"mag");ylabel (ax(2),"phase");line ("xdata",[Pole_1,Pole_1], "ydata",[0,-180], "linewidth", 1)line ("xdata",[Pole_2,Pole_2], "ydata",[0,-180], "linewidth", 1)line ("xdata",[Pole_3,Pole_3], "ydata",[0,-180], "linewidth", 1)line ("xdata",[Zero_1,Zero_1], "ydata",[10,-170], "linewidth", 1, "color", "r")text(Pole_1,1, strcat("fp1 :", num2str(round(Pole_1)), " Hz"))text(Pole_2,1, strcat("fp2 :", num2str(round(Pole_2)), " Hz"))text(Pole_3,1, strcat("fp3 :", num2str(round(Pole_3)), " Hz"))text(Zero_1,11, strcat("fz :", num2str(round(Zero_1)), " Hz"), "color", "r")%---- alternative% bode(Gain_openLoop)i dont have matlab to test the top (isOctave) part which i took from stackoverflow .. it should work in both matlab and octave