<?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>How to increase the number every certain time?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67044/how-to-increase-the-number-every-certain-time</link><description>Hello all, 
 I have a question about nRF52832. 
 
 What I want to do is increase a number every 20 micro seconds. 
 In other words, count how much time has passed . 
 (ex. int count = 0; every 20 microseconds, count++;) 
 
 If I use delay function, I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Oct 2020 08:33:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67044/how-to-increase-the-number-every-certain-time" /><item><title>RE: How to increase the number every certain time?</title><link>https://devzone.nordicsemi.com/thread/274511?ContentTypeID=1</link><pubDate>Tue, 13 Oct 2020 08:33:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5311199-d29b-4458-a390-c60663043e7a</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user=""]&lt;p&gt;What I want to do is increase a number every 20 micro seconds.&lt;/p&gt;
&lt;p&gt;In other words, count how much time has passed .&lt;/p&gt;
&lt;p&gt;(ex. int count = 0; every 20 microseconds, count++;)&lt;/p&gt;[/quote]
&lt;p&gt;What you are describing sounds a lot like a general TIMER application - I highly recommend taking a look at &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/nrf_dev_timer_example.html"&gt;the timer peripheral example from the SDK&lt;/a&gt;, which demonstrates how you may go about setting up and using the timer driver. You could also see &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__timer.html"&gt;the nrfx_timer API Reference documented here&lt;/a&gt;. While the example uses the legacy nrf_drv_timer, I highly recommend that you make use of the nrfx_timer driver instead. If you compare the two, you will see that most functions have an updated version in the nrfx_ driver, which can be used in the same manner as the legacy version.&lt;br /&gt;&lt;br /&gt;To modify the timer example to do exactly what you describe above, all you need to do is change the time_ms to 2 ms ( or use the&amp;nbsp;&lt;em&gt;nrfx_timer_us_to_ticks&amp;nbsp;&lt;/em&gt;function ), and change the contents of the timer event handler (&amp;nbsp;&lt;em&gt;timer_led_event_handler&amp;nbsp;&lt;/em&gt;) to instead increment a variable.&lt;br /&gt;If you make such changes, I must recommend that you also change all function and variable names to something appropriate for their modified usage / functionality.&lt;/p&gt;
[quote user=""]&lt;p&gt;If I use delay function, I can do it.&lt;/p&gt;
&lt;p&gt;But, I want that process while other programs are ongoing, without pause.&lt;/p&gt;[/quote]
&lt;p&gt;Great! This is definitely a better way to go about it, since using a delay is&amp;nbsp;&lt;em&gt;&lt;/em&gt;&lt;span style="font-size:12px;"&gt;&lt;i&gt;seldom&lt;/i&gt;&lt;/span&gt; the best option for these kinds of operations.&lt;br /&gt;A timer is a much better way to go about it, since it is more accurate, while at the same time freeing the CPU to perform other tasks ( or sleep! ) in the meantime.&lt;/p&gt;
[quote user=""]Thanks so much and have a nice day![/quote]
&lt;p&gt;Thank you, and I hope you have a nice day as well!&lt;br /&gt;&lt;br /&gt;Please do not hesitate to ask if anything should be unclear, or if you should encounter any issues or questions in the future.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>