
Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
175
Ver.1.0.0
Use
“void gpio_set_func(GPIO_PinTypeDef pin, GPIO_FuncTypeDef func)” to set PWM
function of pins.
Pin: actual output pins of PWM waveform. func must select from AS_PWM0 ~
AS_PWM5_N in the definition of GPIO_FuncTypeDef according to actual PWM functions
of GPIOs in the table above.
typedef
enum
{
……
AS_PWM0
= 20,
AS_PWM1
= 21,
AS_PWM2
= 22,
AS_PWM3
= 23,
AS_PWM4
= 24,
AS_PWM5
= 25,
AS_PWM0_N
= 26,
AS_PWM1_N
= 27,
AS_PWM2_N
= 28,
AS_PWM3_N
= 29,
AS_PWM4_N
= 30,
AS_PWM5_N
= 31,
}
GPIO_FuncTypeDef
;
For example, use PA0 as PWM0:
gpio_set_func(GPIO_PA0, AS_PWM0)
10.1.2 PWM Clock
The
“pwm_set_clk(int system_clock_hz, int pwm_clk)” is used to set PWM clock.
“system_clock_hz”: current system clock CLOCK_SYS_CLOCK_HZ. (The marco is
defined in app_config.h.)
“pwm_clk”: PWM clock to be configured. “system_clock_hz” must be an integral
multiple of “pwm_clk” so as to get the right PWM clock via frequency division.
To increase accuracy of PWM waveform, PWM clock must be as large as possible but
smaller than system clock. I
t’s recommended to set “pwm_clk” as
“CLOCK_SYS_CLOCK_HZ”:
pwm_set_clk(CLOCK_SYS_CLOCK_HZ, CLOCK_SYS_CLOCK_HZ);
Suppose the current system clock CLOCK_SYS_CLOCK_HZ is 16000000, the PWM
clock set above equals to the system clock, as 16M.
If PWM clock needs to be 8M, set as below. No matter how the system clock changes
(CLOCK_SYS_CLOCK_HZ is 16000000, 32000000 or 48000000), PWM clock will be
8M.
pwm_set_clk(CLOCK_SYS_CLOCK_HZ, 8000000);