Problem combining Count and switch block in simulink

15 次查看(过去 30 天)
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.

采纳的回答

Devineni Aslesha
Devineni Aslesha 2019-10-24
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 个评论
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,

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by