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

buzzer pwm&power

FormerMember
FormerMember

I want to use the pwm to control buzzer, but when I use init function, the power will increase 880 uA, how to decrease the power.

void beep_on(void)//beep on
{
	  app_pwm_channel_duty_set(&PWM1, 0, warning_voice);
}

void beep_off(void)
{
		app_pwm_channel_duty_set(&PWM1, 0, 0);  
}

void beep_on_on(void)
{
		beep_pwm_init();
}
void beep_off_off(void)
{
	  app_pwm_uninit(&PWM1);//in this 
		nrf_gpio_cfg_output(BEEP);							
		nrf_gpio_pin_clear(BEEP);
}
bool ready_flag1=0;
void pwm1_ready_callback(uint32_t pwm_id)    // PWM callback function
{
    ready_flag1 = true;
}
void beep_pwm_init(void)
{
		app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(260,BEEP);//(250L,1,9);//
		pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
	  app_pwm_init(&PWM1,&pwm1_cfg,pwm1_ready_callback);
    app_pwm_enable(&PWM1);
		app_pwm_channel_duty_set(&PWM1, 0, 0);
}

1、first, I use beep_pwm_init() before for(;;), and the testing instrument display the power is increase 880uA. and then, I use beep_on() and beep_off() to start or stop the buzzer. and the connection is good, not always disconnected.

2、I use another way. I use beep_on_on() function when I want the buzzer work, and when I want the buzzer off, I use the beep_off_off(), the power is decreased, but the connection is no longer stable.

please help me to over come this question, thanks.

  • The reason you get that high current draw when initializing the pwm is because the pwm uses the timer peripheral which in turn requires the high frequency clock (HFCLK), see chapter 8.3 "Block resource requirements" in Product Specification.

    You can reduce the current consumption some (~70uA) by letting the HFLCK run from the crystal instead of the RC oscillator (search on this forum for how to do this with or without the SoftDevice).

    The best way to reduce current consumption is probably to disable the pwm when not in use. The PWM library from SDK 9 is known to have some bugs related to the disable or uninit functions among other things, you should upgrade to SDK 10 or 11 (newest). In SDK 11 there is also a new library called "low_power_pwm" which uses RTC (app_timer) to create the PWM. Maybe this is suited for your application.

  • FormerMember
    0 FormerMember in reply to Ole Bauck

    thank you so much, dear friend.

    #define KEY_20MS_DELAY		                   APP_TIMER_TICKS(20,   APP_TIMER_PRESCALER)
    static app_timer_id_t                                             timer_key_20ms_id;
    

    what you say is like that? but this minimum period is 1s, and what I need is about 250us. the buzzer and motor need more than 1HZ frequency.

    I see the SDK11.0, and find the file "low_power_pwm", this is a peripheral test, I try to transplant it to SDK 9.0 with ble, whitch is ble_peripheral.

    All I need is:

    1. about 250us period

    2. low power,I could turn the pwm on or off easy and convenient.

    3. with ble.

    thank you again.

  • Minimum period with app_timer is about 30us, not 1s. The low_power_pwm library is not present in SDK 9, only in SDK 11 (it's a new feature).

  • FormerMember
    0 FormerMember in reply to Ole Bauck

    .

    #define KEY_20MS_DELAY                         APP_TIMER_TICKS(20,   APP_TIMER_PRESCALER)
    static app_timer_id_t                                             timer_key_20ms_id;
    

    this is 20ms,the min time is not 1ms? how to be 30us

  • FormerMember
    0 FormerMember in reply to Ole Bauck

    low_power_init();

    	nrf_delay_ms(500);
    	nrf_delay_ms(500);
    	low_power_pwm_stop(&low_power_pwm_0);
    	nrf_delay_ms(500);
    	nrf_delay_ms(500);
    	low_power_pwm_start((&low_power_pwm_0), low_power_pwm_0.bit_mask);
    	nrf_delay_ms(500);
    	nrf_delay_ms(500);
    	low_power_pwm_stop(&low_power_pwm_0);
    	nrf_gpio_cfg_output(24);
    	nrf_gpio_pins_clear(24);
    

    when I close the pwm. the power is not decrease

Related