why need to plus one

6 views (last 30 days)
yeyuan zhu
yeyuan zhu on 16 Dec 2021
Commented: yeyuan zhu on 1 Mar 2022
Hi,I have a problem in code generation of ePWM module. I read the oficial routine of PMSM vector control, and see the TBPD in the ePWM configuration dialog is "target.PWM_Counter_Period+1". I don't know why need to plus one.
if you know, could you tell me why need to plus one. Thanks a lot.
  1 Comment
Walter Roberson
Walter Roberson on 16 Dec 2021
ePWM -- appears to mean "enhanced Pulse Width Modulation"
PMSM -- appears to mean "permanent magnet synchronous motor"
TBPD -- I cannot find a meaning for.

Sign in to comment.

Accepted Answer

Keyur Mistry
Keyur Mistry on 12 Jan 2022
If you will check in the script file you will find the following equation for calculating PWM contrer: -
Target.PWM_Counter_Period = round(Target.CPU_frequency/Target.PWM_frequency/2)
Now let us say if CPU frequency is 200MHz and PWM frequency is 12kHz then PWM counter is 8333. The expacted sampling time is 8.333333e-5 sec but if we directly uses PWM counter value we will get sampling time as 8.333e-5 sec. Hence to match with expactation we add 1 to the counter value and the new sampling time will be 8.334e-5 sec.
So the reason of adding 1 is basically to keep the generated sampling time in processor always be equal or grater than the demanded sampling time.
If the ratio of CPU frequency and PWM frequency is an integer then you can remove + 1 to the counter value.

More Answers (1)

Walter Roberson
Walter Roberson on 16 Dec 2021
The range varies from 0 to PWM_counter_period. PWM outputs when PWM up-counter matches CMPA and PWM down-counter matches CMPB
That suggests to me that there are (PWM_counter_period plus 1) different states -- for example if PWM_counter_period is 3 then states 0, 1, 2, 3 would exist, which would be 4 different states.
However, this is not a topic I have ever examined before, and this is possibly not relevant.
  1 Comment
yeyuan zhu
yeyuan zhu on 16 Dec 2021
Edited: yeyuan zhu on 16 Dec 2021
I'm sorry that I typing TBPRD as TBPD and Thanks for the link about PWM. Oddly enough, I clicked on the link and found that the Timer Period configuration for the linked document had not plus 1 either.

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!