Counter for Sawtooth signal in Simulink
16 views (last 30 days)
Show older comments
Hello everybody,
I'm trying to set up a round counter for my model. The round counter should count how many revolutions (360 ° or 6.2832rad) my motor has turned.
The signal is a sawtooth and works discretely (50us).
Example of a rising sawtoothes:
With a rising sawtooth ++ (increment) and with a falling - - (decrement).
But I didn't get any further with normal counting.
I think the discrete signal makes it a little more difficult.
I Added an example, but It is missing a sawtooth. But I don´t see where the mistake is.
I thank you in advance.
0 Comments
Answers (4)
Andy Bartlett
on 4 May 2021
Look at the edge detection blocks and the discrete integrator in accumulator mode.
You can also look under the mask of the edge detection blocks to see the underlying design pattern.
Instead of detecting a fall below zero, from the plot it looks like you'll need a different threshold value.
Andy Bartlett
on 7 May 2021
The icon shows the Z-domain description of the Integrator block in accumulator mode (noting that K = 1)
Y(z) = ( z / (z-1) ) * U(z)
which becomes
z * Y(z) - Y(z) = z * U(z)
with some algebra becomes
Y(z) = z^-1 * Y(z) + U(z)
transforming to time domain becomes and noting that z^-1 corresponed to a 1 time step delay.
Y(i) = Y(i-1) + U(i)
So the output at time step i is computed by adding the input at time step i to the output at the previsous time step.
Initializing the first Y to zero, the block is adding up all the input values over time (also called accumlation).
If the inputs are boolean they have values 0 and 1, so the accumulator is doing a simple count of the 1's that have appeared since the simulation started.
To count both up and down feed the appropriate sequence of -1, 0, or 1 into the accumulator.
To create that sequence study what detect fall and detect rise blocks are doing, then generalize the for your situation to create boolean signals representing the wrap forward or wrap back events.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!