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
  • Hi,

    Are you seeing this on all of your samples that have the nRF52805? 

    regards

    Jared

  • Yes, I didn't see PWM introduction in the chip manual, but I used it. Would that cause any problems?

    Thank you.

  • 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? 

Reply Children
  • Hi,

     Sorry to reply late,i use nRF52832 custom PCB ,Keil version5,SDK15.00,here are my code:
    7558.APP_PWM.rar
    2072.PPI_PWM.rar
    Added a Oscilloscope test videos,noise will be heard:



      Is this sound normal?

    Best regards

    colijevia

  • Hi,

    From the video that you shared it seems that there are some shifts in the signal when the noise happens. Are you able to reproduce the issue with app_pwm on a nRF52 DK or is just on the custom board that has nrf52805? 

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

     This seems to indicate that you are able to reproduce it on another board? Please clarify, and specify if you're able to reproduce on a development kit or not.

    regards

    Jared

  • HI,
    sorry to reply so late,I tried with nrf52832 DK, but the same problem still exists.is there any other way for reference?

    regards
    colijevia

  • Hi,

    We're suspecting that the issue might be due to the difference in accuracy between the internal oscillator HFINT and the crystal oscillator HFXO (used by the softdevice). The PWM will run on HFINT unless the HFXO is explicitly started. 

    Could you try running the external oscillator from the start in main by adding this right after you have initialized the Softdevice?:

        err_code = sd_clock_hfclk_request();
        APP_ERROR_CHECK(err_code);
    
        uint32_t hfclk_is_running = 0;
    
        while (!hfclk_is_running)
        {
            APP_ERROR_CHECK(sd_clock_hfclk_is_running(&hfclk_is_running) );
        }
     

    regards

    Jared

  • Hi,

        I tried,and the isseue is solved,now it  works well,thank you.

    regards,


    colijevia

Related