Hello
I would like to use three PWM to output multiple sounds with one buzzer.
First of all, I am testing using two PWM. There is no problem using only one PWM, but there seems to be a problem with the initialization when using two.
APP_PWM_INSTANCE(PWM1,1); // Create the instance "PWM1" using TIMER1 (name, NRF_DRV_TIMER_INSTANCE(num)). APP_PWM_INSTANCE(PWM2,3); // Create the instance "PWM2" using TIMER2. void pwm_play_buzzer_duration(uint32_t duration) { uint8_t i; uint32_t duty = 50; NRF_LOG_INFO("pwm_play_buzzer_duration =>"); ready_flag = false; //Set the duty cycle - keep trying until PWM is ready... while (app_pwm_channel_duty_set(&PWM1, 0, duty) == NRF_ERROR_BUSY); nrf_delay_ms(duration); app_pwm_disable(&PWM1); } void pwm_play_buzzer_duration_2(uint32_t duration) { uint8_t i; uint32_t duty = 50; NRF_LOG_INFO("pwm_play_buzzer_duration =>"); ready_flag = false; // Set the duty cycle - keep trying until PWM is ready... while (app_pwm_channel_duty_set(&PWM2, 0, duty) == NRF_ERROR_BUSY); nrf_delay_ms(duration); app_pwm_disable(&PWM2); } void pwm_init(void) { ret_code_t err_code; /* 1-channel PWM, 200Hz, output on DK LED pins. */ app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1500, BUZZER_PIN); //original 5000L /* Switch the polarity of the second channel. */ pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH; /* Initialize and enable PWM. */ err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback); APP_ERROR_CHECK(err_code); app_pwm_enable(&PWM1); app_pwm_config_t pwm2_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000, BUZZER_PIN); pwm2_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH; err_code = app_pwm_init(&PWM2,&pwm2_cfg,pwm_ready_callback); APP_ERROR_CHECK(err_code); app_pwm_enable(&PWM2); }
How should I set it up when I use multiple PWMs?