<?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>Can I use Timer1 and RTC on the same app?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30500/can-i-use-timer1-and-rtc-on-the-same-app</link><description>Hi all, 
 I would like someone give me a suggestion about timers. 
 in my current approvement I am using an RTC timer with 32k crystal to control my sleep times it is power efficient and accurate, but limited if I want to use micro seconds interruptions</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 Feb 2018 15:04:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30500/can-i-use-timer1-and-rtc-on-the-same-app" /><item><title>RE: Can I use Timer1 and RTC on the same app?</title><link>https://devzone.nordicsemi.com/thread/120995?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2018 15:04:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8bcdeb6-b658-493c-96a7-f2b48c9d452d</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Have you tried to configure the timer_cfg?&lt;/p&gt;
&lt;p&gt;In addition you can use the nrf_drv_timer_us_to_ticks();&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(3);

void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
            bsp_board_led_invert(3);
            break;
    
        default:
            // Do nothing.
            break;
    }
}

int main(void)
{
    uint32_t time_us = 1000000; //Time(in microseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    //Configure all leds on board.
    bsp_board_leds_init();

    //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_1MHz;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_24;
    err_code = nrf_drv_timer_init(&amp;amp;TIMER_LED, &amp;amp;timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_us_to_ticks(&amp;amp;TIMER_LED, time_us);

    nrf_drv_timer_extended_compare(
         &amp;amp;TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&amp;amp;TIMER_LED);

    while (1)
    {
        __WFI();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you look into the functions that are being used, such as the nrf_drv_timer_init(), you can see that it essentially uses the PPI functionality that we discussed in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/30401/what-is-more-efficient-use-nrf_delay_us-or-timer-hfclk-for-1-us" rel="noopener noreferrer" target="_blank"&gt;your other case&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you use the timer with the softdevice, you can&amp;#39;t use timer instance(0), because the softdevice uses timer instance 0. Therefore I changed it to 3.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also changed the timeout handler, because the normal SDK ble examples uses LED1 and (sometimes 2) to display connection status.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can I use Timer1 and RTC on the same app?</title><link>https://devzone.nordicsemi.com/thread/120970?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2018 12:23:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bae93391-6bec-4e32-8ce3-1c5a70a76593</guid><dc:creator>Arepa</dc:creator><description>&lt;p&gt;Hi Ed,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, it is. I am trying to have alternatives, But it is a little confusing on the documentation the term Timer could be use for app timer for RTC and the Timer0,1, etc.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For example using this code I am unable to change the prescaler or bit width chaning the values on timer_cfg&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can I use Timer1 and RTC on the same app?</title><link>https://devzone.nordicsemi.com/thread/120929?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2018 07:38:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64de6aff-ec7e-4122-939f-dfc7c9c036fb</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Is this case related to &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/30401/what-is-more-efficient-use-nrf_delay_us-or-timer-hfclk-for-1-us" rel="noopener noreferrer" target="_blank"&gt;your other case&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;I will assume that it is, but let me know if this is a separate issue, and I will look into it.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>