<?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>timer accuracy</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59390/timer-accuracy</link><description>Hi, 
 I am using 
 
 nRF52840 
 SDK 15.3.0 
 Keil IDE 
 The soft device is S140 
 JLinkRTTViewer for debug 
 
 I am using app_timer to control the LED On time. 
 the app_timer works correctly without SD event. 
 However, when an SD event (e.g disconnect</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 25 Mar 2020 08:21:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59390/timer-accuracy" /><item><title>RE: timer accuracy</title><link>https://devzone.nordicsemi.com/thread/241518?ContentTypeID=1</link><pubDate>Wed, 25 Mar 2020 08:21:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32909e86-3a0e-440c-83d0-9b34890edcde</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;a small addition, in this example, Timer&lt;strong&gt;0&lt;/strong&gt; is used, which takes the&amp;nbsp;&lt;strong&gt;SD&lt;/strong&gt; to fit your needs. therefore, to work simultaneously with SD s140, you need to use another free timer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer accuracy</title><link>https://devzone.nordicsemi.com/thread/241515?ContentTypeID=1</link><pubDate>Wed, 25 Mar 2020 08:17:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8419dfc-f158-4d0e-8939-9248dc455f66</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;Hi, Alex&lt;/p&gt;
&lt;p&gt;when working with a chip, I do not use the functions of working with peripherals from Nordic. That is, I use direct work with registers for certain reasons.&lt;br /&gt;I do not have a ready code for working with a regular LED, but, in principle, this code will cause the output to be inverted every second.&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define LED_PIN     15
#define LED_PORT    1
#define LED_GPIOTE  4
#define LED_PPI_CH  10


// pin p1.15 (port 1 pin 15) as output without pull
NRF_P1-&amp;gt;PIN_CNF[LED_PIN] = ((GPIO_PIN_CNF_SENSE_Disabled   &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos ) 
                            |(GPIO_PIN_CNF_DRIVE_S0S1       &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos ) 
                            |(GPIO_PIN_CNF_PULL_Disabled    &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos  ) 
                            |(GPIO_PIN_CNF_INPUT_Disconnect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos ) 
                            |(GPIO_PIN_CNF_DIR_Output       &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos   ));

// gpiote configuration
NRF_GPIOTE-&amp;gt;CONFIG[LED_GPIOTE] = (GPIOTE_CONFIG_MODE_Task	&amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos)
                               | (LED_PIN )				&amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos)
                               | (LED_PORT)				&amp;lt;&amp;lt; GPIOTE_CONFIG_PORT_Pos);

// Timer 4 for example
NRF_TIMER4-&amp;gt;MODE       = TIMER_MODE_MODE_Timer&amp;lt;&amp;lt;TIMER_MODE_MODE_Pos;
NRF_TIMER4-&amp;gt;BITMODE    = TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos;
NRF_TIMER4-&amp;gt;PRESCALER  = 0x09;
NRF_TIMER4-&amp;gt;CC[0]      = 31250/2; // 500 ms
NRF_TIMER4-&amp;gt;SHORTS     = TIMER_SHORTS_COMPARE0_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE0_CLEAR_Pos;

// Connect timer event to gpio toggle task
NRF_PPI-&amp;gt;CH[LED_PPI_CH].EEP = (uint32_t)&amp;amp;NRF_TIMER4-&amp;gt;EVENTS_COMPARE[0];
NRF_PPI-&amp;gt;CH[LED_PPI_CH].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[LED_GPIOTE];

// Run PPI channel
NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; LED_PPI_CH;
// Run timer
NRF_TIMER4-&amp;gt;TASKS_START = 1;&lt;/pre&gt;This is not the most beautiful and neat solution, but as a starting point it will go.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&amp;nbsp;This code is placed in the main.c after after all functions ending in init:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ble_stack_init();&lt;br /&gt; gap_params_init();&lt;br /&gt; gatt_init();&lt;br /&gt; services_init();&lt;br /&gt; advertising_init();&lt;br /&gt; conn_params_init();&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;From the documentation, I use only the Product Specification(aka datasheet). Accordingly, sections for studying this: PPI, TIMER, GPIO, GPIOTE.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There is some text, but it needs to be understood. Without this, it will be difficult to use this chip at full power.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P.S. maybe someone will add an example with standard functions?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Good luck&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer accuracy</title><link>https://devzone.nordicsemi.com/thread/241514?ContentTypeID=1</link><pubDate>Wed, 25 Mar 2020 08:15:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15ac68eb-6046-406e-bcda-651da3ad7b53</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Check out the&amp;nbsp;&lt;a title="GPIOTE Example" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/nrf_gpiote_example.html"&gt;GPIOTE Example&lt;/a&gt;&amp;nbsp;in the SDK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer accuracy</title><link>https://devzone.nordicsemi.com/thread/241497?ContentTypeID=1</link><pubDate>Wed, 25 Mar 2020 04:40:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:423cc479-b3b0-45b3-a840-5e2b093edaab</guid><dc:creator>alex kim</dc:creator><description>&lt;p&gt;Hi, CheMax&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I want to have an exact timer that can be used in a program regardless of the sd event.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Another hardware timer with PPI for GPIOTE control.&amp;nbsp;Yes, it is resource-intensive, but in this case you will not have problems managing the LED flashing. It will happen automatically without the participation of code and the kernel.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;=&amp;gt;&amp;nbsp;I ask you for an example program or an additional explanation (documentation)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer accuracy</title><link>https://devzone.nordicsemi.com/thread/241051?ContentTypeID=1</link><pubDate>Mon, 23 Mar 2020 09:26:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:077b0b8c-e654-4a66-99b9-844ae5a39e92</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;[quote userid="69031" url="~/f/nordic-q-a/59390/timer-accuracy"][/quote]&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Why does this happen?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; Is it because app_timer priority is lower than SD event?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; Yes. App timer it&amp;#39;s software timers based on one hardware timer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;[quote userid="69031" url="~/f/nordic-q-a/59390/timer-accuracy"][/quote]&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Question 2&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; Which timer should be used to be less affected by SD events?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; Another hardware timer with PPI for GPIOTE control.&amp;nbsp;Yes, it is resource-intensive, but in this case you will not have problems managing the LED flashing. It will happen automatically without the participation of code and the kernel.&lt;/p&gt;
&lt;p&gt;Or for example, you can use the PWM module. At least 2 flashing modes can be arranged on it. But you need to spend a little time studying the documentation.&lt;/p&gt;
&lt;p&gt;Good luck&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>