This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PWM PPI timer_handler

Hi,everyone I want to make out 4 channel PWM with PPI and two timers , PPI configuration like this,

/* Configure PPI channel 0 to toggle PWM_OUTPUT_PIN on every Timer 2 COMPARE[0] match. */
NRF_PPI->CH[0].EEP  = (uint32_t)&NRF_TIMER1->EVENTS_COMPARE[0];
NRF_PPI->CH[0].TEP  = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];
/* Configure PPI channel 1 to toggle PWM_OUTPUT_PIN on every Timer 2 COMPARE[1] match. */
NRF_PPI->CH[1].EEP  = (uint32_t)&NRF_TIMER1->EVENTS_COMPARE[1];
NRF_PPI->CH[1].TEP  = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];

    /* Configure PPI channel 2 to toggle PWM_OUTPUT_PIN on every Timer 2 COMPARE[0] match. */
NRF_PPI->CH[2].EEP  = (uint32_t)&NRF_TIMER1->EVENTS_COMPARE[0];
NRF_PPI->CH[2].TEP  = (uint32_t)&NRF_GPIOTE->TASKS_OUT[1];
/* Configure PPI channel 3 to toggle PWM_OUTPUT_PIN on every Timer 2 COMPARE[2] match. */
NRF_PPI->CH[3].EEP  = (uint32_t)&NRF_TIMER1->EVENTS_COMPARE[2];
NRF_PPI->CH[3].TEP  = (uint32_t)&NRF_GPIOTE->TASKS_OUT[1];

is this right?

another queston is when I use sd_nvic_EnableIRQ , timer_handler function can not be called, but when I use NVIC_EnableIRQ, the EK board's blue tooth function stop working;

here is the code:

      sd_nvic_SetPriority(TIMER1_IRQn,3);
  sd_nvic_SetPriority(TIMER2_IRQn,3);

// Enable interrupt on Timer
//NVIC_EnableIRQ(TIMER1_IRQn);
//NVIC_EnableIRQ(TIMER2_IRQn);

  sd_nvic_EnableIRQ(TIMER1_IRQn);
  sd_nvic_EnableIRQ(TIMER2_IRQn);
     __enable_irq();
  • and timer_handler

      void TIMER1_IRQHandler(void)
      {
        NRF_TIMER1->TASKS_STOP = 1;
        NRF_TIMER1->TASKS_CLEAR= 1;
        // Clear interrupt.
        if ((NRF_TIMER1->EVENTS_COMPARE[3] == 1) && 
        (NRF_TIMER1->INTENSET & TIMER_INTENSET_COMPARE3_Msk))
        {
         NRF_TIMER1->EVENTS_COMPARE[3] = 0;
        }	
        NRF_TIMER1->EVENTS_COMPARE[0] = NRF_TIMER1->EVENTS_COMPARE[1] = 0 ;
         NRF_TIMER->EVENTS_COMPARE[2] = NRF_TIMER1->EVENTS_COMPARE[3] = 0;
           nrf_gpiote_unconfig(0);
           nrf_gpiote_unconfig(1);
           nrf_gpio_pin_clear(PWM_OUTPUT_PIN_NUMBER0);
           nrf_gpio_pin_clear(PWM_OUTPUT_PIN_NUMBER1);
           nrf_gpiote_task_config(0, PWM_OUTPUT_PIN_NUMBER0, NRF_GPIOTE_POLARITY_TOGGLE, \
           NRF_GPIOTE_INITIAL_VALUE_LOW);
           nrf_gpiote_task_config(1, PWM_OUTPUT_PIN_NUMBER1, NRF_GPIOTE_POLARITY_TOGGLE, \
           NRF_GPIOTE_INITIAL_VALUE_HIGH);
           pwm_chanel_set1();		//reset the timer with new value
           NRF_TIMER1->TASKS_START = 1;
         }
    
  • I have found the reason: ble_stack_init() must finish before sd_ppi_ sd_nvic_ ,and other sd_ function;

  • Yes, that is true! I'm glad you found the reason. Sorry I couldn't be of more help. Is it okay that I close the question since it's been resolved?

Related