To implement a counter in MATLAB Simulink that increments and resets to 0 after reaching 20 while retaining the accumulated values

조회 수: 24 (최근 30일)
I want to create an increment counter; once it reaches 20, it should reset to 0, but the existing values should be present and added with the current values. How can I develop this logic in MATLAB Simulink ?
  댓글 수: 1
Paul
Paul 2024년 11월 24일
Hi Mahendran,
Can you clarify the meaning of "existing values should be present and added with the current values"?

댓글을 달려면 로그인하십시오.

답변 (1개)

Ayush
Ayush 2024년 11월 25일
편집: Ayush 2024년 11월 25일
Hi Mahendran,
I understand you need to implement the logic of incrementing a counter and once it reaches a certain limit, it should reset to 0 but the sum achieved should be preserved.
You can use several blocks for achieving this logic in MATLAB Simulink R2022b like:
  1. “Constant block”: To maintain the value of counter
  2. For reading more about this block, refer here: https://www.mathworks.com/help/releases/R2022b/simulink/slref/constant.html
  3. Unit delay block: It helps in incrementing the values of counter. For reading more about this, refer here: https://www.mathworks.com/help/releases/R2022b/simulink/slref/unitdelay.html
  4. Memory block: It helps to preserve the sum achieved till now. For reading more about this block, refer here: https://www.mathworks.com/help/releases/R2022b/matlab/ref/memory.html
  5. Switch block: It helps to reset the value once the counter reaches 20. For reading more about this block, refer here: https://www.mathworks.com/help/releases/R2022b/simulink/slref/switch.html
  6. Relational operator block: It helps to check whether the counter has reached value 20 or not. For reading more about this block, refer here: https://www.mathworks.com/help/releases/R2022b/simulink/slref/relationaloperator.html
I have attached the Simulink model implementing the above logic for your reference with this answer.
Hope it helps!
  댓글 수: 3
MAHENDRAN A
MAHENDRAN A 2024년 11월 25일
But yeah it workss, we need add a divide with the final value, to get accurated output, but i dont why its getting multiplied into 10 anf giving, lets say, the value which I'm expecting is 61, but npw with this logic, its coming 610, so i just divide by 10 at output signal.
If you know, how its multiplying the value 10, please let me know.
Ayush
Ayush 2024년 11월 26일
The above model is implementing the following logic:
1 + 2 + 3 + 4 + .... + 20 (lets say this sum is equal to x)
now, let's say number of iterations are y.
the model gives the following output: x*y
Hope this is the expected behaviour and if not, kindly give an example to depict by taking a small input and depicting the expected output.
Hope it helps!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by