<?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>Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9662/question-about-strange-behavior-of-timer0</link><description>I want to use timer0 to get exact time delay (without soft device used). 
 Timer0 configuration is as 
 void timer0_initialization(void)
{
 NRF_TIMER0-&amp;gt;MODE = TIMER_MODE_MODE_Timer;
 NRF_TIMER0-&amp;gt;PRESCALER = 0;
 NRF_TIMER0-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit;</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 12 Oct 2015 08:02:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9662/question-about-strange-behavior-of-timer0" /><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35702?ContentTypeID=1</link><pubDate>Mon, 12 Oct 2015 08:02:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12b94ddb-d2f9-41c9-96b3-d4eeab0875b2</guid><dc:creator>JiachengWang</dc:creator><description>&lt;p&gt;Hi, Aryan,&lt;/p&gt;
&lt;p&gt;The first value of RTC0-&amp;gt;COUNTER  save in time_capture[0] is just used to record the initial time of waiting  for the first event, and second value saved in  time_capture[1] (in for loop, start form i=1) to record the time of the first event and the starting time for waiting second event, and .......&lt;/p&gt;
&lt;p&gt;The value captured from RTC0 has no difference of unconditional/conditional, just record the time. The time used for waiting the first event is (time_capture[1] - time_capture[0]), and second event time is  (time_capture[2] - time_capture[1]). The output code is&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for (i=1; i&amp;lt;10; i++)
{
    printf(&amp;quot;---- i = %ld, timer counter = %ld\r\n&amp;quot;, i, time_capture[i] - time_capture[i - 1]); 
    nrf_delay_ms(100);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;for NRF_TIMER0-&amp;gt;CC[0] = 16 * 1000, I get the output as
----------------------------------------------------------------
---- i = 1, timer counter = 34
---- i = 2, timer counter = 34
---- i = 3, timer counter = 34
---- i = 4, timer counter = 34
---- i = 5, timer counter = 34
---- i = 6, timer counter = 34
---- i = 7, timer counter = 34
---- i = 8, timer counter = 34
---- i = 9, timer counter = 34&lt;/p&gt;
&lt;p&gt;Thanks a lot,&lt;/p&gt;
&lt;p&gt;Jiacheng&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35701?ContentTypeID=1</link><pubDate>Mon, 12 Oct 2015 07:33:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb56c409-a406-431c-9eb8-0c05a6c1f2ac</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;i did not get it : (
now you are capturing the first RTC-&amp;gt;COUNTER value unconditionally and still it gives you same value like others which are captured condictionally??? monday morning may be .. but i don&amp;#39;t get it :(&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35700?ContentTypeID=1</link><pubDate>Mon, 12 Oct 2015 05:32:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0781cf91-0063-4c6e-9c1d-e52a88a3e330</guid><dc:creator>JiachengWang</dc:creator><description>&lt;p&gt;There is a bug in my previous code.&lt;/p&gt;
&lt;p&gt;Inside the for loop, the EVENTS_COMPARE register is cleared after the event. For  MDK, since all avriable is initialized with 0, each event has the same timer number. but for GCC, the initial value is a random number (I use GCC), so the first event has a different timer number.&lt;/p&gt;
&lt;p&gt;The correct code should be like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;time_capture[0] = NRF_RTC0-&amp;gt;COUNTER;
NRF_TIMER0-&amp;gt;TASKS_CLEAR = 1;
for (i=1; i&amp;lt;10; i++)
{
    NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0;
    (void)NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0];
    while (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] == 0)
    {
    }  
    time_capture[i] = NRF_RTC0-&amp;gt;COUNTER;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This code will give the same timer number for each event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35699?ContentTypeID=1</link><pubDate>Mon, 12 Oct 2015 02:41:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9322017f-82a6-4147-8d19-b6adac70b23d</guid><dc:creator>JiachengWang</dc:creator><description>&lt;p&gt;sorry, it&amp;#39;s my mistake, in timer capture loop, &amp;quot;i&amp;#39; should be started from 0, as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for (i=0; i&amp;lt;10; i++)
{
    while (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] == 0)
    {
    }  
				NRF_TIMER0-&amp;gt;TASKS_CAPTURE[1] = 1;
    time_capture[i] = NRF_TIMER0-&amp;gt;CC[1];
    NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0;
    (void)NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0];
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;give output&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;----------------------------------------------------------------
---- i = 0, timer counter = 5
---- i = 1, timer counter = 7
---- i = 2, timer counter = 5
---- i = 3, timer counter = 7
---- i = 4, timer counter = 7
---- i = 5, timer counter = 5
---- i = 6, timer counter = 7
---- i = 7, timer counter = 5
---- i = 8, timer counter = 7
---- i = 9, timer counter = 5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems the first event give the right timer number.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35698?ContentTypeID=1</link><pubDate>Mon, 12 Oct 2015 01:59:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5931a975-002b-4b1c-8067-5abec9e7eae8</guid><dc:creator>JiachengWang</dc:creator><description>&lt;p&gt;Hi, RK and Aryan,&lt;/p&gt;
&lt;p&gt;Thanks a lot for your help.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying to re-produce the output  with a &amp;quot;pure&amp;quot; SDK environment (I use a mixed environment with som function from old SDK and som my own functions before). I&amp;#39;m currently use UART example code in &amp;quot;nRF52_SDK_0.9.1_3639cc9\examples\peripheral\uart&amp;quot;, just with a simple modification. The main function is (add timer0 config function and modify the last lines in main function):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 */

/** @file
 * @defgroup uart_example_main main.c
 * @{
 * @ingroup uart_example
 * @brief UART Example Application main file.
 *
 * This file contains the source code for a sample application using UART.
 * 
 */

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;

//#define ENABLE_LOOPBACK_TEST  /**&amp;lt; if defined, then this example will be a loopback test, which means that TX should be connected to RX to get data loopback. */

#define MAX_TEST_DATA_BYTES     (15U)                /**&amp;lt; max number of test bytes to be used for tx and rx. */
#define UART_TX_BUF_SIZE 256                         /**&amp;lt; UART TX buffer size. */
#define UART_RX_BUF_SIZE 1                           /**&amp;lt; UART RX buffer size. */

void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event-&amp;gt;evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
    }
    else if (p_event-&amp;gt;evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
    }
}



