Clear Filters
Clear Filters

How to make a time controlled multi port switch?

3 views (last 30 days)
Hello. I want to alternate between a set of inputs using a multi port switch block controlled by an imput control signal that varies in time. To make it more clear, imagine I have 3 data ports and 1 control input. I want to alternate between the 3 data ports every second. How can I do this? I was thinking, can I somehow make an input control signal that is a step function that has value 1 for 0<t<1, 2 for 1<t<2 and 3 for 2<t<3 and so on, periodically and use it as control input for the multiport switch? If so, how can I do this? Thank you.

Answers (1)

Sonam Gupta
Sonam Gupta on 9 Mar 2017
Using a ramp function and mod function will help you to achieve a periodic signal that will behave like step function. It will have value as 0 when t belongs to [0, 1), 1 when t belongs to [1,2) and 2 when t belongs to [2, 3). By doing mod of ramp function with 3 you will always get values in range of 0 to 3. Note that for this logic you need to use Zero based contiguous ordering for input ports. Set 'data port order' property in multi port switch block parameters to 'Zero-based contiguous'.
I have attached a dummy model with the file. It uses three constant blocks as input and in the scope block attached to multi port switch, you can observe the periodic output.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!