Hi,
I am using PWM for a buzzer. It is working, but the current consumption is always 300uA when PWM is not in use. This minimal current consumption appears right after the app_pwm_init
function and never stops.
Could you confirm that this implementation is correct? Should I initialize the PWM instance for every use or can I resue an instance like in the code below?
APP_PWM_INSTANCE(PWM1,1); // Create the instance "PWM1" using TIMER1.
void pwm_ready_callback(uint32_t pwm_id) // PWM callback function
{
}
void buzzer_kernel_init(void)
{
uint32_t err_code;
uint32_t duty = 50;
// PWM
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(250, WATCH_BUZZER_PIN_D);
err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
APP_ERROR_CHECK(err_code);
app_pwm_enable(&PWM1);
// Set the duty cycle - keep trying until PWM is ready...
while (app_pwm_channel_duty_set(&PWM1, 0, duty) == NRF_ERROR_BUSY);
app_pwm_disable(&PWM1);
// Do bip
app_pwm_enable(&PWM1);
nrf_delay_ms(50);
app_pwm_disable(&PWM1);
nrf_delay_ms(50);
// Do bip
app_pwm_enable(&PWM1);
nrf_delay_ms(50);
app_pwm_disable(&PWM1);
}
void buzzer_kernel_on(void)
{
app_pwm_enable(&PWM1);
}
void buzzer_kernel_off(void)
{
app_pwm_disable(&PWM1);
}