accessing the nRF5340 temperature sensor

Hi,

I have a couple of questions regarding reading the nRF5340 Temperature Sensor.

This is a follow-up to the following DevZone ticket:  https://devzone.nordicsemi.com/f/nordic-q-a/120345/sw-got-stuck-during-reading-internal-temp-sensor

 Our app needs to read the die temperature, so based on that ticket, we have to rely on the measurement already requested by MPSL.

1) At what interval is the temperature sensor accessed by the BT Controller and/or MPSL?  The other DevZone ticket mentions 8 seconds.  Is there an exact interval? 

2) Is the interval related to the CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD, CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP, and any other CONFIG?  

3) If so to #2, can we calculate the exact interval? If so, which CONFIG would be best to adjust to, for example, change the interval to 5 seconds?

4) If I'm in DTM mode while in idle state, the die temperature seems to be running at 2.5-3 degrees Celsius higher than in BT mode (in idle state). Is this expected?  This observation was made when using the nRF5340DK, but we see the same difference with our custom HW.

5) Is the following #if macro check correct to conditionalize reading the temperature value directly from the register?

   uint8_t temp;

#if defined(CONFIG_MPSL) && defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION)
   /* we are expecting the MPSL library to read the temperature every x secs */

   temp = nrf_temp_result_get( NRF_TEMP ); /* return value is in increments of 0.25 celsius */
#else
   int count = 0;

   /* start temperature measurement */
   nrf_temp_task_trigger( NRF_TEMP, NRF_TEMP_TASK_START );

   /* wait for the data to be ready */
   while( !nrf_temp_event_check( NRF_TEMP, NRF_TEMP_EVENT_DATARDY ) )
   {
      count++; /* avg counter value when reading the temperature is 140 */

      /* break out of the while loop if counter > 200 so that we don't get stuck */
      if ( count > 200 )
      {
         break;
      }
   }

   temp = nrf_temp_result_get( NRF_TEMP ); /* return value is in increments of 0.25 celsius */

   /* stop the temperature measurement and clear the data ready bit */
   nrf_temp_task_trigger( NRF_TEMP, NRF_TEMP_TASK_STOP );
   nrf_temp_event_clear( NRF_TEMP, NRF_TEMP_EVENT_DATARDY );
#endif

Thanks in advance!

