Problem with the time in stateflow

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

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 25 Sep 2012
Modifié(e) : Azzi Abdelmalek le 25 Sep 2012

0 votes

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 commentaire

Jaime
Jaime le 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.

Connectez-vous pour commenter.

tuan tuan
tuan tuan le 19 Juin 2014

0 votes

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

Catégories

En savoir plus sur Stateflow dans Centre d'aide et File Exchange

Question posée :

le 24 Sep 2012

Community Treasure Hunt

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

Start Hunting!

Translated by