nRF52832 custom board plus some devices. Using SDK 15
I want to count pulses from a previously configured accelerometer. Pulses are slow, around 500 per minute.
I have a working implementation using ppi, pin SENSE and a timer in counter mode.
ret_code_t err_code; if(!nrfx_gpiote_is_init()){ err_code = nrfx_gpiote_init(); APP_ERROR_CHECK(err_code); } nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG; timer_cfg.mode = NRF_TIMER_MODE_COUNTER; nrfx_timer_init(&m_timer, &timer_cfg, timer_dummy_handler); nrfx_gpiote_in_config_t i_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(false); i_config.pull = NRF_GPIO_PIN_PULLUP; nrfx_gpiote_in_init(INT1, &i_config, NULL); nrf_gpio_cfg_sense_input(INT1, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_HIGH); nrfx_gpiote_in_event_enable(INT1, true); err_code = nrf_drv_ppi_init(); if(err_code != NRF_ERROR_MODULE_ALREADY_INITIALIZED){ APP_ERROR_CHECK(err_code); } nrf_ppi_channel_t ppi_channel; nrfx_ppi_channel_alloc(&ppi_channel); nrfx_ppi_channel_assign(ppi_channel, nrfx_gpiote_in_event_addr_get(INT1), nrfx_timer_task_address_get(&m_timer, NRF_TIMER_TASK_COUNT)); nrfx_ppi_channel_enable(ppi_channel); nrfx_timer_enable(&m_timer);
However, I think my approach is wrong and using a timer as a counter is not the most power efficient way.
Comparing used power with same board running eddystone beacon example from SDK (green) as reference, this program running (red trace) yields absurd power use.
My program draws more than 1mA average vs 54uA average. :( !!!
My questions:
-Using TIMER burns so much power? Is HF clock always ON when using TIMERS? Even as a counter with ppi as clock?
-Whats the most efficient way to do this? Time interval does not need to be very precise, this is not working as a frequencymeter
-I read about using the DETECT signal which is shared between GPIOS and is the lowest power burning interrupt source from GPIO. Is that true?
Thanks a lot!!