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

Cross checking the HFCLK against the LFCLK (external SIT1532AC-J5-D14-32.768E – 32.768kHz XO (Standard) NanoDrive Oscillator)

This is a 2 part question concerning the LFCLK input levels as well as how to test the LFCLK frequency against the HFCLK frequency to make sure they are consistent.
In this particular case, the nRF52840 is using the S140 BLE Soft Device and the LFCLK is connected to a SIT1532AC-J5-D14-32.768E – 32.768kHz XO (Standard) NanoDriveTm Oscillator www.digikey.com/.../en. The J5 in the part number indicates it is a 75ppm clock. The D14 indicates it is 1.0V Hi 400mV low intended for direct coupled output. On my board it is connected directly to the P0.00 XL1 pin.
In case it matters, on my board, despite the spec, I measure the swing as being 0.3352V Lo to 0.6947V Hi.
I have set the low-swing xtal option using
NRF_CLOCK->LFCLKSRC = 131073; /* Select xtal source  low swing */ followed by
NRF_CLOCK->TASKS_LFCLKSTART = 1; prior to calling nrf_sdh_enable_request().
The code then does a comparison between the NRF_RTC0->COUNTER, which I believe should track the LFCLK, to the 64MHz DWT->CYCCNT which is based on the board's 32MHz HF xtal.
At first I got what appeared to be relative counts consistent with the LFCLK in RC freerun (on 3 different boards values from 33.0KHz to 32.64KHz. I tried setting the values in sdk_config.h for NRFX_CLOCK_CONFIG_LF_SRC, CLOCK_CONFIG_LF_SRC, and NRF_SDH_CLOCK_LF_SRC to the various indicated possible values. I saw what I would expect to see as the perfect relation between HF and LF clocks when I select option 2 as expected, which instilled some confidence in the measurement of the relative clocks.
If sd_clock_hfclk_request(); is called after the vce_ble_softdevice_request_enable(),  this allows getting an accurate measurement. I imagine the soft device is actively managing the HFCLK and making best effort corrections to the HF counter after it turns it off for periods, but I would appreciate a better understanding of why the LF frequency measurement relative to the HF based DWT->CYCCNT counter can be both higher and lower than the actual frequency.
My specific questions are:
1. What is the best hardware configuration: voltage swing option in combination with capacitive or direct coupling from the SIT1532 mems oscillator and is what I currently have valid for low-swing. Is it the optimal voltage swing option to get?
2. Does the soft device disable the HF automatically at any point if the sync clock is not selected. I ask this since my clock comparison code assumes the 64MHz clock is well behaved. If the 64MHz clock is being stopped, I would expect the measured LFCLK to be higher than it actually is, but this is not always what I see.
3. Is there a way to tell if the configuration is correct, but the LFCLK has not switched to the external clock and is still based on the RC oscillator because it has not detected the external clock? I want to do margin testing and need a clock loss criteria.
4. Is the DWT->CYCCNT expected to track the HFCLK when it is available and/or is it a more complicated combination of several clocks.
5. Final most important question is how you would recommend testing the external LFCLK input in a software only test. The test is needed to assess the health of the system throughout various reliability/environmental tests. Ideally the test could be run at any time without interfering with BLE communications, but a startup only test is possible if an "any time" test is not feasible.
Thanks,
Mitch
Parents
  • Hi Mitch,

     

     

    If sd_clock_hfclk_request(); is called after the vce_ble_softdevice_request_enable(),  this allows getting an accurate measurement.

     If this isn't called, the HFCLK source would normally be the HFINT (RC oscillator), which isn't very accurate (tolerance in the percentage area).

     

    1. What is the best hardware configuration: voltage swing option in combination with capacitive or direct coupling from the SIT1532 mems oscillator and is what I currently have valid for low-swing. Is it the optimal voltage swing option to get?

     If low swing sine, you shall have a DC offset, and the swing should be > 200 mVpp to ensure SNR is high.

    If you provide a rail-to-rail, the requirement is that it goes the VDD_NRF and GND.

    2. Does the soft device disable the HF automatically at any point if the sync clock is not selected. I ask this since my clock comparison code assumes the 64MHz clock is well behaved. If the 64MHz clock is being stopped, I would expect the measured LFCLK to be higher than it actually is, but this is not always what I see.

     If you start the external HFXO, it should not turn it off.

    If you haven't started it, the softdevice will start and stop the HFXO when it needs it (radio operations).

    3. Is there a way to tell if the configuration is correct, but the LFCLK has not switched to the external clock and is still based on the RC oscillator because it has not detected the external clock? I want to do margin testing and need a clock loss criteria.

    The LFCLK does not have a fallback option hardware-wise (you can have one in your application, but there's no implementation of this in our SDK). If you have configured LFXO, it will not start up properly before it actually has clocked input on the XL1/XL2 pins.

    I would recommend that you go into debug mode, and check the NRF_CLOCK->LFCLKSRC register if you are uncertain of the configuration.

     

    4. Is the DWT->CYCCNT expected to track the HFCLK when it is available and/or is it a more complicated combination of several clocks.

     Yes, but: DWT is only active when the debug session is active. It would be better to use a generic 16MHz TIMER peripheral to count this.

    5. Final most important question is how you would recommend testing the external LFCLK input in a software only test. The test is needed to assess the health of the system throughout various reliability/environmental tests. Ideally the test could be run at any time without interfering with BLE communications, but a startup only test is possible if an "any time" test is not feasible.

     If you have a rail-to-rail input, you can connect it to a generic GPIO, and do something like this:

    Configure the GPIO to be used as an GPIOTE IN channel (remember to apply this errata if sampling higher frequencies: https://infocenter.nordicsemi.com/topic/errata_nRF52840_Rev2/ERR/nRF52840/Rev2/latest/anomaly_840_155.html?cp=4_0_1_0_1_10)

    Setup TIMER in counter mode.

    Use PPI to connect the event NRF_GPIOTE->EVENTS_IN[my_ch] to task NRF_TIMER->TASKS_COUNT.

     

    Use a separate NRF_TIMER in capture/compare mode to generate a interrupt on a given time scale to read out the above configured timer using NRF_TIMER->TASKS_CAPTURE[my_ch].

    There's some examples on this on devzone, like this one, which measures the width of a pulse:

    https://devzone.nordicsemi.com/f/nordic-q-a/24805/counting-the-number-of-pulses

    Or this thread:

    https://devzone.nordicsemi.com/f/nordic-q-a/49987/configuring-nrf52840-for-counting-input-frequency-of-upto-5mhz

     

    Kind regards,

    Håkon

Reply
  • Hi Mitch,

     

     

    If sd_clock_hfclk_request(); is called after the vce_ble_softdevice_request_enable(),  this allows getting an accurate measurement.

     If this isn't called, the HFCLK source would normally be the HFINT (RC oscillator), which isn't very accurate (tolerance in the percentage area).

     

    1. What is the best hardware configuration: voltage swing option in combination with capacitive or direct coupling from the SIT1532 mems oscillator and is what I currently have valid for low-swing. Is it the optimal voltage swing option to get?

     If low swing sine, you shall have a DC offset, and the swing should be > 200 mVpp to ensure SNR is high.

    If you provide a rail-to-rail, the requirement is that it goes the VDD_NRF and GND.

    2. Does the soft device disable the HF automatically at any point if the sync clock is not selected. I ask this since my clock comparison code assumes the 64MHz clock is well behaved. If the 64MHz clock is being stopped, I would expect the measured LFCLK to be higher than it actually is, but this is not always what I see.

     If you start the external HFXO, it should not turn it off.

    If you haven't started it, the softdevice will start and stop the HFXO when it needs it (radio operations).

    3. Is there a way to tell if the configuration is correct, but the LFCLK has not switched to the external clock and is still based on the RC oscillator because it has not detected the external clock? I want to do margin testing and need a clock loss criteria.

    The LFCLK does not have a fallback option hardware-wise (you can have one in your application, but there's no implementation of this in our SDK). If you have configured LFXO, it will not start up properly before it actually has clocked input on the XL1/XL2 pins.

    I would recommend that you go into debug mode, and check the NRF_CLOCK->LFCLKSRC register if you are uncertain of the configuration.

     

    4. Is the DWT->CYCCNT expected to track the HFCLK when it is available and/or is it a more complicated combination of several clocks.

     Yes, but: DWT is only active when the debug session is active. It would be better to use a generic 16MHz TIMER peripheral to count this.

    5. Final most important question is how you would recommend testing the external LFCLK input in a software only test. The test is needed to assess the health of the system throughout various reliability/environmental tests. Ideally the test could be run at any time without interfering with BLE communications, but a startup only test is possible if an "any time" test is not feasible.

     If you have a rail-to-rail input, you can connect it to a generic GPIO, and do something like this:

    Configure the GPIO to be used as an GPIOTE IN channel (remember to apply this errata if sampling higher frequencies: https://infocenter.nordicsemi.com/topic/errata_nRF52840_Rev2/ERR/nRF52840/Rev2/latest/anomaly_840_155.html?cp=4_0_1_0_1_10)

    Setup TIMER in counter mode.

    Use PPI to connect the event NRF_GPIOTE->EVENTS_IN[my_ch] to task NRF_TIMER->TASKS_COUNT.

     

    Use a separate NRF_TIMER in capture/compare mode to generate a interrupt on a given time scale to read out the above configured timer using NRF_TIMER->TASKS_CAPTURE[my_ch].

    There's some examples on this on devzone, like this one, which measures the width of a pulse:

    https://devzone.nordicsemi.com/f/nordic-q-a/24805/counting-the-number-of-pulses

    Or this thread:

    https://devzone.nordicsemi.com/f/nordic-q-a/49987/configuring-nrf52840-for-counting-input-frequency-of-upto-5mhz

     

    Kind regards,

    Håkon

Children
No Data
Related