I am working with the PWM driver to drive a stepper motor and I have a couple of doubts about when all the events are generated. My doubts are related to events:
- NRF_PWM_EVENT_SEQEND0 && NRF_PWM_EVENT_SEQEND1
- NRF_PWM_EVENT_LOOPSDONE
- NRF_PWM_EVENT_PWMPERIODEND
As I understand it from the documentation, the event:
- NRF_PWM_EVENT_SEQEND0 && NRF_PWM_EVENT_SEQEND1
Generated when the correspondence SEQUENCE (0 || 1) is finished. At my understanding this is when the `top_count` has been reached the number of times specified in the `repeats` attribute of the sequence plus one. (Assume `end_delay` is 0 for simplicity). - NRF_PWM_EVENT_LOOPSDONE
Generated when both sequences (0 and 1) have being finished the number specified by playback_count. - NRF_PWM_EVENT_PWMPERIODEND
Generated each time top_count is reached.
This is at least what I understand from reading the documentation about the PWM Driver events. Is this correct?
I asked, because I have been setting up a test to count and that is not what I have observe. I have setup a timer in counter mode to count the number of the different pwm events generated, and I obtained weird values. The pwm sequence was defined as:
static uint16_t seq_values[] = {PWM_TOP_COUNT / 2}; // 50% Duty cycle
nrf_pwm_sequence_t const seq =
{
.values.p_common = seq_values,
.length = NRF_PWM_VALUES_LENGTH(seq_values),
.repeats = 0,
.end_delay = 0
};
and the PWM started as:
(void) nrfx_pwm_simple_playback(
&m_pwm0,
&seq,
1,
NRFX_PWM_FLAG_LOOP | NRFX_PWM_FLAG_SIGNAL_END_SEQ0 | NRFX_PWM_FLAG_SIGNAL_END_SEQ1
);with the pwm instance configured in mode NRF_PWM_MODE_UP and in NRF_PWM_LOAD_COMMON.
The results obtained were weird because the amount of events registered of type NRF_PWM_EVENT_SEQEND0 and NRF_PWM_EVENT_SEQEND1 are the double than the events of type NRF_PWM_EVENT_PWMPERIODEND. The number of events of NRF_PWM_EVENT_LOOPSDONE are the same than NRF_PWM_EVENT_PWMPERIODEND which also confuse me, because I wouldn't expect those to be the same according to my assumption on when the event should be generated. The number of events registered by the timer are in order of:
- 4000 for NRF_PWM_EVENT_PWMPERIODEND and NRF_PWM_EVENT_LOOPSDONE.
- 8000 forNRF_PWM_EVENT_SEQEND0 and NRF_PWM_EVENT_SEQEND1.
All the test are made under the same conditions, and the number of pwm pulses generated are the same since the motor moves the gear about the same. So I am a bit confused for when the events are supposed to be generated. By the way I am using SDK 15.
Regards.