Problem with the time in stateflow
6 views (last 30 days)
Show older comments
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)
here is the stateflow chart: http://img1.uploadhouse.com/fileuploads/16652/16652329c34bf837872ee3c0aceb5bd83a5eb2ef.jpg
and here the signal: http://img5.uploadhouse.com/fileuploads/16652/16652343dfed99bf3563615f6006b3e9f76a2b51.png
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
0 Comments
Answers (2)
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
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
0 Comments
See Also
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!