#ifdef ENABLE_LOOPBACK_TEST
/** @brief Function for setting the @ref ERROR_PIN high, and then enter an infinite loop.
 */
static void show_error(void)
{
    
    LEDS_ON(LEDS_MASK);
    while(true)
    {
        // Do nothing.
    }
}


/** @brief Function for testing UART loop back. 
 *  @details Transmitts one character at a time to check if the data received from the loopback is same as the transmitted data.
 *  @note  @ref TX_PIN_NUMBER must be connected to @ref RX_PIN_NUMBER)
 */
static void uart_loopback_test()
{
    uint8_t * tx_data = (uint8_t *)(&amp;quot;\n\rLOOPBACK_TEST\n\r&amp;quot;);
    uint8_t   rx_data;

    // Start sending one byte and see if you get the same
    for (uint32_t i = 0; i &amp;lt; MAX_TEST_DATA_BYTES; i++)
    {
        uint32_t err_code;
        while(app_uart_put(tx_data[i]) != NRF_SUCCESS);

        nrf_delay_ms(10);
        err_code = app_uart_get(&amp;amp;rx_data);

        if ((rx_data != tx_data[i]) || (err_code != NRF_SUCCESS))
        {
            show_error();
        }
    }
    return;
}


#endif

/********************************************************************************/
void timer0_initialization(void)
/*--------------------------------------------------------------------------------
| TIMER0 initialization
|
--------------------------------------------------------------------------------*/
{
  NRF_TIMER0-&amp;gt;TASKS_STOP = 1;
  NRF_TIMER0-&amp;gt;TASKS_CLEAR = 1;
  NRF_TIMER0-&amp;gt;MODE = TIMER_MODE_MODE_Timer;
  NRF_TIMER0-&amp;gt;PRESCALER = 0;
  NRF_TIMER0-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_16Bit;
  NRF_TIMER0-&amp;gt;SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE0_CLEAR_Pos;
  NRF_TIMER0-&amp;gt;INTENSET = TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos;
  NRF_TIMER0-&amp;gt;TASKS_STOP = 1;
}


/**
 * @brief Function for main application entry.
 */
int main(void)
{
    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);
    uint32_t err_code;
    const app_uart_comm_params_t comm_params =
      {
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          RTS_PIN_NUMBER,
          CTS_PIN_NUMBER,
          APP_UART_FLOW_CONTROL_ENABLED,
          false,
          UART_BAUDRATE_BAUDRATE_Baud38400
      };

    APP_UART_FIFO_INIT(&amp;amp;comm_params,
                         UART_RX_BUF_SIZE,
                         UART_TX_BUF_SIZE,
                         uart_error_handle,
                         APP_IRQ_PRIORITY_LOW,
                         err_code);

    APP_ERROR_CHECK(err_code);
			
