How to control each channel of hardware PWM individually?

 Hi  

      Thank you for your attention to my question, I would like to inquire how to control each channel of hardware PWM individually, We have 6 LED lights, each LED has different application scenarios, at some point I only want to control one of them, 

      I see from the example that nrfx_pwm_simple_playback this interface can be used to enable PWM, but how to enable only one of the channels

  • Hi,

    Have you seen Demo 3 in the PWM driver example? It would show you how to only use one channel:

    static void demo3(void)
    {
        NRF_LOG_INFO("Demo 3");
    
        /*
         * This demo uses only one channel, which is reflected on LED 1.
         * The LED blinks three times (200 ms on, 200 ms off), then it stays off
         * for one second.
         * This scheme is performed three times before the peripheral is stopped.
         */
    
        nrf_drv_pwm_config_t const config0 =
        {
            .output_pins =
            {
                BSP_LED_0 | NRF_DRV_PWM_PIN_INVERTED, // 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_LOWEST,
            .base_clock   = NRF_PWM_CLK_125kHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 25000,
            .load_mode    = NRF_PWM_LOAD_COMMON,
            .step_mode    = NRF_PWM_STEP_AUTO
        };
        APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));
        m_used |= USED_PWM(0);
    
        // This array cannot be allocated on stack (hence "static") and it must
        // be in RAM (hence no "const", though its content is not changed).
        static uint16_t /*const*/ seq_values[] =
        {
            0x8000,
                 0,
            0x8000,
                 0,
            0x8000,
                 0
        };
        nrf_pwm_sequence_t const seq =
        {
            .values.p_common = seq_values,
            .length          = NRF_PWM_VALUES_LENGTH(seq_values),
            .repeats         = 0,
            .end_delay       = 4
        };
    
        (void)nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 3, NRF_DRV_PWM_FLAG_STOP);
    }
    

    regards

    Jared

Related