Simple PWM example

Hi,

Is it possible to have a simple example of using PWM with the Zephyr?

With nRF5_SDK_17.1.0 I did this:

void Pwm1Init(void)
{
    ret_code_t err_code;

    nrf_pwm_sequence_t const    m_seq =
    {
        .values.p_individual = &pwm1Values,
        .length              = NRF_PWM_VALUES_LENGTH(pwm1Values),
        .repeats             = 0,
        .end_delay           = 0
    };

    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            BUZZER_PIN | NRF_DRV_PWM_PIN_INVERTED,
	    LED_R | NRF_DRV_PWM_PIN_INVERTED,
	    LED_G | NRF_DRV_PWM_PIN_INVERTED,
	    LED_B | NRF_DRV_PWM_PIN_INVERTED,
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_250kHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 62,                      // PWM period 4032Hz, 62 -> Duty Cycle = 100%.
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
        .step_mode    = NRF_PWM_STEP_AUTO
    };

    err_code = nrf_drv_pwm_init(&m_pwm1, &config0, NULL);
    APP_ERROR_CHECK(err_code);

    pwm1Values.channel_0 = 0x8000;
    pwm1Values.channel_1 = 0x8000;
    pwm1Values.channel_2 = 0x8000;
    pwm1Values.channel_3 = 0x8000;

    nrf_drv_pwm_simple_playback(&m_pwm1, &m_seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}

void Pwm1SetDutyCycle(uint8_t channel, uint16_t value)
{
    ((uint16_t *)(&pwm1Values))[channel] = (value | 0x8000);
}

I used the Pwm1SetDutyCycle function to set the Duty cycle of the 4 channels.
Now what do I do with the Zephyr? Can anyone give me an example? The examples I found didn't help me.

Thank you.

Related