I am using a nRF52832 and v14.2 of the Nordic SDK.
I have a question about the PWM Driver. I have the pwm driver working and driving an LED, but it is unclear to me how to properly update the sequence. I have scanned the forum, and the answers I found did not resolve the issue I am seeing. I also saw functions like nrf_drv_pwm_sequence_update
, but the issue I'm seeing still occurred.
I am only using 1 channel and for the normal mode of operation, I just need the pwm to drive at a set duty cycle, so this is how it is set up:
nrf_drv_pwm_config_t const config0 =
{
.output_pins =
{
BSP_LED_PWM_PIN | NRF_DRV_PWM_PIN_INVERTED,
NRF_DRV_PWM_PIN_NOT_USED,
NRF_DRV_PWM_PIN_NOT_USED,
NRF_DRV_PWM_PIN_NOT_USED
},
.irq_priority = APP_IRQ_PRIORITY_LOW,
.base_clock = NRF_PWM_CLK_4MHz,
.count_mode = NRF_PWM_MODE_UP,
.top_value = PWM_TOPVALUE,
.load_mode = NRF_PWM_LOAD_COMMON,
.step_mode = NRF_PWM_STEP_AUTO
};
static nrf_pwm_values_common_t pwm_singleSequenceValue[] = { 0 }; // Size of 1
nrf_pwm_sequence_t const seq =
{
.values.p_common = pwm_singleSequenceValue,
.length = NRF_PWM_VALUES_LENGTH(pwm_singleSequenceValue),
.repeats = 100,
.end_delay = 0
};
nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 2, NRF_DRV_PWM_FLAG_LOOP);
I then at another time call this from a function:
static uint16_t warning1Values1[] = { ... }; // assume 23 initial values
static flashSequence_t warning1Sequence2 = {
.values = warning1Values1,
.length = (sizeof(warning1Values1) / sizeof (uint16_t)),
.stepTimeMS = 32,
.endDelayMS = 10000
};
nrf_pwm_sequence_t const sequence1 =
{
.values.p_common = warning1Sequence2.values,
.length = warning1Sequence2.length,
.repeats = pwm_convertMSToSteps(warning1Sequence2.stepTimeMS),
.end_delay = pwm_convertMSToSteps(warning1Sequence2.endDelayMS)
};
nrf_drv_pwm_simple_playback(&m_pwm0, &sequence1, 2, NRF_DRV_PWM_FLAG_LOOP);
What I am experiencing is that when I do the above, is that the sequence only plays once, does the endDelay, then loops back and then it plays the sequence twice (correctly). The very first time never plays it twice.
Let me know if I need to elaborate. Some of the code above is my code, but most of it is standard from the reference examples.
Thank you,
amorgan