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

Current consumption when using rtc, ppi and gpiote

Hi Sir/Madam

I wrote a small program for low current verification on nrf51822 development kit with starter mother board. The program is based on "blinky_example" project configuration. It is doing gpio pin 24 toggling by using rtc, ppi and gpiote modules. However, the voltage reading from connector K2 is about 120mV or 1200uA at P7 even the CPU is called "__WFI" and unplugged the Jlink. From my understanding, CPU can operate below 5uA when it is sleep. Or ppi module is already used 1mA? Or something wrong on the code. Thanks a lot.



#define LFCLK_FREQUENCY          (32768UL)             /*!< LFCLK frequency in Hertz, constant */
#define RTC_FREQUENCY             (8UL)                     /*!< required RTC working clock RTC_FREQUENCY Hertz. Changable */
#define COMPARE_COUNTERTIME       (1UL)            /*!< Get Compare event COMPARE_TIME seconds after the counter starts from 0 */

#define COUNTER_PRESCALER         ((LFCLK_FREQUENCY/RTC_FREQUENCY) - 1)  /* f = LFCLK/(prescaler + 1) */


void ppi_init(void)
{
	// Configure PPI channel 0 to start ADC task	
	NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_TICK;	
	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);
}

static void rtc_config(void)
{
	NRF_RTC0->PRESCALER = COUNTER_PRESCALER;                   // Set prescaler to a TICK of RTC_FREQUENCY
	
	// Enable TICK event and TICK interrupt:
	NRF_RTC0->EVTENSET = RTC_EVTENSET_TICK_Msk;
}

static void lfclk_config(void)
{
	NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
	NRF_CLOCK->TASKS_LFCLKSTART = 1;
	while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
	{
	}
	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
}

/**
 * main() function
 * @return 0. int return type required by ANSI/ISO standard.
 */
int main(void)
{
	nrf_gpio_cfg_output(24);
	lfclk_config();
	rtc_config();

	ppi_init();
       
        // Configure the GPIOTE Task to toggle the LED state.
    nrf_gpiote_task_config(0,                         
						   24,
                           NRF_GPIOTE_POLARITY_TOGGLE,						   
                           NRF_GPIOTE_INITIAL_VALUE_LOW);

	
	NRF_RTC0->TASKS_START = 1;
	
    // Enter main loop
    for ( ; ; )
    {		
		__WFI();
	}	
}

Parents Reply Children
No Data
Related