Effacer les filtres
Effacer les filtres

Simulink Ramp - On Demand

35 vues (au cours des 30 derniers jours)
Julian Pires
Julian Pires le 30 Jan 2019
Commenté : Julian Pires le 31 Jan 2019
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
  2 commentaires
Jim Riggs
Jim Riggs le 30 Jan 2019
Modifié(e) : Jim Riggs le 30 Jan 2019
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.
Julian Pires
Julian Pires le 31 Jan 2019
Thanks for the quick response.
1) By this I mean that I use a Matlab function within Simulink, and in that function I declare persistent variables
2) Yes, you're right. I forgot a zero. Essentialy when I scope the output of subtracting the memory value from the current clock, I don't seem to get a constant, flat, 0.0001. In the case that I want to model step size to a function, is there a simpler way to do this? One function in the model is dependent on the sample time, but needs to be changed if I want to run at 1000Hz vs. 10000Hz.
Thanks

Connectez-vous pour commenter.

Réponse acceptée

Jim Riggs
Jim Riggs le 31 Jan 2019
Modifié(e) : Jim Riggs le 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.
  1 commentaire
Julian Pires
Julian Pires le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Event Functions dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by