How to design a simple counter and reset counter in Simulink and MATLAB?

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ธ.ค. 2024

ความคิดเห็น • 46

  • @garypstrike
    @garypstrike 4 ปีที่แล้ว +1

    Very Helpful. I plan to use this technique for an integrator in an earlier version of Simulink which does not provide the reset input on the integrator.

  • @omarsalem5832
    @omarsalem5832 14 วันที่ผ่านมา +1

    Thank you

  • @abhishekm1903
    @abhishekm1903 5 ปีที่แล้ว +2

    Very Nice Tutorial

  • @garypstrike
    @garypstrike 4 ปีที่แล้ว +1

    Just a note: I noticed that in your example the counter can be made to reset at each 5 second interval (instead of 6) by setting the threshold value to 4 instead of 5. Also seems to be a cleaner waveform.

  • @waleedalsamti
    @waleedalsamti 6 ปีที่แล้ว +2

    Thank you for very good explanation

  • @Opuskiller1
    @Opuskiller1 5 ปีที่แล้ว +2

    This is so helpful!!

  • @angelleal3005
    @angelleal3005 3 ปีที่แล้ว

    Great video. Here is how my application works. I'm using an optical sensor to measure the revolutions on a disk. For that I put a pin on the disk so that every rotation it makes is counted as 1 pass on the optical sensor. I want to implement a counter on simulink that starts counting up once the pin passes through my optical sensor and resets itself on the next pass so that it starts counting back again. I managed to convert the analog signal coming from the sensor to a series of pulses so that its value is either one or zero. Now I'm on the counter part but still trying to figure it out. As I said earlier the idea is that for the first value of 1, the counter begins the counting and then on the next value of 1 it resets back to zero and starts counting again. If you have some idea on how to implement this please let me know. Again, great video. Keep up the good work.

  • @johnwayne7923
    @johnwayne7923 4 ปีที่แล้ว +2

    Thank you kind sir

  • @ajayjoseph4626
    @ajayjoseph4626 6 ปีที่แล้ว +1

    Great video sir! I have a Simulink model where I have PWM values starting off at around ~160. I want to create a counter to count up to the ~160 approx and then disable the counter and PWM values should take over. From this video, I want to replace the 5 with the varying PWM, so the counter will count up to the PWM value and the counter should disable. Any suggestions will be much appreciated.

    • @ProgrammerWorld
      @ProgrammerWorld  6 ปีที่แล้ว +1

      Hi Ajay,
      There can be various approach for this. The one I can quickly think of is to use the Enable subsystem block. Have the output of the counter in a switch block (controller input , u). Set the threshold of your switch to ~160. Once this threshold is crossed then switch will turn on one side. You can give Boolean input true or constant input 1 to that port of switch. Connect this switch block output to the enable subsystem condition signal. Thus the enable subsystem will get enabled only once the counter crosses 160. If needed, you can reset the counter value at 160 again to 0 as shown in the video. Hope this information helps.

    • @ajayjoseph4626
      @ajayjoseph4626 6 ปีที่แล้ว +1

      @@ProgrammerWorld Thanks for your reply. I ended up hard coding it on the microcontroller. Thank you very much for your suggestion and it's a great tutorial. Much appreciated!

  • @sangaythinley6802
    @sangaythinley6802 3 ปีที่แล้ว

    Thank you for the informative video. Actually I have some questions regarding counter time, can this counter time can be feed to stepper motor as this counter time shows the steps as per the time . I will be very happy to have your mail so that I can ask you some questions in personal. Thank you once again

    • @ProgrammerWorld
      @ProgrammerWorld  3 ปีที่แล้ว

      For counter time to be fed in the stepper motor, one can easily use the clock block instead. However, yes, this counter can also be used.
      For contacting us, please reach out to us through our below page:
      programmerworld.co/contact/
      For reference, the complete details of this tutorial is shared in the below link also:
      programmerworld.co/simulink/design-a-simple-counter-and-reset-counter-in-simulink/
      Cheers
      Programmer World
      programmerworld.co
      -

  • @gauravpatil1630
    @gauravpatil1630 3 ปีที่แล้ว

    Hi,
    I have 0 or 1 trigger as a input.. so let's say 1 is shows up for 50 secs and I want to limit it to 10sec. The first step is limit the sum of 1 showing time to 10 sec but the other part is I want to limit it for next 300 sec so that the counter should not start counting and once 300sec over it starts again then 10sec cut the counter hold it for 300 sec and so on. Can you help?

  • @simaroaerial7237
    @simaroaerial7237 ปีที่แล้ว

    You shouldn't need to change the solver parameter. Just set the sample time to one second in the delay block and set -1 as initial condition to start it at zero.

    • @ProgrammerWorld
      @ProgrammerWorld  ปีที่แล้ว

      Yes, you are right. Setting the sample time to 1 second in the delay block is a much better solution to set the counter step size equal to simulation time.
      For reference, details shown in this video is also shared in the below link:
      programmerworld.co/simulink/design-a-simple-counter-and-reset-counter-in-simulink/
      Cheers
      Programmer World
      programmerworld.co
      -

  • @natarajana.v4262
    @natarajana.v4262 4 ปีที่แล้ว +1

    thankyou.

  • @sandraprasad393
    @sandraprasad393 11 หลายเดือนก่อน

    Can you please make a model of timer which is on for 10 sec and off for 5 sec

    • @ProgrammerWorld
      @ProgrammerWorld  11 หลายเดือนก่อน

      Thanks for the suggestion. I will try to come up with such a demo.
      However, in the meantime you can check my below page. It may help.
      programmerworld.co/simulink/how-to-create-random-pwm-pulse-width-modulation-signal-with-fixed-duty-cycle-in-simulink-matlab-r2023a-using-random-number-generator-block/

    • @ProgrammerWorld
      @ProgrammerWorld  11 หลายเดือนก่อน

      Below may help. Please check:
      programmerworld.co/simulink/how-to-design-pwm-signal-with-different-on-and-off-period-in-matlab-simulink/

    • @sandraprasad393
      @sandraprasad393 11 หลายเดือนก่อน

      Not this one.. Question is ' model a system inwhich 1) on the timer when the voltage is 5v
      2)on the timer for 10second and off for the next 5second and repeat

  • @rebeccabertazzoni4484
    @rebeccabertazzoni4484 4 ปีที่แล้ว

    Hello :) Thanks for the video, it is very helpful. I have one question about it. If I use your example, is it possible to count the time it takes for the counter to rise from 0 to 5? In my case, the time for each step is not 1 second, it varies, but my threshold is always the same. So, everytime when my counter reaches the threshold to switch back to zero, I would like to know how much time it took. Thank you!

    • @ProgrammerWorld
      @ProgrammerWorld  4 ปีที่แล้ว

      If your question pertains to real clock time for simulation while counter is counting, then I do not think it can be directly done in the Simulink. You can use certain performance measurement techniques in Matlab (like tic-toc command) to measure the real world clock time it takes to simulate the counter for 5 simulation seconds.
      However, if you want to measure the simulation time in your model then you can simply use a clock block for the same.
      Good Luck
      Programmer World
      programmerworld.co
      -

  • @hiramansuryawanshi2025
    @hiramansuryawanshi2025 3 ปีที่แล้ว

    How to implement up counter and down counter in same logic.it should make triangle

    • @ProgrammerWorld
      @ProgrammerWorld  3 ปีที่แล้ว

      Instead of 0 in the other option of Switch block, just implement the decreasing counter logic. Below video can help in implementing the down counter logic:
      th-cam.com/video/9seGi3vMWAc/w-d-xo.html
      th-cam.com/video/aUQ3RNH_oQs/w-d-xo.html
      Cheers
      Programmer World
      programmerworld.co/
      -

  • @rajashriwarade1786
    @rajashriwarade1786 5 ปีที่แล้ว

    Sir...if I want the counter only for 2 cycles then what will be the design

    • @ProgrammerWorld
      @ProgrammerWorld  5 ปีที่แล้ว

      1st use case: After every 2 cycles you want to reset the counter and begin counting again from 0. This case is explained in the later part of this video (after 6:30 mins) where it is shown how to design reset counter.
      2nd use case: The other use case could be that you only want to count for 2 steps irrespective of simulation time of Simulink. In that case you have to use the reset part of the model with Threshold value of switch block being compared with a clock block's output. You can compare that when the clock gives output of more than 2 (2 seconds of simulation time) then your switch block's True condition gives a fixed output of 0. And hence the counter's output will be set to 0 after 2 cycle time.
      I hope the above explanation helps to design your requirement.

  • @yashm5902
    @yashm5902 3 ปีที่แล้ว

    If 3 bit how to proceed!

  • @deepakkumarpandia917
    @deepakkumarpandia917 5 ปีที่แล้ว

    how can we generate a pulse in every 10 seconds in stateflow model??

    • @ProgrammerWorld
      @ProgrammerWorld  5 ปีที่แล้ว

      You can watch my below video:
      th-cam.com/video/wo0eIZq93aU/w-d-xo.html
      This video shows how to generate pulse signals using Simulink blocks. It does not shows the implementation in Stateflow. You can take a hint from this video for implementation in Simulink. If it will be possible then I will create another tutorial showing the implementation in Stateflow.

  • @rajashriwarade1786
    @rajashriwarade1786 5 ปีที่แล้ว

    If We dont want continuous output...if we want it only for two cycles then??

    • @ProgrammerWorld
      @ProgrammerWorld  5 ปีที่แล้ว

      Then put a clock block and rest of the implementation in an enable subsystem. Once clock reaches your required threshold of 2 cycles, just disable the complete subsystem.

  • @silambuarasan5956
    @silambuarasan5956 6 ปีที่แล้ว

    I want many different different increment and decrement and another output signal s

    • @ProgrammerWorld
      @ProgrammerWorld  6 ปีที่แล้ว

      It can easily be done using a Mask Parameter and taking the value of the parameter in the Add block in the feedback loop of counter. I will try to make a video to explain this.

    • @ProgrammerWorld
      @ProgrammerWorld  6 ปีที่แล้ว

      You can refer to below video. This video shows how you can design a variable step counter in Simulink:
      th-cam.com/video/FXGoe91n9GE/w-d-xo.html

  • @Snesvlog
    @Snesvlog 6 ปีที่แล้ว +1

    How to stop the counter once it comes to zero??

    • @ProgrammerWorld
      @ProgrammerWorld  6 ปีที่แล้ว

      Once the counter reaches to zero you can either reset it as shown in my video tutorial.
      If you want to stop it completely then you can use conditional subsystems like Enable subsystems or If condition subsystems. In this subsystem once the counter value reaches to Zero you can disable it. So, the value of counter will not be considered anymore.

  • @josemanuelcaballero1162
    @josemanuelcaballero1162 4 ปีที่แล้ว

    what if the reset threshold is variable?

    • @ProgrammerWorld
      @ProgrammerWorld  4 ปีที่แล้ว

      Please check if the below video helps:
      (How to design variable step increasing and decreasing counter in Simulink?)
      th-cam.com/video/FXGoe91n9GE/w-d-xo.html
      Good Luck
      Programmer World
      programmerworld.co
      -

  • @Shorts-in-Nutshell
    @Shorts-in-Nutshell 6 ปีที่แล้ว

    How to design Decrement counter?

    • @ProgrammerWorld
      @ProgrammerWorld  6 ปีที่แล้ว

      Hi Ankita,
      You can watch my other video titled "How to design a Decreasing Counter and reset counter in Simulink?". This video shows how you can decrease the count in each simulation step. You can watch it using below link:
      th-cam.com/video/9seGi3vMWAc/w-d-xo.html

  • @drirfankhan2073
    @drirfankhan2073 4 ปีที่แล้ว

    How to make this statement in simulink :
    Varying the current from 1 to 25A, in steps of 0.4 ampere, every 40 s over a total simulation period of 2720 s.

    • @ProgrammerWorld
      @ProgrammerWorld  4 ปีที่แล้ว

      In this tutorial, the counter shown takes all the default values such as step size, increment value, etc. For your values, the specifications in the counter will need to be modified. Say for example, step-size should be 40s, Total simulation time = 2720s and increment value in every step to be 0.4Amps. Once you these changes in the model, you will get the model for your requirement.
      For further reference you can watch my other videos on counter topic using the below links:
      th-cam.com/video/FXGoe91n9GE/w-d-xo.html
      th-cam.com/video/aUQ3RNH_oQs/w-d-xo.html
      Hope the above helps.
      Good Luck
      Programmer World
      programmerworld.co
      -

    • @drirfankhan2073
      @drirfankhan2073 4 ปีที่แล้ว +1

      @@ProgrammerWorld thank you sir

    • @drirfankhan2073
      @drirfankhan2073 4 ปีที่แล้ว

      Sir can you please tell me how to make this for a system containing continuous states:
      Varying the current from 1 to 25A, in steps of 0.4A, every 40sec over a total simulation period of 2720sec.
      Please help sir

  • @srm113k
    @srm113k 3 ปีที่แล้ว

    reset back to giro