Problem combining Count and switch block in simulink
9 次查看(过去 30 天)
显示 更早的评论
Maria Fernanda Piracoca Mora
2019-10-21
评论: Maria Fernanda Piracoca Mora
2019-10-24
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.
0 个评论
采纳的回答
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”.
For more information refer to the documentation given below:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!