<?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>Would calculation affect timer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28154/would-calculation-affect-timer</link><description>I am using a power profiler to measure the timing of my program and I found something wrong. So I tested with a simple pure timer. 
 So first I set the timer during to 300ms 
 #define half_epoch_during APP_TIMER_TICKS(300)
err_code = app_timer_create</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 17 Dec 2017 20:51:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28154/would-calculation-affect-timer" /><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111197?ContentTypeID=1</link><pubDate>Sun, 17 Dec 2017 20:51:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68d36787-90ab-4317-b76b-1cf742ac2237</guid><dc:creator>mich_x</dc:creator><description>&lt;p&gt;Thank you all very much for all the help and patience. Turns out, the reason is that I did not wait for some time after I turned off the trigger window. I found that it takes about 10 seconds for the plot actually take effect after I click stop on the trigger window. And after I turned off and waited this time, everything is fine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111198?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2017 09:59:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2c72749-6d58-4640-aa3e-b680994e6eb2</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;One more thing; as is explained &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.tools/dita/tools/power_profiler_kit/PPK_user_guide_Plots_options.html"&gt;here&lt;/a&gt;, it is advised to turn off the Trigger window in the PPK software when looking at timings. After I did that I saw the timer interrupt spikes occurring at exactly 300ms intervals.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111196?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2017 09:49:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6171259-0068-4b07-98e5-3255c417322e</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I have tested with PCA10056 running the app_ble_template example and S140 v5.0.0-2.alpha and I&amp;#39;m still not able to reproduce this. With a logic analyzer I can still see that the interrupt triggers at 300ms intervals. With the PPK though, I do see some variations in the order of 10-20ms. However, I talked to the PPK HW guy, and he told me that this is to be expected because the time axis in the PPK software is not that accurate. Especially if you are running the software on Windows 10.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111195?ContentTypeID=1</link><pubDate>Tue, 12 Dec 2017 18:35:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bfb1c6b-685a-472e-84b2-b26e88f0ddb8</guid><dc:creator>mich_x</dc:creator><description>&lt;p&gt;No, I have not got time to work on this. Did you add Softdevice when you run the test? I think I have to run the test on top of the S14.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111194?ContentTypeID=1</link><pubDate>Tue, 12 Dec 2017 09:41:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f63aafa-6ca5-4045-b3ee-b7cd0ee559cb</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi @mich_x. Did you solve the issue? If not, can you post a screenshot of your current measurements? I did a quick test with a logic analyzer and the timer handler seems to be called at ~300ms with or without your calculations inside it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111193?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 19:43:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a4d0be0-128f-4ff2-8397-d19391ae2587</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;Or so you don&amp;#39;t have to interface to the device, just have it toggle a gpio and then you can measure the rate with an o-scope.
I would assume you will see some jitter in the basic timing since the ble stack has highest interrupt priority but the basic rate should still be 300msec.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111192?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 19:28:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d366a24-25ed-41af-981d-36d94696b3ff</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;You are correct.  You are defining the tick rate.&lt;/p&gt;
&lt;p&gt;On the for loop, I think it is minimum 6million opcodes since you force it to write i to d. Or about 93 msec to execute.&lt;/p&gt;
&lt;p&gt;It is an interesting problem. Still I would probably choose to let it keep track of time and see if it does that correctly while running the for loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111191?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 18:53:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99c913ab-da53-498c-b608-2859a7c09d00</guid><dc:creator>mich_x</dc:creator><description>&lt;p&gt;No, my timer interrupts every 300 ms&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111190?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 18:52:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:847fe6b5-e766-4453-b578-43d8642f7ccd</guid><dc:creator>mich_x</dc:creator><description>&lt;p&gt;Yes. The problem is I am not even sure which timing is right. Is the power profiler somehow compress the X axis. Or Something running on the board would make the timer wrong.&lt;/p&gt;
&lt;p&gt;The truth is my job was using BLE stack to scan periodically. So I set a timer to start the scan every time. So the callback function is just invoking the scan_start() function which is not a lot of opcodes. But the compression of time shows the same pattern as a FOR loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111189?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 18:46:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2eea7011-f362-43ca-a972-d749cc578d28</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;Oh, and I forgot to mention since the app timer interrupts every msec that means that since your count takes about 6/64 of a second or at the very least 3/64 of a second that means your for loop will be interrupted and shoved to the stack at least 46 times just so the app timer can run and service its ISR.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111188?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 18:42:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:510946d3-2ce4-4dd6-b96e-90cc11cdfeee</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;But this brings us back to why is it shorter???  hmmm.&lt;/p&gt;
&lt;p&gt;Why not just have the thing keep time while it runs the for loop stuff and see if it still can keep time?
I would guess something is just weird the way the power profiler is looking at the data.  Maybe it is looking at the dwell time instead of the on time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Would calculation affect timer</title><link>https://devzone.nordicsemi.com/thread/111187?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 18:39:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40638899-c4bc-4d5a-8cb4-3f76c5ceb04c</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;Without digging into this a lot, just looking at the fact that the app timer interrupts every 1msec means that there is quite a bit of code running already. I assume the timer handler probably reloads the timer, updates some local variables, etc.&lt;/p&gt;
&lt;p&gt;Then you have your for loop running.  Every time that kicks in the processor has to create the local variable, load it with 3 million, then theoretically it could do the count directly in the processor registers but I would guess it actually involves a few opcodes to carry out the task. I would guess this total thing could involve 6million or more opcodes (ie, instructions) to complete.&lt;/p&gt;
&lt;p&gt;And, then both of these are ISR&amp;#39;s so every time the processor shoves its registers to the stack, updates the pc, etc. etc.  Anyway the point is a processor that carries out 64mips is really working when you ask it to carry out several million instructions in 300msec.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>