<?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 use Timer to count pulse width</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/31103/how-to-use-timer-to-count-pulse-width</link><description>Hi all , 
 I have to decode the IR pulse for remote . I want to use Timer to count pulse width .I know how to use timer to create a time , but I don&amp;#39;t know how to use timer to count. Please show me a solution . Thank</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Mar 2018 05:57:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/31103/how-to-use-timer-to-count-pulse-width" /><item><title>RE: How to use Timer to count pulse width</title><link>https://devzone.nordicsemi.com/thread/122731?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 05:57:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:999d3254-9192-4e4c-af8d-e3661c5ab71d</guid><dc:creator>norin saiyed</dc:creator><description>&lt;p&gt;you can use application timer. here is the tutorial link. Hope this helps.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/tutorials/b/software-development-kit/posts/application-timer-tutorial"&gt;https://devzone.nordicsemi.com/tutorials/b/software-development-kit/posts/application-timer-tutorial&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;then use app_timer_cnt_get function&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use Timer to count pulse width</title><link>https://devzone.nordicsemi.com/thread/122730?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 05:52:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bfb6022-3d32-4f5d-9392-45cc5b13c34c</guid><dc:creator>Giang</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;

uint32_t counter;


const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);

/**
 * @brief Handler for timer events.
 */
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    static uint32_t i;
    uint32_t led_to_invert = ((i++) % LEDS_NUMBER);

    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
				nrf_gpio_pin_toggle(LED_1);
				NRF_TIMER2-&amp;gt;TASKS_CAPTURE[0] = 1;
				counter = NRF_TIMER2-&amp;gt;CC[0];
            break;

        default:
            //Do nothing.
            break;
    }
}


/**
 * @brief Function for main application entry.
 */
int main(void)
{
    uint32_t time_ms = 1000; //Time(in miliseconds) 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;
    err_code = nrf_drv_timer_init(&amp;amp;TIMER_LED, &amp;amp;timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);		
//32 bit , 1M	
    nrf_drv_timer_extended_compare(
         &amp;amp;TIMER_LED, NRF_TIMER_CC_CHANNEL0, 1000000, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&amp;amp;TIMER_LED);




    while (1)
    {

    }
}

/** @} */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It my code , but I don&amp;#39;t get counter , it alway = 0. Can you explain for me?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use Timer to count pulse width</title><link>https://devzone.nordicsemi.com/thread/122729?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 05:22:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d269f898-4867-4166-94d9-527ac8c2e66f</guid><dc:creator>norin saiyed</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can use app_timer_cnt_get(); for getting count value .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>