PWM duty-cycle error

Hi, I have a custom board with a nRF52832, and I am using a hardware PWM channel to drive a buzzer.

I am using SDK v17.1.0 and softdevice S132.

Sometimes my board needs to advertise fast and sometimes slowly.

When advertising slowly, everything is good. But when advertising fast, the buzzer sound has audible distortion. This annoys my customer.

According to my measurements, the PWM pulse width (and therefore also the duty cycle) changes randomly between 476us and 483us in the same burst of PWM pulses.

What can I do to get rid of the PWM error?

See my initialization of the PWM below.

Thanks in advance,

Kenneth

uint16_t value = (FREQ_TO_PERIOD_US(tones[tone])) & 0xFFFE; // Make value even to avoid distortion
                                                            // because of uneven duty cycles
nrf_drv_pwm_config_t const config0 =
{
    .output_pins =
    {
        BUZZER_PWM_PIN,             // channel 0
        NRF_DRV_PWM_PIN_NOT_USED,   // channel 1
        NRF_DRV_PWM_PIN_NOT_USED,   // channel 2
        NRF_DRV_PWM_PIN_NOT_USED,   // channel 3    
    },
    .irq_priority = APP_IRQ_PRIORITY_HIGH, //APP_IRQ_PRIORITY_LOW,
    .base_clock   = NRF_PWM_CLK_1MHz,
    .count_mode   = NRF_PWM_MODE_UP,
    .top_value    = value,
    .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
    .step_mode    = NRF_PWM_STEP_AUTO
};
APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));
pwm_values.channel_0 = value / 2;   // 50% duty cycle
static nrf_pwm_sequence_t const buzzer_seq =
{
    .values.p_individual = &pwm_values,
    .length              = NRF_PWM_VALUES_LENGTH(pwm_values),
    .repeats             = 0,
    .end_delay           = 0
};
nrf_drv_pwm_simple_playback(&m_pwm0, &buzzer_seq, 0, NRF_DRV_PWM_FLAG_LOOP);

When the buzzer sound is finished I call

nrf_drv_pwm_uninit(&m_pwm0);
 

Parents Reply Children
No Data
Related