Hi,
I am developing an application which needs a precise reference clock of 20ms. I have a 32MHz Xtal on the PCB with a tolerance of +-10ppm. To configure the device to use the XTAL i have created a kconfig as follows:
config APP_ENABLE_HFXO bool "Use HFXO as HFCLK source" help Turn on the high-frequency clock, which means switching to the crystal as a source rather than the internal oscillator.
I then added a line in prj.conf 'CONFIG_APP_ENABLE_HFXO=y'
I think i found this in another example but cannot remember exactly where. When I run the code in debug it the HFCLKSTAT has the src as the Xtal so I assume the main clock is now running from the Xtal - is this correct? Are there any other steps needed to configure the Xtal.
I have then configured a timer using the nrfx libraries to toggle a pin using the PPI in compare mode with a period of 20ms. I am using 16MHz as my timer frequency and a count of 320,000. The timer is reset using a shortcut when the compare happens.
The issue I am having is that the output square wave is not stable. Its period varies by up to 0.1ms per pulse which seems quite high. Should the accuracy of the pulse be related directly to the crystal tolerance (10ppm) and should it be stable?