nrfx pwm PERIODEND Event missing

The nrfx pwm supports a number of events for a callback:

/** @brief PWM driver event type. */
typedef enum
{
NRFX_PWM_EVT_FINISHED, ///< Sequence playback finished.
NRFX_PWM_EVT_END_SEQ0, /**< End of sequence 0 reached. Its data can be
safely modified now. */
NRFX_PWM_EVT_END_SEQ1, /**< End of sequence 1 reached. Its data can be
safely modified now. */
NRFX_PWM_EVT_STOPPED, ///< The PWM peripheral has been stopped.
} nrfx_pwm_evt_type_t;

The underlying peripheral seems to support other events including EVENTS_PWMPERIODEND

/** @brief PWM events. */
typedef enum
{
    NRF_PWM_EVENT_STOPPED      = offsetof(NRF_PWM_Type, EVENTS_STOPPED),       ///< Response to STOP task, emitted when PWM pulses are no longer generated.
    NRF_PWM_EVENT_SEQSTARTED0  = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[0]), ///< First PWM period started on sequence 0.
    NRF_PWM_EVENT_SEQSTARTED1  = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[1]), ///< First PWM period started on sequence 1.
    NRF_PWM_EVENT_SEQEND0      = offsetof(NRF_PWM_Type, EVENTS_SEQEND[0]),     ///< Emitted at the end of every sequence 0 when its last value has been read from RAM.
    NRF_PWM_EVENT_SEQEND1      = offsetof(NRF_PWM_Type, EVENTS_SEQEND[1]),     ///< Emitted at the end of every sequence 1 when its last value has been read from RAM.
    NRF_PWM_EVENT_PWMPERIODEND = offsetof(NRF_PWM_Type, EVENTS_PWMPERIODEND),  ///< Emitted at the end of each PWM period.
    NRF_PWM_EVENT_LOOPSDONE    = offsetof(NRF_PWM_Type, EVENTS_LOOPSDONE)      ///< Concatenated sequences have been played the specified number of times.
} nrf_pwm_event_t;
I can get EVENTS_PWMPERIODEND to trigger a GPIOTE but I wanted an ISR
Is there a supported way to get EVENTS_PWMPERIODEND to trigger an ISR? 
I'm in SDK2.7.0 on nrf52840
Parents
  • Hello,

    I guess you would need to use the nrfx_pwm api directly (instead of the zephyr pwm or pwm_nrfx api).

    There is possible starting example here:
    https://github.com/too1/ncs-nrfx-pwm-simple-example/blob/master/src/main.c  

    I expect you need to add the pwm callback to the nrfx_pwm_init, e.g.:

    irq_enable(PWM1_IRQn);

    nrfx_pwm_init(&my_pwm, &config0, pwm_isr_handler, NULL);

    ISR_DIRECT_DECLARE(pwm_isr_handler)
    {
        nrfx_pwm_irq_handler();
        ISR_DIRECT_PM(); 
    }
    void nrfx_pwm_irq_handler() {
    ...
        if (nrf_pwm_event_check(NRF_PWM1, NRF_PWM_EVENT_PWMPERIODEND)) {
            nrf_pwm_event_clear(NRF_PWM1, NRF_PWM_EVENT_PWMPERIODEND);
            ...
        }
    }

    Not tested, but something like that,
    Kenneth

Reply
  • Hello,

    I guess you would need to use the nrfx_pwm api directly (instead of the zephyr pwm or pwm_nrfx api).

    There is possible starting example here:
    https://github.com/too1/ncs-nrfx-pwm-simple-example/blob/master/src/main.c  

    I expect you need to add the pwm callback to the nrfx_pwm_init, e.g.:

    irq_enable(PWM1_IRQn);

    nrfx_pwm_init(&my_pwm, &config0, pwm_isr_handler, NULL);

    ISR_DIRECT_DECLARE(pwm_isr_handler)
    {
        nrfx_pwm_irq_handler();
        ISR_DIRECT_PM(); 
    }
    void nrfx_pwm_irq_handler() {
    ...
        if (nrf_pwm_event_check(NRF_PWM1, NRF_PWM_EVENT_PWMPERIODEND)) {
            nrf_pwm_event_clear(NRF_PWM1, NRF_PWM_EVENT_PWMPERIODEND);
            ...
        }
    }

    Not tested, but something like that,
    Kenneth

Children
No Data
Related