This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF_DRV_PWM_EVT_FINISHED event occurs immediately after PWM started with NRF_DRV_PWM_FLAG_STOP flag

I've been learning to use the PWM.

This should set the PWM up for a period of around 250ms

   NRF_LOG_INFO("Demo 1");

       nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            NRF_DRV_PWM_PIN_NOT_USED, // channel 0
            NRF_DRV_PWM_PIN_NOT_USED, // channel 1
            NRF_DRV_PWM_PIN_NOT_USED, // channel 2
            NRF_DRV_PWM_PIN_NOT_USED  // channel 3
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        //.base_clock   = PWM_PRESCALER_PRESCALER_DIV_1,	//16MHz
	.base_clock   = PWM_PRESCALER_PRESCALER_DIV_128,	// 125kHz
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 32767,	// period
        .load_mode    = NRF_PWM_LOAD_COMMON,
        .step_mode    = NRF_PWM_STEP_TRIGGERED
    };
    APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, demo1_handler));
    m_used |= USED_PWM(0);

    m_demo1_seq_values.channel_0 = 1000;	// alternates between these
    
    m_demo1_seq.length = 1; // numb of alternates

    nrfx_gpiote_out_set(23);	
    (void)nrf_drv_pwm_simple_playback(&m_pwm0, &m_demo1_seq, 1,
                                      NRF_DRV_PWM_FLAG_STOP);

After the period is over I expect to clear pin 23.

static void demo1_handler(nrf_drv_pwm_evt_type_t event_type)
{   
    if (event_type == NRF_DRV_PWM_EVT_FINISHED)
    {
	nrfx_gpiote_out_clear(23);	
	restart = true;
	return;

I find that its cleared immediately i.e. the PWM period thinks its finished straight away.

The reason I'm asking is I would like to use the ISR to restart the PWM period - like a single shot mode.

kind regards

Liam

Parents Reply Children
No Data
Related