Hi .. i am new to pwm, i want to drive the gear motor for that i need pwm pin , which pin i can configure , how to do ? how to configure the pwm pin . which example will be easy to start with it
Hi .. i am new to pwm, i want to drive the gear motor for that i need pwm pin , which pin i can configure , how to do ? how to configure the pwm pin . which example will be easy to start with it
Hello,
I don't know exactly what motor you use, but if it is a small servo motor, the typical PWM duty cycles are 1000µs to 2000µs, and a PWM period of ms.
I suggest that you look into the example found in:
SDK\examples\peripheral\pwm_library
Note that this example sets the PWM period in:
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, BSP_LED_0, BSP_LED_1);
where 5000L (L for Long integer) is given in µs. so if you need a 20ms period, you must use:
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(20000L, BSP_LED_0, BSP_LED_1);
Then, you use the function app_pwm_channel_duty_set(&PWM1, channel_no, value) to change the duty cycle, which is the width of the PWM pulse. Channel_no is 0 or 1 (depending on the pin, BSP_LED_0 or BSP_LED_1), and value is the pwm period in percent of the PWM period. Please note that 1000µs is 5% of 20000µs, while 6% is 1200µs, so if you want smaller steps, change the app_pwm_channel_duty_set to divide by 1000 instead of 100, and you can give the pwm duty cycle in smaller steps.
Best regards, and good luck.
Edvin