How do I start a counter based on a threshold value in Simulink?

7 次查看(过去 30 天)
I am implementing some fault detection logic, i.e i am comparing some incoming digital data with the threshold value using comparator in Simulink. When incoming data crosses threshold value, a counter has to start. If that counter value is greater than 20 mili sec then counter has to send a step signal until the comparison using comparator is done.
How do I do this?

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-5-27
This counter question seems to come up often recently. One of the ways to implement a counter in Simulink is to use the Integrator block. Take a look at this post to see if it gives you a clue.
  3 个评论
Fangjun Jiang
Fangjun Jiang 2011-5-30
I assume you want to count how long your signal has exceeded the threshold value. Compare your signal value with the threshold value, if it is greater than the threshold, it outputs 1. Feed this signal to the integrator, as long as your signal is greater than the threshold, the comparator outputs 1 and the integrator keeps integrating, thus the output of the integrator is a time counter. Regarding reset, when do you want to reset the time counter? You can enable the reset of the integrator and construct your logic to provide that resetting signal. There is many options for the resetting signal, edge or low/high value. I am not clear what do your mean by saying "until the comparison using comparator is done". Do you mean when your signal is less than the threshold? Then you can use the opposite (logical NOT) of the comparator output to reset the integrator. What resetting signal do you have now? How can it reset regularly? Can you take a look at the resetting signal and see what's happening?
harish bharadwaj
harish bharadwaj 2011-5-31
i want to count how long the signal exceeded the threshold value.
i have followed according to your suggestion,but the integrator based counter is resetting even though the comparator output is one but this is not the way how i expected the counter to work. it has to count as long as the signal exceeds thresdhold value.
hope you are now clear about my problem.
please suggest me a solution for this

请先登录,再进行评论。

更多回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-5-31
It sounds like that you don't need to re-set your integrator. Let's say your input signal is greater than the threshold for 10 mili sec, then goes below the threshold for 20 mili sec, and then greater than the threshold for 30 mili sec, what is your expected output?
1. You want the output to increase from 0 to 0.01 for the first 10 mili sec, then stay at 0.01 for 20 mili sec time period, then goes from 0.01 to 0.04 for the rest of 30 mili sec time period. You don't need the re-setting. Disable the re-setting option of the integrator block.
2. You want the output to increase from 0 to 0.01 for the first 10 mili sec, then re-set to 0 for 20 mili sec time period, then goes from 0 to 0.03 for the rest of 30 mili sec time period. You need the re-setting. Use the opposite of the comparator block output to re-set the integrator block.
  4 个评论
Walter Roberson
Walter Roberson 2011-6-7
For locations you can upload to, please see
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Array and Matrix Mathematics 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by