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,

    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

  • Great!! 

    To elaborate a bit more for anyone else that might be seeing this issue:  HFXO is automatically used when you're using the radio. The chip will switch between using HFINT and HFXO based on the power requirement unless the HFXO is manually started. Starting the HFXO manually will always keep it on. The consequences of this is added power consumption. This might not be a significant drawback if you're already using PWM. You could try only enabling HFXO clock when you use PWM and then stop it after you're done using PWM. 

    If you don't use the Softdevice, then you can Start and Stop the HFXO by writing directly to the register:

    Start:

    // Start clock for accurate frequencies
    NRF_CLOCK->TASKS_HFCLKSTART = 1; 
    // Wait for clock to start
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) ;

    Stop:
    NRF_CLOCK->TASK_HFCLKSTOP = 1;
    
    If you use the Softdevice, then you can Start and Stop the HFXO by requesting and releasing the clock:
    Request:
        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) );
        }
    Release:

        err_code = sd_clock_hfclk_release();
        APP_ERROR_CHECK(err_code);
    

    The benefit of using the HFXO with PWM is that you'll get a higher accuracy then with the HFINT. The HFINT is specified as typical +- 1.5% but can be max +- 6%. This can create a significant variation between samples, and when the radio runs on (HFXO) and the PWM (HFINT). 

    You can read more about HFXO and HFINT here.

    regards

    Jared 

Reply
  • Great!! 

    To elaborate a bit more for anyone else that might be seeing this issue:  HFXO is automatically used when you're using the radio. The chip will switch between using HFINT and HFXO based on the power requirement unless the HFXO is manually started. Starting the HFXO manually will always keep it on. The consequences of this is added power consumption. This might not be a significant drawback if you're already using PWM. You could try only enabling HFXO clock when you use PWM and then stop it after you're done using PWM. 

    If you don't use the Softdevice, then you can Start and Stop the HFXO by writing directly to the register:

    Start:

    // Start clock for accurate frequencies
    NRF_CLOCK->TASKS_HFCLKSTART = 1; 
    // Wait for clock to start
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) ;

    Stop:
    NRF_CLOCK->TASK_HFCLKSTOP = 1;
    
    If you use the Softdevice, then you can Start and Stop the HFXO by requesting and releasing the clock:
    Request:
        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) );
        }
    Release:

        err_code = sd_clock_hfclk_release();
        APP_ERROR_CHECK(err_code);
    

    The benefit of using the HFXO with PWM is that you'll get a higher accuracy then with the HFINT. The HFINT is specified as typical +- 1.5% but can be max +- 6%. This can create a significant variation between samples, and when the radio runs on (HFXO) and the PWM (HFINT). 

    You can read more about HFXO and HFINT here.

    regards

    Jared 

Children
No Data
Related