Problem with the time in stateflow

6 views (last 30 days)
Jaime
Jaime on 24 Sep 2012
Answered: tuan tuan on 19 Jun 2014
Dear users,
I am trying to simulate a stepper motor driver with Stateflow, but I have found some problems that I am not able to solve it.
The driver has to work with a PWM of 20kHz. To control the period of the PWM I am using counters to increment them when the program detect a 1 us rise step. But when I see the results of the simulation the PWM frequency is about 16kHz (it takes 10 us more per PWM pulse). The AH and BH signals are inputs and AH is '1' when the comparation between the output driver and the current reference is greater than 0 (BH is '1' when this diference is less than 0)
As you can see, sometimes it works with a PWM frequency of 20kHz (50 us) and other times it works at 16.66 kHz (60 us). Any idea why this happens and how could I solve it?
I used the debugger to see what happen and it seems that the stateflow works correctly, but I don't know where is the problem with the time in the program. Do you know some other method to control correctly the time in stateflow?
Yours sincerely, Jaime

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 25 Sep 2012
Edited: Azzi Abdelmalek on 25 Sep 2012
You have to debug your chart step by step and watch your signals, there is maby an error in your chart. another important thing, how is your chart triggered? If you use a fixed step , it will be easier to debug then using event to trigger your chart. Other thing that possibly could create a problem is when your fixed step is not quite chosen compared to your signals frequencies
  1 Comment
Jaime
Jaime on 26 Sep 2012
Thank you for the advice. Finally I have done again another stateflow and this one works correctly...I still don't know where is the error in the first one but I don't want to spend more time with it.

Sign in to comment.


tuan tuan
tuan tuan on 19 Jun 2014
dear user
i don't known how to genarate PWM to control cicuit my project :use PWM (microchip) to driver the cicuit can you help me write code by stateflow .pleasea help me

Categories

Find more on Complex Logic in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!