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
  • Hello,

    Thank you for your patience with this.

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

    To clarify this, this means that you must ensure that the pointer you provide actually points to the values for the playback at the time of the playback - for example, if the values only persist through the scope of an 'update_pwm' function, they may be overwritten by the time the playback actually happens, which is not a valid way to operate the PWM peripheral.
    On the other hand, if your playback sequence values are persistent throughout the duration of your PWM peripheral's operation - such as in the case of global variables - it will ensure that the pointer you provide to the PWM peripheral always points to the valid playback sequence values.

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

    No, because this function only update's the PWM's pointer - it does not perform any check to see if the location of the values will persist until the playback occurs.
    The issue arises if you supply a pointer that points to non-persistent playback sequence values. The 'safe window' in this case would therefor be the time in which you can guarantee that the sequence playback values that you have provided the pointer for does not change / are actually stored at the location.

    Please do not hesitate to let me know if any part of this still should be unclear! :) 

    Best regards,
    Karl

Reply
  • Hello,

    Thank you for your patience with this.

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

    To clarify this, this means that you must ensure that the pointer you provide actually points to the values for the playback at the time of the playback - for example, if the values only persist through the scope of an 'update_pwm' function, they may be overwritten by the time the playback actually happens, which is not a valid way to operate the PWM peripheral.
    On the other hand, if your playback sequence values are persistent throughout the duration of your PWM peripheral's operation - such as in the case of global variables - it will ensure that the pointer you provide to the PWM peripheral always points to the valid playback sequence values.

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

    No, because this function only update's the PWM's pointer - it does not perform any check to see if the location of the values will persist until the playback occurs.
    The issue arises if you supply a pointer that points to non-persistent playback sequence values. The 'safe window' in this case would therefor be the time in which you can guarantee that the sequence playback values that you have provided the pointer for does not change / are actually stored at the location.

    Please do not hesitate to let me know if any part of this still should be unclear! :) 

    Best regards,
    Karl

Children
No Data
Related