Dear Nordic Developer Zone,
Is there a way to set the LFCLK (32kHz) on a GPIO for precision measurement?
Best regards
Dear Nordic Developer Zone,
Is there a way to set the LFCLK (32kHz) on a GPIO for precision measurement?
Best regards
Hi Sebastien,
yes, you can connect the LFCLK to a GPIO using the RTC and GPIOTE:
For example: RTC tick event can be configured to trigger a GPIOTE task which toggles a pin. See code example below which starts up the internal 32 kHz RC and configures RTC Tick event to toggle gpio 0:
// Start 32 kHz clock
NRF_CLOCK->TASKS_LFCLKSTART = 1;
// Configure GPIOTE to toggle gpio 0
NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) |
(GPIOTE_CONFIG_OUTINIT_Low << GPIOTE_CONFIG_OUTINIT_Pos) |
(GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos) |
(0 << GPIOTE_CONFIG_PSEL_Pos);
// Configure RTC1 to generate tick event
NRF_RTC1->PRESCALER = 0;
NRF_RTC1->EVTENSET = RTC_EVTENSET_TICK_Msk;
// Connect RTC1 tick event to GPIOTE toggle task
NRF_PPI->CH[0].EEP = (uint32_t) &NRF_RTC1->EVENTS_TICK;
NRF_PPI->CH[0].TEP = (uint32_t) &NRF_GPIOTE->TASKS_OUT[0];
NRF_PPI->CHEN = PPI_CHENCLR_CH0_Msk;
// Start RTC1
NRF_RTC1->TASKS_START = 1;
while(1)
{
}
The pulse width of the signal measured on gpio 0 corresponds to LFCLK frequency (1 / 32768 seconds).
Note that the internal RC needs to be calibrated (using calibration task NRF_CLOCK->TASKS_CAL) to achieve 250 ppm accuracy. External 16 MHz crystal should be running during calibration for best results.
Thanks for your answer.
i think you get only half of the LFCLK here on GPIO. 1 TICK is one toggle on GPIO which converts to two RTC ticks converting to one cycle on GPIO.
I'm measuring only 16.67KHz using the above code! :(
Hello - is this method also applicable to the nRF52840?