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

Change the pwm frequency

hi, I follow the pwm routine, 51822 can work and output pwm, when I want to change the frequency of pwm encountered a problem, the program reset. I use the method when i need to change the pwm frequency when i reinitialize pwm_init

void Motor_Pwm_Init(uint32_t freq,uint32_t MotorLeft_Polarity,uint32_t MotorRight_Polarity)
{

	uint32_t err_code;

	app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(freq,MOTOR_LEFT_PIN,MOTOT_RIGHT_PIN); //set pwm frequency	
	
	pwm1_cfg.pin_polarity[0] = MotorLeft_Polarity;	 //Polarity of active state on pin.
    pwm1_cfg.pin_polarity[1] = MotorRight_Polarity;
	
	err_code = app_pwm_init(&PWM1,&pwm1_cfg,NULL);																						//  Init the PWM
    APP_ERROR_CHECK(err_code);

	app_pwm_enable(&PWM1);	
	
}

uint8_t Motor_Duty_Set(uint32_t DutyLeft,uint32_t DutyRight)
{
	uint8_t TimeOut = 0;
	
	while (app_pwm_channel_duty_set(&PWM1,(uint8_t) 0, DutyLeft) == NRF_ERROR_BUSY)

}
Related