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

Problem with pwm (piezo buzzer) using with ble_app_blinky example

Hi,

I am trying to switch on-off a piezo buzzer though ble using the ble_app_blinky example.

i modified the code such that

led_0 show advertising 

led_2 show connection

pin 8 show buzzer pin

Problem: the application runs correctly and connects with app but when i send the led_on command from app , the device automatically disconnect.

i have checked some threads and found out there is problem with pwm turning off.

#define ADVERTISING_LED                 BSP_BOARD_LED_0                         /**< Is on when device is advertising. */
#define CONNECTED_LED                   BSP_BOARD_LED_2                         /**< Is on when device has connected. */
#define LEDBUTTON_LED                   8                                      /**< LED to be toggled with the help of the LED Button Service. */
#define LEDBUTTON_BUTTON                BSP_BUTTON_0                            /**< Button that will trigger the notification event with the LED Button Service */

uint32_t value;  //for buzzer volume
APP_PWM_INSTANCE(PWM1,1);                   // Create the instance "PWM1" using TIMER1.
static volatile bool ready_flag;            // A flag indicating PWM status.
void pwm_ready_callback(uint32_t pwm_id)    // PWM callback function
{
    ready_flag = true;
}

void buzz_config(void){

    /* 2-channel PWM, 200Hz, output on DK LED pins. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(250L,LEDBUTTON_LED);
    /* Initialize and enable PWM. */
    app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
		pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
		app_pwm_enable(&PWM1);
	  app_pwm_channel_duty_set(&PWM1, 0, 0);
    
}
void buzz_on(){
			
			for (uint8_t i = 0; i < 40; ++i)
				{
					value = (i < 20) ? (i * 5) : (100 - (i - 20) * 5);
					ready_flag = false;
					while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY);
					nrf_delay_ms(25);
				}
												
}

static void led_write_handler(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t led_state)
{
    if (led_state)
    {
		 buzz_on();  
    }
    else
    {
		app_pwm_channel_duty_set(&PWM1, 0, 0); 
    }
}
int main(void)
{
    // Initialize.
    log_init();
    leds_init();
    timers_init();
    buttons_init();
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
	buzz_config();

    // Start execution.
    //NRF_LOG_INFO("Blinky example started.");
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

Please help me for the same. thanks

Parents Reply Children
No Data
Related