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

Pwm minimum frequency setting

hi, I would like to use pwm to output the 1HZ waveform to drive the motor, but when I set the frequency to be 1HZ, I can not find the device and cause 51822 to reset. This is my code:

    Motor_Pwm_Init(1000000,1,1);
    Motor_Duty_Set(50,50);

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

	uint32_t err_code;
	
	app_pwm_disable(&PWM1);
	app_pwm_uninit(&PWM1);
	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;
	wdt_feed();
	while (app_pwm_channel_duty_set(&PWM1,(uint8_t) 0, DutyLeft) == NRF_ERROR_BUSY)
	{
		
	}
}
Related