Problem with the time in stateflow

3 次查看(过去 30 天)
Jaime
Jaime 2012-9-24
回答: tuan tuan 2014-6-19
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

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-9-25
编辑:Azzi Abdelmalek 2012-9-25
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 个评论
Jaime
Jaime 2012-9-26
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.

请先登录,再进行评论。


tuan tuan
tuan tuan 2014-6-19
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

类别

Help CenterFile Exchange 中查找有关 Complex Logic 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by