Dear nordicsemi,
In our application, we need obtain the number of input edges,but we always get a incorrected result in a long-time testing situation (2-3 hours), and this phenomenon is random. We realized this application with GPIOTE, PPI,Timer( Counter mode). The detailed processes are,
1.GPIOTE. Initialization with event mode, GPIOTE Channel 7, Pin 23,NRF_GPIOTE_POLARITY_LOTOHI.
Code:
nrf_gpiote_event_configure(7,23, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpiote_event_enable(7);
2.PPI. Using PPI Channel 2 to trigger the timer counter counting 1. NOTE: the task of triggering a timer counter is assigned to fork endpoint. NOTE:SECOND_COUNTER is the problem timer counter we concerned.
Code:
nrf_ppi_channel_and_fork_endpoint_setup( PPI_Channnel_2, (uint32_t)nrf_gpiote_event_addr_get(NRF_GPIOTE_EVENTS_IN_7), (uint32_t)&PWN_COUNTER->TASKS_CLEAR, (uint32_t)&SECOND_COUNTER->TASKS_COUNT);// nrf_ppi_channel_enable(PPI_Channnel_2);
3.EGU. Using a EGU channel to check whether the count is right or not, and emplyed a PPI channel (PPI Channel 16). The PPI capture the counter of SECOND_COUNTER, meanwhile trigger the EDU channel entering a callback function.
Code:
nrf_ppi_channel_and_fork_endpoint_setup( NRF_PPI_CHANNEL16, (uint32_t)nrf_gpiote_event_addr_get(NRF_GPIOTE_EVENTS_IN_7), (uint32_t)&SECOND_COUNTER->TASKS_CAPTURE[1], (uint32_t)&NRF_EGU0->TASKS_TRIGGER[0]); nrf_ppi_channel_enable(NRF_PPI_CHANNEL16); NVIC_SetPriority(SWI0_EGU0_IRQn, 7); NVIC_EnableIRQ(SWI0_EGU0_IRQn); nrf_egu_int_enable(NRF_EGU0,EGU_INTENSET_TRIGGERED0_Msk);
4.EGU Callback Function. This callback function is called via NRF_GPIOTE_EVENTS_IN_7. In this function, we compare the current count of the SECOND_COUNTER with the last count. If both count has a difference of 2, we print the error info using the RTT.
Code:
uint32_t second_old=0; void SWI0_EGU0_IRQHandler(void) { if (nrf_egu_event_check(NRF_EGU0, NRF_EGU_EVENT_TRIGGERED0)) { nrf_egu_event_clear(NRF_EGU0, NRF_EGU_EVENT_TRIGGERED0); if(SECOND_COUNTER->CC[1]-second_old>1) { SEGGER_RTT_printf(0,"\r\n**SECOND_COUNTER->CC[1]:%d\r\n",SECOND_COUNTER->CC[1]); SEGGER_RTT_printf(0,"**second_old:%d\r\n",second_old); } second_old=SECOND_COUNTER->CC[1]; } }
5. We can get error information from RTT Viewer.
0> **SECOND_COUNTER->CC[1]:11986
0> **second_old:11984
We can learn that the the timer counter counted an additional edge. And this may happened internal, because the EGU callback function was not been called.
Beside, we alse recorded the waveform of Pin 23 ( the input of NRF_GPIOTE_EVENTS_IN_7).
In this picture, the yellow line is the input signal, it shows with Persistence Mode.
We also search " PPI Channel 2" in the whole project files, the results shows that it only been used here, the searching scope includes nrf_soc.h. And we also emplyed these codes:
// err_code = sd_power_mode_set(NRF_POWER_MODE_CONSTLAT);
// APP_ERROR_CHECK(err_code);
The problem still existed.
NOTE: This application must running after the BLE Connection.
What should we do next? Thank you so much.