Parents Reply Children
  • Hi ronbo999,

    Thank you for your patience.

    Please find the answers to your questions below:

    1) At what interval is the temperature sensor accessed by the BT Controller and/or MPSL?  The other DevZone ticket mentions 8 seconds.  Is there an exact interval? 

    The temperature is read whenever RC calibration is done (https://github.com/nrfconnect/sdk-nrf/blob/v3.0.2/subsys/mpsl/init/mpsl_init.c#L352) or when sdc_hci_cmd_vs_zephyr_read_chip_temp / mpsl_temperature_getis called.

    2) Is the interval related to the CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD, CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP, and any other CONFIG?  
    3) If so to #2, can we calculate the exact interval? If so, which CONFIG would be best to adjust to, for example, change the interval to 5 seconds?

    The interval is related to this CONFIG_MPSL_CALIBRATION_PERIOD.

    Edit: CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP specifies how often the LFRC calibration can be skipped if the temperature change is too little. Referring to its description, the skip is decided based on temperature, so we can reasonably understand that temperature is read every period, regardless of whether a LFRC calibration is skipped or not.

    4) If I'm in DTM mode while in idle state, the die temperature seems to be running at 2.5-3 degrees Celsius higher than in BT mode (in idle state). Is this expected?  This observation was made when using the nRF5340DK, but we see the same difference with our custom HW.

    Is the DTM sample running with UART? If so, it is also running a TIMER instance alongside UART to wait for commands. That might explain the increased temperature.

    5) Is the following #if macro check correct to conditionalize reading the temperature value directly from the register?

    While MPSL is enabled, it owns the TEMP peripheral and mpsl_temperature_get() (or the equivalent vendor-specific HCI command) must be used to read the temperature.

    If MPSL is not compiled in or not enabled the peripheral can be accessed directly with nrf_temp API. In this case, no macro check is necessary.

    Hieu

  • Hi Hieu,

    These are great answers.

    However, we are using NCS 2.6.4 with the nRF5340. 

    CONFIG_MPSL_CALIBRATION_PERIOD is not in NCS 2.6.4. That config seems to be introduced for the 54L but, with its introduction, is also used for 5340. The commit is here:  github.com/.../dafd26a6d9db313b358e29b310c6e5d7d72dd017.

    1. Would you adjust your reply to these Ronbo's two questions for the case of NCS 2.6.4/nRF5340?

    1) At what interval is the temperature sensor accessed by the BT Controller and/or MPSL?  The other DevZone ticket mentions 8 seconds.  Is there an exact interval? 

    2) Is the interval related to the CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD, CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP, and any other CONFIG?  

    2. Also, with the introduction of CONFIG_MPSL_CALIBRATION_PERIOD, it seems the default period was originally 4 seconds in the initial commit but was later changed to 60 seconds. But for our case, if we were to use the latest NCS with that CONFIG,  it seems the default period would still be based on CLOCK_CONTROL_NRF_CALIBRATION_PERIOD and perhaps multiplied by CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP.

  • Hi variant,

    variant said:

    1. Would you adjust your reply to these Ronbo's two questions for the case of NCS 2.6.4/nRF5340?

    1) At what interval is the temperature sensor accessed by the BT Controller and/or MPSL?  The other DevZone ticket mentions 8 seconds.  Is there an exact interval? 

    2) Is the interval related to the CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD, CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP, and any other CONFIG?  

    In NCS v2.6.4, the interval is related to CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD.

    Refer to: https://github.com/nrfconnect/sdk-nrf/blob/v2.6.4/subsys/mpsl/init/mpsl_init.c#L320-L323

    You are right that it is also related to CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP, and that is true for both 2.6.4 and 3.0.2. I will have to update my previous answer. My apologies.
    Calibration skipping is based on temperature, and the maximum number of consecutive skips are configured by this. This is detailed in its description.

    Edit: I forgot that the focus of this question is temperature accuracy, not LFRC. You can see that CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP specifies how often the LFRC calibration can be skipped. Referring to its description, the skip is decided based on temperature, so we can reasonably understand that temperature is read every period, regardless of whether a LFRC calibration is skipped or not.

    variant said:
    2. Also, with the introduction of CONFIG_MPSL_CALIBRATION_PERIOD, it seems the default period was originally 4 seconds in the initial commit but was later changed to 60 seconds. But for our case, if we were to use the latest NCS with that CONFIG,  it seems the default period would still be based on CLOCK_CONTROL_NRF_CALIBRATION_PERIOD and perhaps multiplied by CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP.

    It seems that our developers found that a period of 4 seconds was too excessive when LFXO is used. Refer to the commit message here: https://github.com/nrfconnect/sdk-nrf/commit/67750a2e378c04a9845515941bea04541812d22f.

    The period itself is only controlled by CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD or CONFIG_MPSL_CALIBRATION_PERIOD. Whether a skip happen or not depends on the temperature change.

    However, if you expect the skip to consistently happen due to the specifics of your product, then it might be fair to do multiply with (CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP + 1) for the true period.

    Edit: I address whether CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP should be calculated above.

    Does this answer your concern with this item #2?

  • Hi Hieu,

    All of your responses are again very clear. You have answered all of my questions.  Thank you!

    Also, we have verified that we see MPSL update the temperature every CONFIG_MPSL_CALIBRATION_PERIOD.  The default in our case is CONFIG_MPSL_CALIBRATION_PERIOD=4 seconds.  

      You can set this ticket as answered.

Related