Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Safely updating duty cycle values during playback

The NRF documentation for nrf_pwm_sequence_t says:

When the sequence is set (by a call to nrf_pwm_sequence_set), the provided duty cycle values are not copied. The values pointer is stored in the internal register of the peripheral, and the values are loaded from RAM during the sequence playback. Therefore, you must ensure that the values do not change before and during the sequence playback (for example, the values cannot be placed in a local variable that is allocated on stack).

But the NRFX function nrfx_pwm_sequence_values_update is defined as

a Function for updating the pointer to the duty cycle values in the specified sequence during playback.

Does this mean that the user can update duty cycles using this function at any time, without worrying about a safe window?

Parents
  • Thanks for the update. What I am not clear on, is at what point it becomes unsafe to change the values.... So. If I have an external trigger ( for example, an ADC read), that provides values for the PWM duty cycle, and when it completes, I want to update the PWM duty cycles. I know that the NRFX_PWM_EVT_END_SEQ0 or NRFX_PWM_EVT_END_SEQ1  Indicates that it is safe to update the values, but I'm not clear what event I should subscribe to that indicates that it is unsafe. nrfx_pwm_evt_type_t  only contains 

    Enumerator
    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.

    And NRFX_PWM_EVT_FINISHED  appears to occur at the same time as NRFX_PWM_EVT_END_SEQ0/1. 

    Is the only way to do this using NRFX, to cache the new values until that NRFX_PWM_EVT_END_SEQ0/1 occurs, and then update then? 

     

    I notice that NRF has a more compete set of events:

    Enumerator
    NRF_PWM_EVENT_STOPPED 

    Response to STOP task, emitted when PWM pulses are no longer generated.

    NRF_PWM_EVENT_SEQSTARTED0 

    First PWM period started on sequence 0.

    NRF_PWM_EVENT_SEQSTARTED1 

    First PWM period started on sequence 1.

    NRF_PWM_EVENT_SEQEND0 

    Emitted at the end of every sequence 0 when its last value has been read from RAM.

    NRF_PWM_EVENT_SEQEND1 

    Emitted at the end of every sequence 1 when its last value has been read from RAM.

    NRF_PWM_EVENT_PWMPERIODEND 

    Emitted at the end of each PWM period.

    NRF_PWM_EVENT_LOOPSDONE 

    Concatenated sequences have been played the requested number of times.

    I presume that the safe window is defined as between SEQSTARTED and SEQEND? But these events are not available in NRFX?

    Is there a reason why some of these events are not exposed at the NRFX layer?

  • Hello again, 

    Andy Gould said:
    Thanks for the update.

    No problem at all, I am happy to help!

    Andy Gould said:
    Is the only way to do this using NRFX, to cache the new values until that NRFX_PWM_EVT_END_SEQ0/1 occurs, and then update then? 

    Yes, this is how you should do this, update the sequence as part of the END_SEQ event handling. The NRFX_PWM_EVT_FINISHED event will only be generated once a sequence playback has completed the specified number of times - generated when the LOOPSDONE event has been generated - while the SEQEND events are generated for each sequence end.

    Andy Gould said:
    I presume that the safe window is defined as between SEQSTARTED and SEQEND?

    No, that would be the unsafe window - the values should not be changed between SEQSTARTED and SEQEND, instead it should be between SEQEND and SEQSTARTED.

    Andy Gould said:

    But these events are not available in NRFX?

    Is there a reason why some of these events are not exposed at the NRFX layer?

    These events are not exposed to the application layer, no - they are used by the driver directly, and then the driver will forward relevant NRFX events to the application layer event handler based on these. These 

    Best regards,
    Karl

Reply
  • Hello again, 

    Andy Gould said:
    Thanks for the update.

    No problem at all, I am happy to help!

    Andy Gould said:
    Is the only way to do this using NRFX, to cache the new values until that NRFX_PWM_EVT_END_SEQ0/1 occurs, and then update then? 

    Yes, this is how you should do this, update the sequence as part of the END_SEQ event handling. The NRFX_PWM_EVT_FINISHED event will only be generated once a sequence playback has completed the specified number of times - generated when the LOOPSDONE event has been generated - while the SEQEND events are generated for each sequence end.

    Andy Gould said:
    I presume that the safe window is defined as between SEQSTARTED and SEQEND?

    No, that would be the unsafe window - the values should not be changed between SEQSTARTED and SEQEND, instead it should be between SEQEND and SEQSTARTED.

    Andy Gould said:

    But these events are not available in NRFX?

    Is there a reason why some of these events are not exposed at the NRFX layer?

    These events are not exposed to the application layer, no - they are used by the driver directly, and then the driver will forward relevant NRFX events to the application layer event handler based on these. These 

    Best regards,
    Karl

Children
No Data
Related