PWM single pulse generation

Hi there,

I'm trying to create a single pulse from PWM instance. Using SDK5 SDK, I could create only even number of pulses with a nrf_pwm_simple_playback().  When  playback_count = 1 or 2, I get two pulses. playback_count = 3, 4 I get four pulses. 5,6 I get 6 pulses so. 

from nrfx_pwm.c:

288 nrf_pwm_sequence_set(p_instance->p_registers, 0, p_sequence);
289 nrf_pwm_sequence_set(p_instance->p_registers, 1, p_sequence);
290 bool odd = (playback_count & 1);
291 nrf_pwm_loop_set(p_instance->p_registers,
292 (playback_count / 2) + (odd ? 1 : 0));

Is it okay just to create one pulse?

Then I tried to do directly via HAL, but couldn't get PWM to stop after SEQEND0 finishes:

#define first_pin PWM_PIN_A
#define second_pin PWM_PIN_B
#define PWM_CH0_DUTY 5
#define PWM_CH1_DUTY 5
#define PWM_CH2_DUTY 5
#define PWM_CH3_DUTY 5
uint16_t pwm_seq[4] = {PWM_CH0_DUTY, PWM_CH1_DUTY, PWM_CH2_DUTY, PWM_CH3_DUTY};

void demo8(void)
{
// 5us active cycle
NRF_PWM0->PSEL.OUT[0] = (first_pin << PWM_PSEL_OUT_PIN_Pos) | (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos);
NRF_PWM0->PSEL.OUT[1] = (second_pin << PWM_PSEL_OUT_PIN_Pos) | (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos);

NRF_PWM0->PSEL.OUT[2] = 0xFF;
NRF_PWM0->PSEL.OUT[3] = 0xFF;

NRF_PWM0->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);

//count up
NRF_PWM0->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos);


//1MHZ
NRF_PWM0->PRESCALER = (PWM_PRESCALER_PRESCALER_DIV_16 << PWM_PRESCALER_PRESCALER_Pos);

//stop after 15us
NRF_PWM0->COUNTERTOP = (15 << PWM_COUNTERTOP_COUNTERTOP_Pos);

// no loop
NRF_PWM0->LOOP = (PWM_LOOP_CNT_Disabled << PWM_LOOP_CNT_Pos);
NRF_PWM0->DECODER = (PWM_DECODER_LOAD_Individual << PWM_DECODER_LOAD_Pos) | (PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos);

// RAM address of this sequence
NRF_PWM0->SEQ[0].PTR = ((uint32_t)(pwm_seq) << PWM_SEQ_PTR_PTR_Pos);
// number of sequences. Each sequence is a 16-bit.
NRF_PWM0->SEQ[0].CNT = ((sizeof(pwm_seq) / sizeof(uint16_t)) << PWM_SEQ_CNT_CNT_Pos);


NRF_PWM0->SEQ[0].REFRESH = 0;

NRF_PWM0->SEQ[0].ENDDELAY = 0;
/* NRF_PWM0->SHORTS = PWM_SHORTS_SEQEND0_STOP_Enabled << PWM_SHORTS_SEQEND0_STOP_Pos ; */
/* delay(100); */
NRF_PWM0->TASKS_SEQSTART[0] = 1;
}

Is there a way that I could use PWM to create just one single pulse for each time I call TASKS_SEQSTART[0]? Thanks.

Related