Simulink Ramp - On Demand

17 views (last 30 days)
Julian Pires
Julian Pires on 30 Jan 2019
Commented: Abdur on 29 Nov 2025 at 17:12
Hello,
I would like to have a signal ramp from a min. value to a max value. and back down again, in a set amount of time. I initially did this with persistent variables which allowed me to reset the ramp signal and run it essentially on demand. Is there a simple work around that doesn't involve the use of persistent variables?
On a related note, is it possible to output the sample time as a variable? I've tried using a clock with a memory block, and subtracting to get the sample time, but for a fixed step size of 0.0001, the sample time is not constant but varies between 0.0009999 and 0.0001.
Thanks
  4 Comments
Abdur
Abdur on 29 Nov 2025 at 17:12

There are a few things that are unclear to me in your question. 1) What do you mean by "persistent variables" in Simulink? 2) Are you sure that you have the right number of zeros in your time step numbers, or could it be 0.0000999 and 0.0001. These would be essentially the same value in digital representation (variation only in the least significan bit). If you set the model time ste to a fixed size, it should not vary, but computing the step by taking the difference between two numbers may have some "noise" in the LSB.

Abdur
Abdur on 29 Nov 2025 at 17:12

Good

Sign in to comment.

Accepted Answer

Jim Riggs
Jim Riggs on 31 Jan 2019
Edited: Jim Riggs on 31 Jan 2019
You can set the model time step in the "model configuration parameters" to be a variable that you define in the Matlab workspace. This way, you can refer to this variable anywhere in the model. The entire model will run at this fixed timestep.
Another approach is to use a rate transition block to specify the rate that the model block runs at, and you can also define this rate as a variable in the Matlab workspace. (The rate transition sets the rate of the input signal to the block)
Build your ramp function as a function of elapsed time, (elapsed time = current time - start time) and then use a trigger or enable signal to set start time = current time (elapsed time =zero) to start the signal.
Here is another thought: you can construct the elapsed time using an integrator block (integral of time) and use an "external reset" (on the integrator block) to start over at zero. This will cause the ramp function to restart from the beginning.
  2 Comments
Julian Pires
Julian Pires on 31 Jan 2019
Thanks Jim,
The rate transition block helped elsewhere in the model. I'm trying to use a lookup table to build the ramp function (as it ramps up then back down again), but your proposed solution seems like it should work.
Thanks again
Abdur
Abdur on 29 Nov 2025 at 17:12

Good

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!