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

Which HF clock will be chosen by BLE stack?

Hi, In my code, I have not started the HF clock. I call the ble_stack_init where "SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);" is called. Which HF clock will be chosen at what PPM by the micro if I don't deliberately start the HF clock like this:

	NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;

	NRF_CLOCK->TASKS_HFCLKSTART = 1;


     while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
Parents Reply Children
  • Hi Stian, Thanks for the reply. The problem I am having is - with the same firmware on different nRF51822xxAA hardware (I use S130 SD v10.0.0), when I start the softdevice (without me purposely starting the HF Xtal clock- meaning, the softdevice would start the HF Xtal clock automatically), I get different results timing wise on the different nRF51s. Timing wise, I mean, I display the number of seconds elapsed via the nRF control app (previously known as the master control panel). After around 30 minutes, there is a difference of upto 22 seconds between two different nRF51 - running the same firmware. Both nRF51s connected to the same phone model (Nexus 5 Android version: 6.0.1). WIll this be because, softdevice negotiates and uses different PPM while it starts the HF Xtal clock at different nRF51 hardwares?

  • How do you measure the time? Are you using the RTC on the nRF and transmit the timestamp over BLE? Are you using a library for this or did you write your own code? In general, if a counter is running without the HF clock enabled, this must be based on the RTC (and the LF clock) and this is not very accurate.

  • Hi Stian, Thanks for the reply. I need to generate pulses as low as 30usec(on time = 30usec and off time = 70 usec) width in my project. I calculate 1 second = 10000 cycles (1 cycle = 30usec on and 70usec off). I use gpiote+ppi to output the pulses. I have used driver apis (not directly register write) for all the functions used. Since they all use softdevice for the driver, I thought the HF Xtal clock started by softdevice would be used for all those driver functions.

  • For 30µs the HFINT should be good enough (internal HF clock, not the crystal). Remember that the app_timer library for instance uses the LFCLK (RTC peripheral) which is only at 32kHz. You should use the TIMER peripheral which is using the HFCLK. The timer starts the HFINT automatically, and there's no need to start the crystal. Just let the SD start the crystal by itself when it needs it, and the TIMER can run on the HFINT without conflicting.

Related