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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 25일
편집: Azzi Abdelmalek 2012년 9월 25일

0 개 추천

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일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Stateflow에 대해 자세히 알아보기

질문:

2012년 9월 24일

답변:

2014년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by