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

9 visualizzazioni (ultimi 30 giorni)
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?
  2 Commenti
Todd Flanagan
Todd Flanagan il 27 Mag 2011
Could you give us a screenshot of what you have now?
abdelkader mahmoudi
abdelkader mahmoudi il 4 Nov 2020
hello if you get the solution please tell usabout it i'm really need it

Accedi per commentare.

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 27 Mag 2011
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 Commenti
Fangjun Jiang
Fangjun Jiang il 30 Mag 2011
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 il 31 Mag 2011
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

Accedi per commentare.

Più risposte (1)

Fangjun Jiang
Fangjun Jiang il 31 Mag 2011
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 Commenti
harish bharadwaj
harish bharadwaj il 7 Giu 2011
could u please tell how to send that screenshot of that model
Walter Roberson
Walter Roberson il 7 Giu 2011
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

Accedi per commentare.

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by