I have a microcontroller F28027 PICCOLO USB
, and I want to generate code for a model created in simulink. My question is: how can I generate a PWM who has the duty cycle after a sine? The sine is between 0 and 1023 and I have also the frequency 20kHz or more. I need to do this things in Simulink and after that to build model
. I already tried all I found on the internet but I can't figure out how to synchronize the duty cycle with the sine wave. I need to use a ePWM or what block?
1
votes
1 Answers
2
votes
If you have a sine curve in a coordinate system where each coordinate is (X, Y), then let the time you update the PWM with be X, and the PWM duty cycle be Y.
That is, after X time units, update the PWM with the value of sin(X)
.
You have to re-scale from radians to raw timer ticks. It might be convenient to use the same unit everywhere, so perhaps pick a universal unit which is 1 tick of your PWM cycle expressed in (micro/milli) seconds.