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

How to use app_pwm module?

Is there any example for how to use app_pwm module?

I want to control the LED effect, Thanks!

Parents
  • I'm using the nrf_pwm driver if you want to use that. Code ripped out of its context and with very basic usage but you get the idea...

    #include "nrfx_pwm.h"
    
    static nrf_pwm_values_common_t seq_values[] = {0};
    nrf_pwm_sequence_t const seq =
    {
        .values.p_common     = seq_values,
        .length              = NRF_PWM_VALUES_LENGTH(seq_values),
        .repeats             = 0,
        .end_delay           = 0
    };
    
    static nrfx_pwm_config_t const config_pwm =
    {                                                                             \
        .output_pins  = {LED_PIN,                                                \
                         NRFX_PWM_PIN_NOT_USED,                                   \
                         NRFX_PWM_PIN_NOT_USED,                                   \
                         NRFX_PWM_PIN_NOT_USED },                                 \
        .irq_priority = PWM_DEFAULT_CONFIG_IRQ_PRIORITY,                          \
        .base_clock   = (nrf_pwm_clk_t)PWM_DEFAULT_CONFIG_BASE_CLOCK,             \
        .count_mode   = (nrf_pwm_mode_t)PWM_DEFAULT_CONFIG_COUNT_MODE,            \
        .top_value    = PWM_DEFAULT_CONFIG_TOP_VALUE,                             \
        .load_mode    = (nrf_pwm_dec_load_t)PWM_DEFAULT_CONFIG_LOAD_MODE,         \
        .step_mode    = (nrf_pwm_dec_step_t)PWM_DEFAULT_CONFIG_STEP_MODE,         \
    };
    
    static nrfx_pwm_t m_pwm0 = NRFX_PWM_INSTANCE(0);
    
    main{}
    {
        APP_ERROR_CHECK(nrfx_pwm_init(&m_pwm0, &config_pwm, NULL));
        seq_values[0] = 10*(100-duty_cycle);
        nrfx_pwm_simple_playback(&m_pwm0, &seq, 1, NRFX_PWM_FLAG_LOOP);
    }

    Regards

    //Ola

Reply
  • I'm using the nrf_pwm driver if you want to use that. Code ripped out of its context and with very basic usage but you get the idea...

    #include "nrfx_pwm.h"
    
    static nrf_pwm_values_common_t seq_values[] = {0};
    nrf_pwm_sequence_t const seq =
    {
        .values.p_common     = seq_values,
        .length              = NRF_PWM_VALUES_LENGTH(seq_values),
        .repeats             = 0,
        .end_delay           = 0
    };
    
    static nrfx_pwm_config_t const config_pwm =
    {                                                                             \
        .output_pins  = {LED_PIN,                                                \
                         NRFX_PWM_PIN_NOT_USED,                                   \
                         NRFX_PWM_PIN_NOT_USED,                                   \
                         NRFX_PWM_PIN_NOT_USED },                                 \
        .irq_priority = PWM_DEFAULT_CONFIG_IRQ_PRIORITY,                          \
        .base_clock   = (nrf_pwm_clk_t)PWM_DEFAULT_CONFIG_BASE_CLOCK,             \
        .count_mode   = (nrf_pwm_mode_t)PWM_DEFAULT_CONFIG_COUNT_MODE,            \
        .top_value    = PWM_DEFAULT_CONFIG_TOP_VALUE,                             \
        .load_mode    = (nrf_pwm_dec_load_t)PWM_DEFAULT_CONFIG_LOAD_MODE,         \
        .step_mode    = (nrf_pwm_dec_step_t)PWM_DEFAULT_CONFIG_STEP_MODE,         \
    };
    
    static nrfx_pwm_t m_pwm0 = NRFX_PWM_INSTANCE(0);
    
    main{}
    {
        APP_ERROR_CHECK(nrfx_pwm_init(&m_pwm0, &config_pwm, NULL));
        seq_values[0] = 10*(100-duty_cycle);
        nrfx_pwm_simple_playback(&m_pwm0, &seq, 1, NRFX_PWM_FLAG_LOOP);
    }

    Regards

    //Ola

Children
Related