Simulink - how to hold signal value after change (transmission)

11 views (last 30 days)
I need a way to hold a signal value after it changes for a specific amount of times with only simulink blocks.
My Simulink model specifically is a transmission and I want to add a shift suppresor. So basically when the current gear changes it should not shift for 3 seconds. I've tried around with a detect change block that detects a new gear and then a subsystem gets triggered that goes into a switch which is activated as soon as the subsystem has an output and then the gear which is stored in the subsystem gets transmitted instead of the gear that would've been transmitted.
You can see a screenshot of my transmission. The basic principle is that the upshift and downshift logic always check if the gear should be changed and if yes puts out a 1 which is either added or subtracted from the current gear.
I'm thankful for every help!

Accepted Answer

TED MOSBY
TED MOSBY on 11 Jul 2025
You can use MATLAB's "monostable" block for your use case. It will create an output that stays "on" for a specific time after being triggered.
First, detect the moment the gear changes by comparing its current value to its previous value:
  • Unit Delay block: Feed the current gear signal into it.
  • Relational Operator block: Compare the current gear with the output of the Unit Delay. Set the operator to "not equal" (~=). The output will be a pulse (1) when the gear changes.
Now, use the Monostable block to create the 3-second hold:
  • Connect the output of your Relational Operator (the change pulse) to the input of the Monostable block.
  • Double-click the Monostable block and set the Pulse duration to 3.
The output of this Monostable block is now your "lock" signal. It will become 1 as soon as it's triggered by a gear change and will automatically return to 0 after 3 seconds.
Use the "lock" signal from the Monostable block to control a Switch that allows or blocks the shift commands.
  1. Get your shift_command (+1 or -1 from your up/downshift logic).
  2. Connect the shift_command to the bottom input of a Switch block.
  3. Connect a Constant block (value 0) to the top input of the Switch.
  4. Connect the "lock" signal (from the Monostable block) to the middle control input of the Switch.
Here is the documentation:
Hope it helped!

More Answers (1)

Altaïr
Altaïr on 10 Jul 2025
One straightforward approach to achieve this is by using a Stateflow chart, as illustrated below.
For those who prefer to work with Simulink blocks, building a counter with the Detect Change block and implementing the if-else logic using "If" and "If Action Subsystem" blocks is a suitable method.
Both approaches produce the desired output, as shown.
For more information on the blocks refer the following links:
  1 Comment
Dominik
Dominik on 10 Jul 2025
Hey @Altaïr, thank you very much for taking the time to look into my problem!
I tried to copy your Simulink model but unfortunately I still haven't been able to solve it. The output looks exactly like the input. I think I'm missing the logic in the if action subsystem even tho it seems like there is nothing in the subsystem.
Let me show the gear curve, I marked all the "illegal" shifts (signal changes). All the shifts that are 3s and above are fine and should be displayed in the result and the ones below should not because the logic does not allow a shift if a previous shift is less than 3 seconds ago. The vector for the repeating seq. stair is: [3 3 3 4 4 4 4 5 4 4 4 4 5 5 5 5 5 5 4 4 4 5 5 4 3].' if you want to try this sequence.

Sign in to comment.

Tags

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!