This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Precise angle control of Servo motor using PWM

I have included PWM library in BLE uart example to control the servo motor. I am able to import the library successfully and able to control the servo. Below is my init_pwm function

void init_pwm(void)
{
		ret_code_t err_code;
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(20000L, SERVO);

    pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1,&pwm1_cfg,NULL);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);
	
		
		while (app_pwm_channel_duty_set(&PWM1, 0, 7) == NRF_ERROR_BUSY);
		nrf_delay_ms(100);
		app_pwm_disable(&PWM1);
}

Total period for a PWM to control a servo motor should be 20ms. This is have set in the init_pwm function above. Now the problem is to control the angle of the motor the Pulse width should be from 1ms to 2 ms max which converts to duty cycle 5% to 10% and the function  app_pwm_channel_duty_set get input in uint16_t. So I only have the option to set the duty cycle to 5,6,7,8,9 & 10.  Each value corresponds to 36 degree movement for servo motor. This is no where near to Precise angle controlling of servo motor. I have tested different values in this function and figured out that it works with value from 3 to 13. 

Is there any way I can control the angle of the motor precisely in 1 degree step size? 

Hardware information: Custom board with NRF52832. 

Related