How can I make decisions in my model based on how much real-time has expired since the last time the decision was made in Simulink 7.0 (R2007b)?

1 view (last 30 days)
I have a controller for my motor that decides when to turn it on and off based on certain inputs. I would also like to be able to implement logic so that the controller will not turn on the motor if it has been turned on for more than eight times in the past one hour (real-time). I would also like to ultimately generate ERT code from this model.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
There are a couple of different ways this logic can be implemented in Simulink :
1. One can implement a counter logic which increments its value every simulation step ( so every 2 seconds if say your Simulation Step size is 2 seconds) and write the value to a data store. The motor controller can read from this memory location every time and figure out the time since the last time the motor was turned on (or some such equivalent value). Of course you would reset this memory value according to your needs (e.g maybe every one hour). Now as far as this working on a real-time system, as with any generated code from a model you need a scheduler that calls the simulation every fixed-step size seconds. So hook the generated code to up to a scheduler that calls it every 2 seconds and you are all set.
Note: This will implement the logic you desired, but one situation to consider might be the following:
If your motor has been idle for 58 mins and then turns on (and off) 6 times in 1 min (chattering), the above logic alone will not help in preventing this. Additional logic might need to put in to safeguard against this situation.
2. Another idea that can be considered is that you can have first order dynamic system that basically ramps up as time goes along (according to its time constant) and gets reset every one hour (say). You could use the output of this first order system to make your ON/OFF decision for your motor in a sort of similar way as above.

More Answers (0)

Categories

Find more on Multicore Processor Targets in Help Center and File Exchange

Products


Release

R2007b

Community Treasure Hunt

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

Start Hunting!