Problem combining Count and switch block in simulink

9 views (last 30 days)
I'm trying to create a simulink model that counts the number of pulses of a square wave, and depending on that number, the model turns on or off the square pulse. In order to count the number of pulses, I include a Count block, whose input is the square wave. Then I compare the number of counts with a fixed value. If the number of counts is bigger, then, the input signal changes to a zero signal. In that step I included a Switch block. When I simulated the model, using Simulink R2019b, the counts signal had jumps at expected times, but with random heights.
The Count block is set up to count either edge, and count data type is double. The model is using VariableStepDiscrete solver, with auto(0.1) step. I simply removed the switch block, and built a simpler model, that just counted the number of cycles, while comparing the number of counts to reference value. Turns put that model works fine.
Why this happens? How can I switch input signals depending on the number of counts? How can I reset the number of counts depending on the cycles counted? By the way, the idea of this aplication is to use optointerrupters combined with an encoder wheel to measure the angle swept by the wheel. Thanks in advance.

Accepted Answer

Devineni Aslesha
Devineni Aslesha on 24 Oct 2019
The issue occurred primarily because the Switch block is being used before the Counter block in your Simulink model. In order to switch the input signal based on the number of counts, the switch block should be used after the count block as shown below. To reset the number of counts depending on the cycles counted, select the Reset Input port check box in Counterblock. When you enable the Rst port, the block resets the counter to its initial value each time a trigger event occurs at the Rst port.The type of trigger event is based on the Count event parameter in the counter block. The Period of the input signal should be specified as a value greater than the fixed value (i.e. “5”) selected to reset the input signal. In the given model, the Period is selected as “6.
Simulink Model.png
Result.png
For more information refer to the documentation given below:
  1 Comment
Maria Fernanda Piracoca Mora
Thanks for your answer. However, could you help me to understand why the switch block must be used after the count block? Thanks in advance,

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!