Simulink: Two simulation steps within one

16 views (last 30 days)
Peter
Peter on 29 Apr 2011
Hello everyone,
Here is the problem: I have a simulink block-diagram scheme which represents a simple stepper motor control system. It consist of two parts - first is stepper itself with power source and controlled H-bridge, second part prepares control signals for that bridge. Input for the whole scheme is a sequence (1xN vector) of rotation values in degrees. Now how it should work: having the stepper motor step size (0.045 deg for example) system should compute how many steps should be done by stepper to achieve next position (next rotation value in sequence) and (let's say 2 steps should be done) output 2 corresponding control signals to H-bridge. The problem is, that if on let's say first simulation step motor should do two steps, that means that within one simulation step motor should do two simulation steps...
I tried to do that with For Loop, but it seems that For Loop performs all its iterations within one simulation step, which is not suitable in my case. Is it possible to solve such problem?
Many thanks in advace for an answer!
Best regards, Peter.
  1 Comment
Peter
Peter on 29 Apr 2011
I can restate my question. Is it possible to run one part of simulink model two times within one simulation step? (run stepper motor two times - two make two steps)

Sign in to comment.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 29 Apr 2011
What have you set as "Iteration limit source" in the For Iterator block? It seems like all you need to do is make this "external" and connect the number_of_iterations signal to this input. Please elaborate on how your Iterator block is configured if have misunderstood your use-case.
  4 Comments
Peter
Peter on 30 Apr 2011
Yep, now it works that way. There was a problem - when number of iterations was one, iterator block didn't start, but i fixed it by adding 0.1 so number of iterations became 1.1.
I suppose this is impossible to run a subsystem which is outside Iterator block twice. The logic I want to implement:
if u1>0
for i=1:N %N - number of steps in positive direction
S1 = computed control signal;
Run stepper motor with S1 signal;
end;
elseif u1<0
for i=1:N %N - number of steps in negative direction
S2 = cimputed control signal;
Run stepper motor with S2 signal;
end;
So the problem is with running a subsysem, which is outside For Loop... If I try to output control signal S1 each iteration, the For Loop outputs only the last one and stepper motor is then controlled only with that last signal.
Kaustubha Govind
Kaustubha Govind on 2 May 2011
Ah! So what you want to do is concatenate the output of each iteration, such that S1 has a width of 'N'?
One way I can think of is using the Iterated Assignment block (see http://www.mathworks.com/help/toolbox/simulink/slref/assignment.html), and assign one element of the output at a time. However, since the output needs to be fixed dimensions, you could set the output size to be the maximum number of iterations possible.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!