MATLAB Answers

Duty cycle Matlab funciton is Simulink. Error! -Undefined function or variable 'duty_cycle'. The first assignment to a local variable determines its class.

2 views (last 30 days)
Hi,
I want to make a function which would vary the duty cycler of a converter to get 400V output.
UNfortunately I am getting the error: Undefined function or variable 'duty_cycle'. The first assignment to a local variable determines its class.
This is my code. can you tell me what I should do?
function duty_cycle = dutycycle(Voltage_grid,past_duty)
duty_cycle_=0
if Voltage_grid>400
duty_cycle=duty_cycle-0.1
end
if Voltage_grid<400
duty_cycle=duty_cycle+0.1
end
if Voltage_grid==400
duty_cycle=past_duty
end
end

  0 Comments

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 1 Jun 2020
Two comments.
  1. Feed the "duty_cycle" to a "unit delay" block and then connect it to "past_duty".
  2. The first line inside your MATLAB Function should be "duty_cycle=past_duty;"
This way, you'll be able to regulate the voltage.

  3 Comments

Mario Nikolov
Mario Nikolov on 1 Jun 2020
Thank you very much. I realized the error disappeared and the simulation now works. It is my first time working with simulink and I am still quite the noob. Do you happen to know how I can make now that my output keeps 400V because for some reason althogh the function tries to keep 400 it is kinda stuck on very low voltages...
Fangjun Jiang
Fangjun Jiang on 1 Jun 2020
Your feedback control logic seems right however there are many elements in the loop. You just need to debug along the loop to see if all the signals make sense. You might also need to increase the "Gain" for this simple PI controller.

Sign in to comment.

More Answers (0)