/*******************************************************************************/
/*******************************************************************************/
/*******************************************************************************/
    uint32_t i;
    uint32_t time_capture[10];

    timer0_initialization( );
    
    NRF_TIMER0-&amp;gt;CC[0] = 1 * 16; 
 
    NRF_TIMER0-&amp;gt;TASKS_CLEAR = 1;
    NRF_TIMER0-&amp;gt;TASKS_START = 1;
    for (i=1; i&amp;lt;10; i++)
    {
        while (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] == 0)
        {
        }  
				NRF_TIMER0-&amp;gt;TASKS_CAPTURE[1] = 1;
        time_capture[i] = NRF_TIMER0-&amp;gt;CC[1];
        NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0;
        (void)NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0];
    }
  
    printf(&amp;quot;-------------------------------- Start ------------------------------- \r\n&amp;quot;);
    for (i=0; i&amp;lt;10; i++)
    {
        printf(&amp;quot;---- i = %ld, time delay = %ld\r\n&amp;quot;, i, time_capture[i]); 
			  nrf_delay_ms(10);
    }
}
/** @} */
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With smaller CC[0] value “NRF_TIMER0-&amp;gt;CC[0] = 1 * 16” and capture timer0 counter and RTC0 is not used. The output of above code is as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;-------------------------------- Start -------------------------------
---- i = 0, timer counter = 0
---- i = 1, timer counter = 7
---- i = 2, timer counter = 8
---- i = 3, timer counter = 9
---- i = 4, timer counter = 10
---- i = 5, timer counter = 11
---- i = 6, timer counter = 8
---- i = 7, timer counter = 9
---- i = 8, timer counter = 10
---- i = 9, timer counter = 11
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems the first event still have different timer number.  With some larger CC[0] value, NRF_TIMER0-&amp;gt;CC[0] = 1000 * 16 give output&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;-------------------------------- Start -------------------------------
---- i = 0, timer counter = 0
---- i = 1, timer counter = 7
---- i = 2, timer counter = 5
---- i = 3, timer counter = 7
---- i = 4, timer counter = 5
---- i = 5, timer counter = 7
---- i = 6, timer counter = 5
---- i = 7, timer counter = 7
---- i = 8, timer counter = 5
---- i = 9, timer counter = 7
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The code is simple, please help to check the lines of TIMER0 initialization, if some registers have wrong configured.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using nRF52832 preview DK board (PCA10036), if possible, please repeat the output with above code at your side.&lt;/p&gt;
&lt;p&gt;Thanks again and Best Regards,&lt;/p&gt;
&lt;p&gt;Jiacheng&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35697?ContentTypeID=1</link><pubDate>Sun, 11 Oct 2015 07:54:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9bcc243-d5a7-4187-8ff8-01e373189c14</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;The CC register doesn&amp;#39;t take any time at all so that&amp;#39;s not the problem. This output makes no sense to me currently, I can&amp;#39;t see how you could be getting this result. As long as TIMER0 is started from 0 when you start it, the first event will occur 16,000 ticks later.&lt;/p&gt;
&lt;p&gt;As well as recording the RTC0 counts, how about recording the TIMER0 count at the same moments to just confirm they make sense. ie add a timer_capture[] variable and after each of the &lt;code&gt;time_capture[x]=RTC0-&amp;gt;COUNTER&lt;/code&gt; lines add something which captures the TIMER0 count to CC[1] and stores that - then print them out too.&lt;/p&gt;
&lt;p&gt;Take that printf() at the start out too, just to eliminate that, I don&amp;#39;t know what printf() library you have in there and whether it&amp;#39;s asynchronous, uses timers or anything else.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35696?ContentTypeID=1</link><pubDate>Sun, 11 Oct 2015 04:17:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1d7fb4b-d3ba-4703-a92e-d3e56596b50e</guid><dc:creator>JiachengWang</dc:creator><description>&lt;p&gt;Hi, Aryan,&lt;/p&gt;
&lt;p&gt;Put &amp;quot;NRF_TIMER0-&amp;gt;TASKS_CLEAR=1&amp;quot;  there has no any help.&lt;/p&gt;
&lt;p&gt;With more test, I have the following observation: put some delay right after &amp;quot;NRF_TIMER0-&amp;gt;CC[0] = 1000 * 16;&amp;quot;, the delay is the same. the code like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; NRF_TIMER0-&amp;gt;CC[0] = 1000 * 16; 
  nrf_delay_ms(1);  
  
  time_capture[0] = NRF_RTC0-&amp;gt;COUNTER;   
 
  NRF_TIMER0-&amp;gt;TASKS_START = 1;
  for (i=1; i&amp;lt;10; i++)
  {
    NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0; 
    while (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] == 0)
    {        
    }
    time_capture[i] = NRF_RTC0-&amp;gt;COUNTER;   
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;then I get the output as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;---------------------------------- Start --------------------------------------- 
i = 1, time delay = 34
i = 2, time delay = 34
i = 3, time delay = 34
i = 4, time delay = 33
i = 5, time delay = 34
i = 6, time delay = 34
i = 7, time delay = 34
i = 8, time delay = 34
i = 9, time delay = 34
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, if I reduce the delay as  &amp;quot;nrf_delay_us(500);&amp;quot;, the output is as.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;---------------------------------- Start --------------------------------------- 
i = 1, time delay = 25
i = 2, time delay = 34
i = 3, time delay = 34
i = 4, time delay = 33
i = 5, time delay = 34
i = 6, time delay = 34
i = 7, time delay = 34
i = 8, time delay = 34
i = 9, time delay = 34
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Why CC register take so long time? I want to use timer0 to get exact time delay as about 20us ~30us. timer0 has timing resolution of 16M, I think it is enough to control such time delay. Would you please give me some suggestions or comments?&lt;/p&gt;
&lt;p&gt;Thanks a lot!&lt;/p&gt;
&lt;p&gt;Jiacheng&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35695?ContentTypeID=1</link><pubDate>Sun, 11 Oct 2015 02:32:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86d73a9a-8cdd-4a99-91f5-15f4f2a1d550</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Does it help if you put a &lt;code&gt;NRF_TIMER0-&amp;gt;TASKS_CLEAR=1&lt;/code&gt; before starting the timer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35694?ContentTypeID=1</link><pubDate>Sat, 10 Oct 2015 23:03:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7db06347-ad91-4993-b279-bc449777fa4d</guid><dc:creator>JiachengWang</dc:creator><description>&lt;p&gt;Hi, Aryan,&lt;/p&gt;
&lt;p&gt;Thanks a lot for your quick response.&lt;/p&gt;
&lt;p&gt;The point is that the first event time (after timer0 task tarted) is different. To record the time of first event (and remove the delay right after timer0 started), the code is modified as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{
  uint32_t i;
  uint32_t time_capture[10];
   
  /* UART and RTC0 initialization */
  
  printf (&amp;quot;---------------------------------- Start --------------------------------------- \r\n&amp;quot;);
  
  timer0_initialization1( );
  /* RTC0 initialization */
  rtc0_time_out_config( );
  
  time_capture[0] = NRF_RTC0-&amp;gt;COUNTER;  
  
  NRF_TIMER0-&amp;gt;CC[0] = 1000 * 16;
  NRF_TIMER0-&amp;gt;TASKS_START = 1;
  
  for (i=1; i&amp;lt;10; i++)
  {
    NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0;    
    while (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] == 0)
    {        
    }
    time_capture[i] = NRF_RTC0-&amp;gt;COUNTER;
  }
  for (i=1; i&amp;lt;10; i++)
  {
    printf(&amp;quot;i = %ld, time delay = %ld, \r\n&amp;quot;, i, time_capture[i] - time_capture[i - 1]); 
  }
  
  while(1);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the result is as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;   ---------------------------------- Start --------------------------------------- 
    i = 1, time delay = 8, 
    i = 2, time delay = 34, 
    i = 3, time delay = 34, 
    i = 4, time delay = 34, 
    i = 5, time delay = 33, 
    i = 6, time delay = 34, 
    i = 7, time delay = 34, 
    i = 8, time delay = 34, 
    i = 9, time delay = 34, 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How can I get the same time of the first event as the other events?&lt;/p&gt;
&lt;p&gt;Thanks again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question about strange behavior of Timer0</title><link>https://devzone.nordicsemi.com/thread/35693?ContentTypeID=1</link><pubDate>Sat, 10 Oct 2015 17:24:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18fffae0-70af-471a-81cb-de6d771591ae</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;capture the RTC-&amp;gt;COUNTER value after you get the event&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  for (i=0; i&amp;lt;10; i++)
     {  
        NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0;
    while (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] == 0)
    {    
       /* delay 1ms */    
    }
    time_capture[i] = NRF_RTC0-&amp;gt;COUNTER;  // &amp;lt;-- this is changed
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;you are not using interrupts to sense the TIMER0 events, so if you add nrf_delay_ms(some_number), then you are just ignoring the events happening within that time.
After that when you capture the RTC-&amp;gt;COUNTER value then it will give you different numbers because of the initial ignored events which caused many overflows in RTC counter.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>