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();
Parents
  • In your code you are only using TIMER1. If you want to use two different timers (as you say) to control two PWM signals, the ppi_init() would look something linke this:

    static void ppi_init(void)
    {
    /* Configure PPI channel 0 to toggle PWM_OUTPUT_PIN1 on every Timer 1 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_PIN1 on every Timer 1 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_PIN2 on every Timer 2 COMPARE[0] match. */
    NRF_PPI->CH[2].EEP  = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[0];
    NRF_PPI->CH[2].TEP  = (uint32_t)&NRF_GPIOTE->TASKS_OUT[1];
    	
    /* Configure PPI channel 3 to toggle PWM_OUTPUT_PIN2 on every Timer 2 COMPARE[1] match. */
    NRF_PPI->CH[3].EEP  = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[1];
    NRF_PPI->CH[3].TEP  = (uint32_t)&NRF_GPIOTE->TASKS_OUT[1];
    
    /* Enable only PPI channels 0 - 3. */
    NRF_PPI->CHEN       = (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos) |
    			          (PPI_CHEN_CH1_Enabled << PPI_CHEN_CH1_Pos) |
    				      (PPI_CHEN_CH2_Enabled << PPI_CHEN_CH2_Pos) |
                          (PPI_CHEN_CH3_Enabled << PPI_CHEN_CH3_Pos);
    }
    

    When SoftDevice is enabled you must use sd_nvic_EnableIRQ(). If you would like to use the PWM library with SoftDevice you should check out this project on GitHub: github.com/.../nrf51-pwm-library

  • I have found the reason: ble_stack_init() must finish before sd_ppi_ sd_nvic_ ,and other sd_ function;

Reply Children
No Data
Related