<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Questions about the temperature sensor (TEMP)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113828/questions-about-the-temperature-sensor-temp</link><description>Hi. 
 I am experimenting with an internal temperature sensor (TEMP) on an nRF52810 microcontroller and have some questions: 
 1. How to select a crystal oscillator as a source of HFCLK to achieve better temperature sensor performance? 
 2. How to measure</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 12 Aug 2024 13:56:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113828/questions-about-the-temperature-sensor-temp" /><item><title>RE: Questions about the temperature sensor (TEMP)</title><link>https://devzone.nordicsemi.com/thread/497849?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2024 13:56:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb696cf3-e1cc-4816-a418-d1589644c438</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about the temperature sensor (TEMP)</title><link>https://devzone.nordicsemi.com/thread/497843?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2024 13:34:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6752b262-53b4-4c30-9189-4b6360012a12</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Either use clock_control module (recommended approach, as other modules might also request HFCLK):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.5.0/samples/cellular/at_client/src/main.c#L16-L24"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.5.0/samples/cellular/at_client/src/main.c#L16-L24&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Or, you can directly start it via the registers:&lt;/p&gt;
&lt;p&gt;NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;&lt;/p&gt;
&lt;p&gt;while(NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);&lt;/p&gt;
&lt;p&gt;&lt;span&gt;NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;H&amp;aring;kon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about the temperature sensor (TEMP)</title><link>https://devzone.nordicsemi.com/thread/497840?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2024 13:30:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7d223c6-1353-4026-bd2c-b578e5ea109e</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi H&amp;aring;kon.&amp;nbsp;Thank you for your reply.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yeah, your advice worked. When I include &amp;quot;nrf.h&amp;quot; I get the temperature calculation in 35 ns.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could you please answer my first question. How can I select an external generator as HFCLK and be sure that the temperature measurement performance will improve?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about the temperature sensor (TEMP)</title><link>https://devzone.nordicsemi.com/thread/497745?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2024 08:24:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18b528c4-5457-4172-afe8-458080f7357e</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You are not clearing your events, and it seems that you&amp;#39;re also not dereferencing TEMP_EVENTS_DATARDY. The data types are returned as 64 bit length, so you need to print as &amp;quot;%lld&amp;quot; types.&lt;/p&gt;
&lt;p&gt;I would recommend that you rather include &amp;quot;nrf.h&amp;quot; and access the temp directly (or include nrf_temp.h and use that API):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/zephyr.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/timing/timing.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;

int main(void)
{
	int32_t tmp;
	timing_t start_time, end_time;
	uint64_t total_cycles;
	uint64_t total_ns;
	timing_init();
	while (1) {
		timing_start();
		NRF_TEMP-&amp;gt;TASKS_START = 1;
		start_time = timing_counter_get();
		while (NRF_TEMP-&amp;gt;EVENTS_DATARDY == 0) {}
		end_time = timing_counter_get();
		timing_stop();		
		NRF_TEMP-&amp;gt;EVENTS_DATARDY = 0;
		printk(&amp;quot;Temperature measurement time = %lld ns\n&amp;quot;, timing_cycles_to_ns(timing_cycles_get(&amp;amp;start_time, &amp;amp;end_time)));
		tmp = (int32_t)NRF_TEMP-&amp;gt;TEMP / 4;
		printk(&amp;quot;SoC temperature = %d\n&amp;quot;, tmp);
		NRF_TEMP-&amp;gt;TASKS_STOP = 1;
		k_msleep(5000);
	}
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This will print approx. 35 us:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Temperature measurement time = 35437 ns&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about the temperature sensor (TEMP)</title><link>https://devzone.nordicsemi.com/thread/497701?ContentTypeID=1</link><pubDate>Sun, 11 Aug 2024 13:41:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0911378-f501-4f2e-b6da-bf659395536e</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;I tried to use the &lt;a href="https://docs.zephyrproject.org/latest/kernel/timing_functions/index.html"&gt;Executing Time Functions&lt;/a&gt; from Zephyr to measure time (in nanoseconds), but I think the result of the measurement is wrong.&lt;/p&gt;
&lt;p&gt;My program code --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;...
#include &amp;lt;zephyr/timing/timing.h&amp;gt;
...

/* TEMP */
#define TEMP_BASE           (0x4000C000U)
#define TEMP_TASKS_START    (TEMP_BASE + 0x000U)
#define TEMP_TASKS_STOP     (TEMP_BASE + 0x004U)
#define TEMP_EVENTS_DATARDY (TEMP_BASE + 0x100U)
#define TEMP_TEMP           (TEMP_BASE + 0x508U)

int main(void)
{ 	
	int32_t tmp;
	timing_t start_time, end_time;
	uint64_t total_cycles;
    uint64_t total_ns;

	timing_init();
	
	while (1) {
	
		timing_start();
		*(uint32_t *)TEMP_TASKS_START = 1;
		
		start_time = timing_counter_get();
		while (TEMP_EVENTS_DATARDY == 0) {
        	// need to wait for the event, an empty loop won&amp;#39;t work
  	    }
		end_time = timing_counter_get();

    	total_cycles = timing_cycles_get(&amp;amp;start_time, &amp;amp;end_time);
    	total_ns = timing_cycles_to_ns(total_cycles);

		timing_stop();
		LOG_INF(&amp;quot;Temperature measurement time = %d ns&amp;quot;, total_ns);
		
		tmp = *(int32_t *)TEMP_TEMP / 4;
		LOG_INF(&amp;quot;SoC temperature = %d\n&amp;quot;, tmp);
		
		k_msleep(5000);
	}
	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Terminal output --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/0576.time.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see the function returns 1125 nanoseconds (1.125 microseconds), although the documentation says that the temperature calculation time is about 36 microseconds.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/temp-time.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Can you please tell me where I&amp;#39;m making a mistake?&lt;br /&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>