0

While trying to drive steper motor from s function I have to reach the parameters of pulse generator. What I have to do is adjust the period parameter of pulse generator in order to be able to adjust the stepper motor.However, I don't know how to reach them on simulink via either s-function or matlab function. Any help will be appreciated. Thanks.

1 Answers1

0

I'm not sure if I got your question, but you can simply set the parameters from matlab, like this;

set_param('test_project/Pulse Generator','Period','0.1');

or

set_param('test_project/Pulse Generator','Period','a_variable');

the same for other parameters;

set_param('test_project/Pulse Generator','Amplitude','an_other_var*2*pi');
set_param('test_project/Pulse Generator','Amplitude','100');
set_param('test_project/Pulse Generator','Pulse Width','eps');

this could be done in a for loop for example;

for j=1:1:10
    set_param('test_project/Pulse Generator','Period','j*2*pi');
    % do other things here...
end

You can do it from s-function too, dedicate an output in matlab workspace and then do something similar to those codes above.

hope I understood your point.

Shivid
  • 1,295
  • 1
  • 22
  • 36
  • The OP needs a variable frequency pulse generator where the next rise/fall of the pulse is controlled based on what is happening at this time step if the simulation. Using `set_param` as you've outlines won't do that correctly while the simulation is running. – Phil Goddard Aug 18 '17 at 19:00
  • Is it possible in this case to use a `Unit delay` block, since the simulation is discrete time based? Putting `unit delay` block on output of s-function or whatever matlab or simulink block that calculates based on `result(k-1)` and then using `set_param` determines the `period(k)`. I'll update my answer with blocks. – Shivid Aug 18 '17 at 20:13
  • You can't change the sample time of a typical block (such as the Unit Delay) during simulation. Only block's that have been specifically written to allow VariableSampleTime, like a variable step S-Function, allow this. – Phil Goddard Aug 18 '17 at 20:20