You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

Purpose: to demonstrate how to implements independent PWM signal output. .
Command:
Usage: usage: ./sample_pwm PwmNum Freq DutyRatio
Parameter:
PwmNum pwm number
Freq: pwm frequency
DutyRatiopwm duty ratio (range0-1000)
Notice: 1.when gpio_pwm used for pwm function, the pin direction must be output.
2.The frequency and duty cycle parameters set by the interface may be different from those obtained by the interface.
Cause: The frequency is divided by using the frequency divider on the 54 MHz basic clock. The frequency divider is the value in the frequency control register.
When the frequency is set, the value obtained by dividing the set frequency by 54 MHz needs to be written to the frequency control register. For example, to set the 10 MHz clock, the coefficient value in the frequency control register is 5 (54 MHz/10 MHz = 5.4).
Read the frequency control register through the interface for reading the frequency. The coefficient value in the read frequency control register is 5. 54M/5 = 10.8M, rounded off to 11M.
The duty cycle is divided into 1000 equal parts in the 255th period. The DutyRatio parameter indicates the high-level time. The value written to the duty cycle control register is DutyRatio/1000 x 255.
For example, if the duty cycle to be set is 700, the value written to is 178 (700/1000 x 255 = 178.5).
Then, read the data through the interface for reading the duty cycle. The coefficient value in the duty cycle control register is 178. 178 / 255 * 1000 = 698.03. The value is 698.