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

PWM of nRF52805

Dear all:
                Recently, I was debugging nrf52805 by custom PCB, using sdk17.00, I enabled PWM, frequency of 4kHz, to drive 4kHz passive buzzer, encountered a problem:
                The buzzer seems to have a strong noise, as if it was interrupted by something.
                We analyzed the PWM waveform with an oscilloscope and found that there was no problem with the waveform.
                We also tried to analyze the causes of the noise. After we turned off the advertising, the buzzer noise almost disappeared.
                We tried to move the same driver to nRF52810 and nRF52832, and found that even if there was a advertising, the buzzer would not have noise, which was very stable.
                The PWM configuration I use is as follows:


                static void PWM_config(void)
                {
                  app_pwm_config_t Buzzer_function_pwm_cfg =
                  APP_PWM_DEFAULT_CONFIG_1CH(250, BUZZER);

                  ret_code_t err_code = app_pwm_init(&Buzzer_function, &Buzzer_function_pwm_cfg, NULL);
                  APP_ERROR_CHECK(err_code);

                 app_pwm_enable(&Buzzer_function);

                 app_pwm_channel_duty_set(&Buzzer_function, 0, 50);

                 }


                Can someone give me some advice?
Thanks

Parents Reply Children
  • Hi,

    No, it shouldn't be problematic. app_pwm doesn't use the PWM peripheral, instead it uses bit-banging and a GPIO pin to produce a PWM signal. 

    What pins are you using?

    regards

    Jared

  • Hi,
    I used PIN P0.16,PPI function seems to be not working, it seems to be interrupted intermittently.

  • colijevia said:
    PPI function seems to be not working, it seems to be interrupted intermittently.

    PPI runs independently of the CPU and shouldn't be interrupted. Could you elaborate more on this? 

    If you probe the PWM signal on P0.16, how does it look like when you compare it with the samples that has a nRF52832? 

  • Hi,
    Sorry, I didn't notice that the program in 52832 added delay:

    ...
    buzzer_power_on();
    nrf_delay_ms(500);
    buzzer_power_off();
    ...

    I found that the buzzer is very stable only during the delay period 500ms.
    Now, I simulate PWM by PPI and timer, but no matter on nrf52323 or nrf52810, the buzzer will also be interrupted.
    My configuration is as follows:

    static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(1);
    static nrf_ppi_channel_t m_ppi_channel;

    void my_gpiote_init(void)
    {
    ret_code_t err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_config_t out_config = NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(true);

    err_code = nrfx_gpiote_out_init(BUZZER_PIN, &out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_task_enable(BUZZER_PIN);

    }

    static void PPI_event_init(void)
    {
    ret_code_t err_code;
    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;

    err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, NULL);
    APP_ERROR_CHECK(err_code);

    uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 125);
    nrf_drv_timer_extended_compare(&m_timer,
    NRF_TIMER_CC_CHANNEL0,
    ticks,
    NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
    false);

    nrf_drv_timer_enable(&m_timer);
    uint32_t timer_compare_event_addr =

    nrf_drv_timer_compare_event_address_get(&m_timer,NRF_TIMER_CC_CHANNEL0);


    uint32_t gpiote_task_addr = nrf_drv_gpiote_out_task_addr_get(BUZZER_PIN);

    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
    timer_compare_event_addr,
    gpiote_task_addr);
    APP_ERROR_CHECK(err_code);

    ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);

    APP_ERROR_CHECK(err_code);

    }

    Best regards
    colijevia

  • Hi,

    colijevia said:
    Now, I simulate PWM by PPI and timer, but no matter on nrf52323 or nrf52810, the buzzer will also be interrupted.

    So now you also see the issue on the other samples that have a different nRF52 IC? 

    Could you share the code that uses app_pwm that produces the issue? 

Related