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

consumption Timer2+PPI

I use the Timer2 and the PPI for toggle a GPIO to control the frequency of 16Mhz Quartz is correct. But when I stop the function I have a permanent consumption of ~ 6 mA, even when the product works by Bluetooth.

The only way to remove the consumption of the product is reset.

Do you have an alternative solution?

this is test functions

void Start_Quartz_UC(void)
{

 // Use 16MHz from external crystal
 // This could be customized for RC/Xtal, or even to use a 32 kHz crystal


  NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
  NRF_CLOCK->TASKS_HFCLKSTART    = 1;

while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
{
		// Do nothing while waiting for the clock to start
}

NRF_TIMER2->MODE        = TIMER_MODE_MODE_Timer;
NRF_TIMER2->PRESCALER   = 0;

// Load initial values to Timer 2 CC registers
// Set initial CC0 value to anything > 1
NRF_TIMER2->CC[0]       = UC_VALEUR_OFF;
NRF_TIMER2->CC[1]       = UC_VALEUR_PERIODE;
NRF_TIMER2->CC[2]       = UC_VALEUR_OFF;

// Set up interrupt for CC2
// This interrupt is to force the change of CC0 to happen when it is safe.
// A safe time is after the highest possible CC0 value, but before the lowest one.

NRF_TIMER2->INTENSET    = TIMER_INTENSET_COMPARE2_Enabled << TIMER_INTENSET_COMPARE2_Pos;

// Create an Event-Task shortcut to clear TIMER2 on COMPARE[1] event.
NRF_TIMER2->SHORTS      = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);

// Configure GPIOTE channel 0 to toggle the PWM pin state.
// Note that we can only connect one GPIOTE task to one output pin.
nrf_gpiote_task_config(0, HORLOGE_OUTPUT, NRF_GPIOTE_POLARITY_TOGGLE, \
NRF_GPIOTE_INITIAL_VALUE_LOW);

// Configure PPI channel 0 to toggle PWM_OUTPUT_PIN on every Timer 2 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];

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

// Enable only PPI channels 0 and 1. */
NRF_PPI->CHEN       = (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos) |
(PPI_CHEN_CH1_Enabled << PPI_CHEN_CH1_Pos);
NRF_TIMER2->TASKS_START    = 1;                    // Start timer.
}


 void Stop_Quartz_UC(void)
 {
    NRF_TIMER2->EVENTS_COMPARE[0]  = 0;
   NRF_TIMER2->EVENTS_COMPARE[1]  = 0;
   NRF_TIMER2->EVENTS_COMPARE[2]  = 0;
   NRF_TIMER2->TASKS_STOP         = 1;  // Stop timer.
   nrf_gpiote_unconfig 	( 0	); 		//Evite une conso permanente de 1mA.
   NVIC_DisableIRQ(TIMER2_IRQn);
   NVIC_DisableIRQ(TIMER1_IRQn);

   NRF_CLOCK->TASKS_HFCLKSTOP     = 1;
  }

Best Regard,

Charly

Related