Tool/software:
Hi, can we use a timer to generate a PWM? If so, how could we control/change its frequency and duty cycle while running?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
Hi, can we use a timer to generate a PWM? If so, how could we control/change its frequency and duty cycle while running?
Below steps, example code could be used for AM62x, AM64x devices. Also concepts and code applies for applications running on M4F and R5F cores. Just update Timer PWM pin, Timer Clock selection address and Timer instance as per user's Timer selection.
For this FAQ, we will focus on AM64x M4F.
Pick a timer
For this example, we are going to pick Timer2.
Timer Configuration:
Please consider notes below while using Timer + PWM .
NOTES :
1. When changing duty from 100% to other than 0% duty , make sure that SCPWM signal should be low . For this , user need to call Pwm_SetPeriodAndDuty API with 0% duty then feed user duty values, otherwise user may get different duty values .
2. Not enabled interrupts in the example.
3. Duty resolution is 1%.
4. By default 25MHz clock is feeding to Timer Module and prescale are disabled.
5. Call Pwm_SetPeriodAndDuty API , if any change in frequency and duty for only one time..
Test Results :
Tested the above example at 1Hz and 200KHz at 1% duty and 99% duty. All test cases are passing.