Plecs { Name "buck_boost_average_current_mode_C_code" Version "3.7" CircuitModel "ContStateSpace" StartTime "0.0" StopTime "simuation_total_time" Solver "radau" MaxStep "1e-3" InitStep "-1" FixedStep "1e-3" Refine "1" ZCStepSize "1e-9" RelTol "1e-3" AbsTol "-1" TurnOnThreshold "0" SyncFixedStepTasks "2" UseSingleCommonBaseRate "1" LossVariableLimitExceededMsg "3" NegativeSwitchLossMsg "3" DivisionByZeroMsg "2" StiffnessDetectionMsg "2" MaxConsecutiveZCs "1000" AssertionAction "1" InitializationCommands "fid = fopen(\"myfile.txt\");\n\nfor i = 1:100\n\tfli" "ne = fgetl(fid);\n\t\n\tif(fline == -1)\n\t\tbreak;\n\tend\n\n\tdisp(fline);" "\n\teval(fline);\n\t\t\n\t\nend\n\nfclose(fid)" InitialState "1" SystemState "" CodeGenTopologies "[]" CodeGenSwitchingAlgorithm "1" CodeGenMatrixCodingStyle "1" CodeGenParameterInlining "2" CodeGenInliningExceptions "AAAACwAAAAAA" CodeGenIntegerWordSize "32" CodeGenAbsTimeUsageMsg "3" CodeGenBaseName "" CodeGenOutputDir "" CodeGenExtraOpts "" ExtendedMatrixPrecision "1" MatrixSignificanceCheck "2" Schematic { Location [0, 45; 3840, 2060] ZoomFactor 2.49666 SliderPosition [65, 0] ShowBrowser off BrowserWidth 100 Component { Type CScript Name "Average Current Mode" Show on Position [375, 600] Direction up Flipped off Parameter { Variable "NumInputs" Value "2" Show off } Parameter { Variable "NumOutputs" Value "2" Show off } Parameter { Variable "NumContStates" Value "0" Show off } Parameter { Variable "NumDiscStates" Value "0" Show off } Parameter { Variable "NumZCSignals" Value "0" Show off } Parameter { Variable "DirectFeedthrough" Value "1" Show off } Parameter { Variable "Ts" Value "Tsamp" Show off } Parameter { Variable "Parameters" Value "" Show off } Parameter { Variable "LangStandard" Value "2" Show off } Parameter { Variable "RuntimeCheck" Value "2" Show off } Parameter { Variable "Declarations" Value "#define x1 InputSignal(0,0) // current feedback\n#defin" "e x2 InputSignal(0,1) // voltage feedback\n\nfloat y1 = 0;\nfloat y2 = 0;\n" Show off } Parameter { Variable "StartFcn" Value "" Show off } Parameter { Variable "OutputFcn" Value "OutputSignal(0,0) = y1;\nOutputSignal(0,1) = y2;" Show off } Parameter { Variable "UpdateFcn" Value "#define VREF\t\t0.800000\n#define voltage_b2\t\t-1.2006" "28\n#define voltage_b1\t\t0.004665\n#define voltage_b0\t\t1.205293\n\n#define" " voltage_a2\t\t0.882603\n#define voltage_a1\t\t-1.882603\n#define voltage_a0" "\t\t1.000000\n\n#define current_b2\t\t-0.193683\n#define current_b1\t\t0.0087" "78\n#define current_b0\t\t0.202460\n\n#define current_a2\t\t0.167764\n#define" " current_a1\t\t-1.167764\n#define current_a0\t\t1.000000\n\n#define VM_i\t\t2" ".500000\n#define Hs_v\t\t0.011111\n#define Hs_i\t\t0.100000\nstatic float cur" "rent_err0,current_err1,current_err2,current_out0,current_out1,current_out2;\n" "static float voltage_err0,voltage_err1,voltage_err2,voltage_out0,voltage_out1" ",voltage_out2;\n\nvoltage_err0= VREF-x2; //Change x2 with your feedback volta" "ge variable\n\nvoltage_out0 = voltage_err0*voltage_b0 + voltage_err1*voltage_" "b1 +voltage_err2*voltage_b2 -voltage_out1*voltage_a1 - voltage_out2*voltage_a" "2;\n\n//Limiter\nif(voltage_out0 >= VM_i)\n{\n\t voltage_out0 = VM_i;\n}\nels" "e if(voltage_out0 <= 0)\n{\n\t voltage_out0 = 0.001;\n}\n\nvoltage_out2=volta" "ge_out1;\nvoltage_out1=voltage_out0;\n\nvoltage_err2=voltage_err1;\nvoltage_e" "rr1=voltage_err0;\n\ncurrent_err0= voltage_out0-x1; //Change x1 with your fee" "dback currrent variable\n\ncurrent_out0 = current_err0*current_b0 + current_e" "rr1*current_b1 +current_err2*current_b2 -current_out1*current_a1 - current_ou" "t2*current_a2;\n\n//Limiter\nif(current_out0 >= VM_i)\n{\n\t current_out0 = V" "M_i;\n}\nelse if(current_out0 <= 0)\n{\n\t current_out0 = 0.001;\n}\n\ncurren" "t_out2=current_out1;\ncurrent_out1=current_out0;\n\ncurrent_err2=current_err1" ";\ncurrent_err1=current_err0;\n\ny1=current_out0; //Change y1 with your outpu" "t duty variable\ny2=voltage_out0; //y2 is voltage controller output (iref) - " "for debugging only\n" Show off } Parameter { Variable "DerivativeFcn" Value "" Show off } Parameter { Variable "TerminateFcn" Value "" Show off } } Component { Type SignalMux Name "Mux" Show off Position [315, 600] Direction right Flipped off Parameter { Variable "Width" Value "2" Show off } } Component { Type Subsystem Name "Modulator" Show on Position [615, 595] Direction down Flipped off Frame [-50, -20; 50, 20] LabelPosition [0, 0] SampleTime "-1" MaskIconFrame on MaskIconOpaque off MaskIconRotates on Terminal { Type Output Position [-54, 0] Direction left } Terminal { Type Input Position [50, 0] Direction right } Schematic { Location [0, 20; 960, 467] ZoomFactor 1 SliderPosition [121, 0] ShowBrowser off BrowserWidth 100 Component { Type TriangleGenerator Name "Sawtooth\nGenerator" Show off Position [265, 95] Direction right Flipped on Parameter { Variable "Min" Value "0" Show off } Parameter { Variable "Max" Value "1" Show off } Parameter { Variable "f" Value "fsw" Show on } Parameter { Variable "DutyCycle" Value "1" Show off } Parameter { Variable "Delay" Value "0" Show off } } Component { Type RelationalOperator Name "Relational\nOperator" Show off Position [205, 150] Direction right Flipped on Parameter { Variable "Operator" Value "3" Show off } } Component { Type Output Name "PWM" Show on Position [150, 150] Direction left Flipped off Parameter { Variable "Index" Value "1" Show on } Parameter { Variable "Width" Value "-1" Show off } } Component { Type Gain Name "Gain" Show off Position [375, 155] Direction right Flipped on Parameter { Variable "K" Value "1/VM_i" Show off } Parameter { Variable "Multiplication" Value "1" Show off } } Component { Type Saturation Name "Saturation" Show off Position [295, 155] Direction right Flipped on Parameter { Variable "UpperLimit" Value "0.99" Show on } Parameter { Variable "LowerLimit" Value "0.01" Show on } } Component { Type Input Name "Vc" Show on Position [445, 155] Direction right Flipped on Parameter { Variable "Index" Value "2" Show on } Parameter { Variable "Width" Value "-1" Show off } } Connection { Type Signal SrcComponent "Sawtooth\nGenerator" SrcTerminal 1 Points [235, 95] DstComponent "Relational\nOperator" DstTerminal 1 } Connection { Type Signal SrcComponent "Relational\nOperator" SrcTerminal 3 DstComponent "PWM" DstTerminal 1 } Connection { Type Signal SrcComponent "Gain" SrcTerminal 2 DstComponent "Saturation" DstTerminal 1 } Connection { Type Signal SrcComponent "Vc" SrcTerminal 1 DstComponent "Gain" DstTerminal 1 } Connection { Type Signal SrcComponent "Saturation" SrcTerminal 2 DstComponent "Relational\nOperator" DstTerminal 2 } } } Component { Type SignalDemux Name "Demux" Show off Position [505, 600] Direction right Flipped on Parameter { Variable "Width" Value "2" Show off } } Component { Type Scope Name "iref" Show on Position [545, 635] Direction up Flipped off Location [971, 693; 1382, 928] State "AAAA/wAAAAD9AAAAAgAAAAEAAAAAAAAAAPwCAAAAA/sAAAAQAFoAbwBvA" "G0AQQByAGUAYQAAAAAA/////wAAAD8A////+wAAABQAUwBhAHYAZQBkAFYAaQBlAHcAcwAAAAAA//" "///wAAAHEA////+wAAAAwAVAByAGEAYwBlAHMAAAAAAP////8AAABxAP///wAAAAMAAAAAAAAAAPw" "BAAAAAfsAAAAUAEQAYQB0AGEAVwBpAGQAZwBlAHQAAAAAAP////8AAABpAP///wAAAZsAAADIAAAA" "BAAAAAQAAAAIAAAACPwAAAABAAAAAgAAAAEAAAAOAFQAbwBvAGwAQgBhAHIBAAAAAP////8AAAAAA" "AAAAA==" SavedViews "AAAAAgAAAAA=" HeaderState "AAAA/wAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAL/gMAAAAJAAAAC" "QAAAGQAAAAIAAAAZAAAAAcAAABkAAAABgAAAGQAAAAFAAAAZAAAAAQAAABkAAAAAwAAAGQAAAACAA" "AAZAAAAAEAAABkAAAAewAAAAsBAAABAAAAAAAAAAAAAAAAZP////8AAACBAAAAAAAAAAMAAABHAAA" "AAQAAAAAAAAAAAAAACQAAAAAAAAA0AAAAAQAAAAA=" PlotPalettes "AAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" Axes "1" TimeRange "0.0" ScrollingMode "1" SingleTimeAxis "1" Open "0" Ts "-1" SampleLimit "0" XAxisLabel "" Axis { Name "" AutoScale 1 MinValue 0 MaxValue 1 Signals {} SignalTypes [ ] Untangle 0 KeepBaseline off BaselineValue 0 } Fourier { SingleXAxis on AxisLabel "Frequency" Scaling 0 PhaseDisplay 0 Axis { Name "" AutoScale 1 MinValue 0 MaxValue 1 Signals {} Untangle 0 KeepBaseline off BaselineValue 0 } } } Component { Type Delay Name "Delay" Show on Position [455, 600] Direction right Flipped off Parameter { Variable "N" Value "1" Show off } Parameter { Variable "X0" Value "0" Show off } Parameter { Variable "Ts" Value "1/digital_controller_write_delay" Show off } } Component { Type From Name "From13" Show off Position [150, 630] Direction right Flipped off Parameter { Variable "Tag" Value "Vo" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type From Name "From14" Show off Position [150, 570] Direction right Flipped off Parameter { Variable "Tag" Value "IL" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type Gain Name "Voltage \nSensor Gain" Show on Position [260, 630] Direction right Flipped off Parameter { Variable "K" Value "Hs_v" Show off } Parameter { Variable "Multiplication" Value "1" Show off } } Component { Type Gain Name "Current\nSensor Gain" Show on Position [260, 570] Direction right Flipped off Parameter { Variable "K" Value "Hs_i" Show off } Parameter { Variable "Multiplication" Value "1" Show off } } Component { Type Goto Name "Goto7" Show off Position [700, 595] Direction right Flipped off Parameter { Variable "Tag" Value "PWM" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type DCVoltageSource Name "V_dc" Show off Position [275, 260] Direction down Flipped on Parameter { Variable "V" Value "Vinput" Show on } } Component { Type Mosfet Name "T1" Show off Position [330, 150] Direction right Flipped on Parameter { Variable "Ron" Value "0" Show off } Parameter { Variable "s_init" Value "0" Show off } Parameter { Variable "thermal" Value "" Show off } Parameter { Variable "T_init" Value "0" Show off } } Component { Type Resistor Name "R" Show off Position [620, 250] Direction down Flipped off Parameter { Variable "R" Value "Rload50" Show on } } Component { Type Capacitor Name "C1" Show off Position [530, 255] Direction down Flipped on Parameter { Variable "C" Value "Cout" Show on } Parameter { Variable "v_init" Value "0" Show on } } Component { Type Goto Name "Goto" Show off Position [805, 260] Direction left Flipped off Parameter { Variable "Tag" Value "Vo" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type From Name "From2" Show off Position [330, 105] Direction down Flipped off Parameter { Variable "Tag" Value "PWM" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type Resistor Name "R1" Show off Position [740, 220] Direction down Flipped off Parameter { Variable "R" Value "Rload50" Show on } } Component { Type Switch Name "S1" Show on Position [740, 265] Direction down Flipped off Parameter { Variable "s_init" Value "0" Show off } } Component { Type PulseGenerator Name "50% to 100%" Show on Position [685, 265] Direction right Flipped off Parameter { Variable "Hi" Value "1" Show off } Parameter { Variable "Lo" Value "0" Show off } Parameter { Variable "f" Value "fdisturbance" Show off } Parameter { Variable "DutyCycle" Value "0.5" Show off } Parameter { Variable "Delay" Value "0" Show off } } Component { Type Ground Name "Ground" Show off Position [740, 325] Direction up Flipped off } Component { Type Ground Name "Ground1" Show off Position [275, 360] Direction up Flipped off } Component { Type Inductor Name "L1" Show off Position [380, 195] Direction up Flipped off Parameter { Variable "L" Value "Lout" Show on } Parameter { Variable "i_init" Value "0" Show off } } Component { Type Diode Name "D1" Show off Position [445, 150] Direction left Flipped on Parameter { Variable "Vf" Value "0" Show off } Parameter { Variable "Ron" Value "0" Show off } Parameter { Variable "thermal" Value "" Show off } Parameter { Variable "T_init" Value "0" Show off } } Component { Type Ammeter Name "Am1" Show on Position [380, 310] Direction up Flipped off } Component { Type Goto Name "Goto1" Show off Position [420, 310] Direction right Flipped off Parameter { Variable "Tag" Value "IL" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type Resistor Name "R2" Show off Position [530, 195] Direction down Flipped off Parameter { Variable "R" Value "Cout_ESR" Show on } } Component { Type Resistor Name "R3" Show off Position [380, 255] Direction up Flipped off Parameter { Variable "R" Value "Lout_ESR" Show on } } Component { Type Voltmeter Name "Vout" Show on Position [840, 260] Direction down Flipped off } Component { Type From Name "From15" Show off Position [145, 265] Direction right Flipped off Parameter { Variable "Tag" Value "Vo" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type From Name "From16" Show off Position [145, 245] Direction right Flipped off Parameter { Variable "Tag" Value "IL" Show off } Parameter { Variable "Visibility" Value "1" Show off } } Component { Type Scope Name "Scope" Show on Position [195, 255] Direction up Flipped off Location [971, 693; 1382, 1128] State "AAAA/wAAAAD9AAAAAgAAAAEAAAAAAAAAAPwCAAAAA/sAAAAQAFoAbwBvA" "G0AQQByAGUAYQAAAAAA/////wAAAGcA////+wAAABQAUwBhAHYAZQBkAFYAaQBlAHcAcwAAAAAA//" "///wAAAHEA////+wAAAAwAVAByAGEAYwBlAHMAAAAAAP////8AAABxAP///wAAAAMAAAAAAAAAAPw" "BAAAAAfsAAAAUAEQAYQB0AGEAVwBpAGQAZwBlAHQAAAAAAP////8AAABpAP///wAAAZsAAAGQAAAA" "BAAAAAQAAAAIAAAACPwAAAABAAAAAgAAAAEAAAAOAFQAbwBvAGwAQgBhAHIBAAAAAP////8AAAAAA" "AAAAA==" SavedViews "AAAAAgAAAAA=" HeaderState "AAAA/wAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAL/gMAAAAJAAAAC" "QAAAGQAAAAIAAAAZAAAAAcAAABkAAAABgAAAGQAAAAFAAAAZAAAAAQAAABkAAAAAwAAAGQAAAACAA" "AAZAAAAAEAAABkAAAAxAAAAAsBAAABAAAAAAAAAAAAAAAAZP////8AAACBAAAAAAAAAAMAAABgAAA" "AAQAAAAAAAAAAAAAACQAAAAAAAABkAAAAAQAAAAA=" PlotPalettes "AAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAA" "AEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" Axes "2" TimeRange "0" ScrollingMode "1" SingleTimeAxis "1" Open "0" Ts "-1" SampleLimit "0" XAxisLabel "" Axis { Name "IL" AutoScale 1 MinValue 0 MaxValue 1 Signals {} SignalTypes [ ] Untangle 0 KeepBaseline off BaselineValue 0 } Axis { Name "Vout" AutoScale 1 MinValue 0 MaxValue 1 Signals {} SignalTypes [ ] Untangle 0 KeepBaseline off BaselineValue 0 } Fourier { SingleXAxis on AxisLabel "Frequency" Scaling 0 PhaseDisplay 0 Axis { Name "" AutoScale 1 MinValue 0 MaxValue 1 Signals {} Untangle 0 KeepBaseline off BaselineValue 0 } Axis { Name "" AutoScale 1 MinValue 0 MaxValue 1 Signals {} Untangle 0 KeepBaseline off BaselineValue 0 } } } Component { Type ZeroOrderHold Name "Zero-Order\nHold" Show on Position [195, 570] Direction right Flipped off Parameter { Variable "Ts" Value "Tsamp" Show off } } Component { Type ZeroOrderHold Name "Zero-Order\nHold1" Show on Position [195, 630] Direction right Flipped off Parameter { Variable "Ts" Value "Tsamp" Show off } } Connection { Type Signal SrcComponent "Mux" SrcTerminal 1 DstComponent "Average Current Mode" DstTerminal 1 } Connection { Type Signal SrcComponent "Current\nSensor Gain" SrcTerminal 2 Points [300, 570] DstComponent "Mux" DstTerminal 2 } Connection { Type Signal SrcComponent "Voltage \nSensor Gain" SrcTerminal 2 Points [300, 630] DstComponent "Mux" DstTerminal 3 } Connection { Type Signal SrcComponent "Demux" SrcTerminal 2 DstComponent "Modulator" DstTerminal 2 } Connection { Type Signal SrcComponent "Demux" SrcTerminal 3 Points [515, 605] DstComponent "iref" DstTerminal 1 } Connection { Type Signal SrcComponent "Average Current Mode" SrcTerminal 2 DstComponent "Delay" DstTerminal 1 } Connection { Type Signal SrcComponent "Delay" SrcTerminal 2 DstComponent "Demux" DstTerminal 1 } Connection { Type Signal SrcComponent "Modulator" SrcTerminal 1 DstComponent "Goto7" DstTerminal 1 } Connection { Type Wire SrcComponent "T1" SrcTerminal 1 Points [275, 150] DstComponent "V_dc" DstTerminal 1 } Connection { Type Wire SrcComponent "R" SrcTerminal 2 Points [620, 150] Branch { Points [530, 150] Branch { DstComponent "R2" DstTerminal 2 } Branch { DstComponent "D1" DstTerminal 1 } } Branch { Points [740, 150] Branch { Points [840, 150] DstComponent "Vout" DstTerminal 2 } Branch { DstComponent "R1" DstTerminal 2 } } } Connection { Type Wire SrcComponent "C1" SrcTerminal 2 Points [530, 340] Branch { Points [380, 340] Branch { Points [275, 340] Branch { DstComponent "V_dc" DstTerminal 2 } Branch { DstComponent "Ground1" DstTerminal 1 } } Branch { DstComponent "Am1" DstTerminal 2 } } Branch { Points [620, 340] Branch { DstComponent "R" DstTerminal 1 } Branch { Points [840, 340] DstComponent "Vout" DstTerminal 1 } } } Connection { Type Signal SrcComponent "From2" SrcTerminal 1 DstComponent "T1" DstTerminal 3 } Connection { Type Wire SrcComponent "S1" SrcTerminal 2 DstComponent "R1" DstTerminal 1 } Connection { Type Signal SrcComponent "50% to 100%" SrcTerminal 1 DstComponent "S1" DstTerminal 3 } Connection { Type Wire SrcComponent "S1" SrcTerminal 1 DstComponent "Ground" DstTerminal 1 } Connection { Type Wire SrcComponent "T1" SrcTerminal 2 Points [380, 150] Branch { DstComponent "D1" DstTerminal 2 } Branch { DstComponent "L1" DstTerminal 1 } } Connection { Type Signal SrcComponent "Am1" SrcTerminal 3 DstComponent "Goto1" DstTerminal 1 } Connection { Type Wire SrcComponent "C1" SrcTerminal 1 DstComponent "R2" DstTerminal 1 } Connection { Type Wire SrcComponent "Am1" SrcTerminal 1 DstComponent "R3" DstTerminal 2 } Connection { Type Wire SrcComponent "R3" SrcTerminal 1 DstComponent "L1" DstTerminal 2 } Connection { Type Signal SrcComponent "Vout" SrcTerminal 3 DstComponent "Goto" DstTerminal 1 } Connection { Type Signal SrcComponent "From16" SrcTerminal 1 Points [160, 245; 160, 250] DstComponent "Scope" DstTerminal 1 } Connection { Type Signal SrcComponent "From15" SrcTerminal 1 Points [160, 265; 160, 260] DstComponent "Scope" DstTerminal 2 } Connection { Type Signal SrcComponent "From14" SrcTerminal 1 DstComponent "Zero-Order\nHold" DstTerminal 1 } Connection { Type Signal SrcComponent "Zero-Order\nHold" SrcTerminal 2 DstComponent "Current\nSensor Gain" DstTerminal 1 } Connection { Type Signal SrcComponent "From13" SrcTerminal 1 DstComponent "Zero-Order\nHold1" DstTerminal 1 } Connection { Type Signal SrcComponent "Zero-Order\nHold1" SrcTerminal 2 DstComponent "Voltage \nSensor Gain" DstTerminal 1 } } } DemoSignature "LzH5bLyLf3LRVbgiYEHAJBQiwumRyPLEa6fn55hY0C0="