nrf_gpiote_task_config(0, 16, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW); // Configure PPI channel 0 to toggle PWM_OUTPUT_PIN on every TIMER2 COMPARE[0] match. NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[0]; NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0]; // Enable PPI channel 0. NRF_PPI->CHEN = (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos); // Init TIMER2 for 10kHz PWM NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; // Set the timer in Counter Mode NRF_TIMER2->TASKS_CLEAR = 1; // Clear the tasks first to be usable for later NRF_TIMER2->PRESCALER = 4; // 2^PRESCALER (values authorized 1 to 9) 4 : 16MHz / 16 = 10MHz NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit; //Set counter to 16 bit resolution // Init OC0 PWM NRF_TIMER2->CC[0] = 20UL; NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos); // Enable OC1 interrupt on TIMER2 NVIC_EnableIRQ(TIMER2_IRQn); // Start TIMER2 NRF_TIMER2->TASKS_START = true;