<?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>Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/104317/unable-to-capture-the-pulse-at-gpio</link><description>Hi all, Im trying to capture the pulse (to calculate its time period of complete pulse which will be start from rising/falling edge and ends at rising/falling edge). for this I found following examples but both did not work for me. https://github.com</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 09 Oct 2023 06:25:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/104317/unable-to-capture-the-pulse-at-gpio" /><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/449280?ContentTypeID=1</link><pubDate>Mon, 09 Oct 2023 06:25:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e97696a-d316-420d-a242-0d6a60cd01b3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I need you to test with the output signal&amp;nbsp;from&amp;nbsp;the &amp;quot;SIG_OUT_PIN&amp;quot;&lt;/p&gt;
[quote user="Khalil Ahmad"] it was 5KHz constant at any frequency.[/quote]
&lt;p&gt;Where are you seeing this? Please post a screenshot/picture.&lt;/p&gt;
[quote user="Khalil Ahmad"]I made changes so that it will not generate the input signal so that i can supply from outside and then i did not notice any output signal[/quote]
&lt;p&gt;I need you to test with the output signal on the SIG_OUT_PIN before you start making changes to the code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/449241?ContentTypeID=1</link><pubDate>Sat, 07 Oct 2023 00:21:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a3b50d3-bf04-4e2b-9584-f7262df3b206</guid><dc:creator>Khalil Ahmad</dc:creator><description>&lt;p&gt;yes I used signal generator to generate a signal on the input pin and tried to measure the output from logic analyzer. I noticed following&lt;/p&gt;
&lt;p&gt;1 - When i used that code without any change... the ouput signal was constant despite the changes from the signal generator (changing the frequency of the signal). it was 5KHz constant at any frequency.&lt;/p&gt;
&lt;p&gt;2 - I made changes so that it will not generate the input signal so that i can supply from outside and then i did not notice any output signal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/449076?ContentTypeID=1</link><pubDate>Thu, 05 Oct 2023 15:41:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bd51217-1776-4276-aada-9f657ad066cc</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Were you measuring on the input or output pin? How did you measure it? Do you have a trace from a scope or logic analyzer that can be used as a reference?&lt;/p&gt;
&lt;p&gt;I verified the input and output signal on a DK with a logic analyzer here with that code here.&lt;/p&gt;
[quote user="Khalil Ahmad"]Then I made following changes but there is no signal or data on the com port.[/quote]
&lt;p&gt;Can you point me to the exact changes you made?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/449032?ContentTypeID=1</link><pubDate>Thu, 05 Oct 2023 13:26:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fdfc6f1-3b26-4075-bb65-36b7bce0f67a</guid><dc:creator>Khalil Ahmad</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include &amp;lt;stdint.h&amp;gt;

#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;

#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;


/* Signal generator output */
#define SIG_OUT_PIN             29
#define SIG_OUT_INTERVAL_US     1

#define SIG_INPUT_PIN     3


static const nrf_drv_timer_t m_timer1 = NRF_DRV_TIMER_INSTANCE(1);
static const nrf_drv_timer_t m_timer2 = NRF_DRV_TIMER_INSTANCE(2);
static const nrf_drv_timer_t m_timer3 = NRF_DRV_TIMER_INSTANCE(3);

static volatile bool m_sample_pending;

/* Timer event handler. Not used since Timer1 and Timer2 are used only for PPI. */
static void empty_timer_handler(nrf_timer_event_t event_type, void * p_context)
{
}

static void signal_capture_handler(nrf_timer_event_t event_type, void * p_context)
{
    uint32_t err_code;
    uint32_t timer_ticks;

    timer_ticks = nrf_drv_timer_capture(&amp;amp;m_timer3, NRF_TIMER_CC_CHANNEL0);

    NRF_LOG_INFO(&amp;quot;Signal period: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; us&amp;quot;, NRF_LOG_FLOAT((float)timer_ticks/16.0f));

    nrf_drv_timer_clear(&amp;amp;m_timer3);
    nrf_drv_timer_clear(&amp;amp;m_timer2);
    m_sample_pending = false;
    nrf_drv_gpiote_in_event_disable(SIG_INPUT_PIN);
}

void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{

}


static void log_init(void)
{
    uint32_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}

static void hf_clock_start(void)
{
    /* Start HFXO for better accuracy */
    NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
    while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0)
      {};
}
/*
static void signal_generator_start(void)
{
    uint32_t err_code; 
    uint32_t out_task_addr;
    uint32_t timer_evt0_addr;
    nrf_ppi_channel_t ppi_channel;
    

    nrf_drv_gpiote_out_config_t signal_out = GPIOTE_CONFIG_OUT_TASK_TOGGLE(true);
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;

    /* Configure timer and output signal */
  /*  err_code = nrf_drv_timer_init(&amp;amp;m_timer1, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer1,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrfx_timer_us_to_ticks(&amp;amp;m_timer1, SIG_OUT_INTERVAL_US),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);

    timer_evt0_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer1,NRF_TIMER_CC_CHANNEL0);

    /* Configure GPIOTE task */
 /*   err_code = nrf_drv_gpiote_out_init(SIG_OUT_PIN, &amp;amp;signal_out);
    APP_ERROR_CHECK(err_code);

    out_task_addr = nrf_drv_gpiote_out_task_addr_get(SIG_OUT_PIN);

    nrf_drv_gpiote_out_task_enable(SIG_OUT_PIN);
    
    /* Connect timer event to GPIOTE task through PPI */
 /*   err_code = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel, timer_evt0_addr, out_task_addr);
    APP_ERROR_CHECK(err_code);

    nrf_drv_ppi_channel_enable(ppi_channel); 
        
    /* Start signal generation */
 /*   nrf_drv_timer_enable(&amp;amp;m_timer1);                    
}
*/

static void signal_input_sampling_init(void)
{
    uint32_t err_code;
    nrf_ppi_channel_t ppi_channel;
    uint32_t gpiote_evt_addr;
    uint32_t count_task_addr;
    uint32_t timer_start_addr;
    uint32_t timer_stop_addr;
    uint32_t timer_evt0_addr;
    uint32_t timer_evt1_addr;

    nrf_drv_gpiote_in_config_t input_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;

    err_code = nrf_drv_gpiote_in_init(SIG_INPUT_PIN, &amp;amp;input_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    gpiote_evt_addr = nrf_drv_gpiote_in_event_addr_get(SIG_INPUT_PIN);

    timer_cfg.mode = NRF_TIMER_MODE_COUNTER;

    err_code = nrf_drv_timer_init(&amp;amp;m_timer2, &amp;amp;timer_cfg, signal_capture_handler);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_timer_compare(&amp;amp;m_timer2,
                          NRF_TIMER_CC_CHANNEL0,
                          1,
                          false);
   
    nrf_drv_timer_compare(&amp;amp;m_timer2,
                          NRF_TIMER_CC_CHANNEL1,
                          2,
                          true);

    count_task_addr = nrf_drv_timer_task_address_get(&amp;amp;m_timer2, NRF_TIMER_TASK_COUNT);
    timer_evt0_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer2, NRF_TIMER_CC_CHANNEL0);
    timer_evt1_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer2, NRF_TIMER_CC_CHANNEL1);
    
    nrf_drv_timer_enable(&amp;amp;m_timer2);

    timer_cfg.mode = NRF_TIMER_MODE_TIMER;

    err_code = nrf_drv_timer_init(&amp;amp;m_timer3, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    timer_start_addr = nrf_drv_timer_task_address_get(&amp;amp;m_timer3, NRF_TIMER_TASK_START);
    timer_stop_addr  = nrf_drv_timer_task_address_get(&amp;amp;m_timer3, NRF_TIMER_TASK_STOP);

    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel, gpiote_evt_addr, count_task_addr);
    APP_ERROR_CHECK(err_code);

    nrf_drv_ppi_channel_enable(ppi_channel); 

    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel, timer_evt0_addr, timer_start_addr);
    APP_ERROR_CHECK(err_code);

    nrf_drv_ppi_channel_enable(ppi_channel); 

    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel, timer_evt1_addr, timer_stop_addr);
    APP_ERROR_CHECK(err_code);

    nrf_drv_ppi_channel_enable(ppi_channel); 
}

static void ppi_init(void)
{
    uint32_t err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);
}

static void gpiote_init(void)
{
    uint32_t err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
}

static void signal_input_sample(void)
{
    if (!m_sample_pending)
    {
        nrf_drv_gpiote_in_event_enable(SIG_INPUT_PIN, false);
        m_sample_pending = true;
    }
}
/**
 * @brief Function for application main entry.
 */
void main(void)
{
    hf_clock_start();
    log_init();

    ppi_init();
    gpiote_init();

   // signal_generator_start();
    signal_input_sampling_init();

    while (true)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            //__WFE();
            


  signal_input_sample();
        
       // if(signal_input &amp;gt; 0)
        //{
            NRF_LOG_INFO(&amp;quot;Capture value: %i us&amp;quot;, signal_input_sample());
              NRF_LOG_INFO(&amp;quot;Capture value: %i us&amp;quot;,  signal_input_sampling_init());
      //  }
       // else NRF_LOG_INFO(&amp;quot;No capture detected&amp;quot;);
        
       // nrf_delay_ms(500);
        NRF_LOG_FLUSH();

           // nrf_delay_ms(1000);

        }
    }
}

/** @} */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Yes, I tried your code and even i was intereted to work on it. But it did not work at all. First of all I used as it is and it was giving constatnt clock of 500KHz despite the changing the clock at input pin. Then I made following changes but there is no signal or data on the com port.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448998?ContentTypeID=1</link><pubDate>Thu, 05 Oct 2023 12:02:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63f0efce-13cc-4b4e-a2c0-49eabab03b40</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The code you are using now appears to be reliant on interrupts to capture the input signal period, which means the shortest signal period you can measure is going to be limited by the interrupt and wakeup latency of the device:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/33212/nrf52-gpiote-interrupt-latency/154209"&gt;RE: nRF52 GPIOTE interrupt latency&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I suggest you try to get the code I posted in your other ticket to work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448932?ContentTypeID=1</link><pubDate>Thu, 05 Oct 2023 07:01:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c67401a3-7406-4781-bff6-1d9626d9eff7</guid><dc:creator>Khalil Ahmad</dc:creator><description>&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1696489213152v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/vibe"&gt;Vidar Berg&lt;/a&gt;&amp;nbsp; Im getting these values for the signal. Now I want to check either these are the ticks or time.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448925?ContentTypeID=1</link><pubDate>Thu, 05 Oct 2023 06:35:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5085064-2402-4212-affb-36900b3b5a22</guid><dc:creator>Khalil Ahmad</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/** @file
* @defgroup temperature_example_main main.c
* @{
* @ingroup temperature_example
* @brief Temperature Example Application main file.
* @details
* This file contains the source code for a sample application using the temperature sensor.
* This contains workaround for PAN_028 rev2.0A anomalies 28, 29,30 and 31. PAN 43 is not covered.
*  - PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly
*  - PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register.
*  - PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs.
*  - PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module
*  - PAN_028 rev2.0A anomaly 43 - TEMP: Using PPI between DATARDY event and START task is not functional.
*
*/
#include &amp;lt;stdint.h&amp;gt;

#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;

#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#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;

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

const nrf_drv_timer_t capture_timer = NRF_DRV_TIMER_INSTANCE(3);

#define SAMPLE_PIN                      3
#define TIMER_PRESCALER                 NRF_TIMER_FREQ_1MHz
#define GPIOTE_CH_CAPTURE               0
#define GPIOTE_CH_RESTART               1
#define GPIOTE_CH_SELFTEST              2

#define SELF_TEST                       1

/////editing pasting from PPI Example


#define PPI_EXAMPLE_TIMERS_PHASE_SHIFT_DELAY   (1)// (10)    // 1s = 10 * 100ms (Timer 0 interrupt)
#define PPI_EXAMPLE_TIMER0_INTERVAL             (1)//(100)   // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER3_INTERVAL             (2)//(2000)  // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER4_INTERVAL             (2)//(2000)  // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER1_INTERVAL             (2)//(2000)  // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER2_INTERVAL             (2)//(2000)  // Timer interval in milliseconds


static const nrf_drv_timer_t m_timer0 = NRF_DRV_TIMER_INSTANCE(0);
//static const nrf_drv_timer_t m_timer3 = NRF_DRV_TIMER_INSTANCE(1);
//static const nrf_drv_timer_t m_timer4 = NRF_DRV_TIMER_INSTANCE(2);
static const nrf_drv_timer_t m_timer1 = NRF_DRV_TIMER_INSTANCE(1);
static const nrf_drv_timer_t m_timer2 = NRF_DRV_TIMER_INSTANCE(2);
//static const nrf_drv_timer_t m_timer4 = NRF_DRV_TIMER_INSTANCE(2);
//const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);

static nrf_ppi_channel_t m_ppi_channel1;
static nrf_ppi_channel_t m_ppi_channel2;

static volatile uint32_t m_counter;

static void timer0_event_handler(nrf_timer_event_t event_type, void * p_context)
{
    ++m_counter;
}

/* Timer event handler. Not used since Timer1 and Timer2 are used only for PPI. */
static void empty_timer_handler(nrf_timer_event_t event_type, void * p_context)
{
}


/** @brief Function for initializing the PPI peripheral.
*/
static void ppi_init(void)
{
    uint32_t err_code = NRF_SUCCESS;

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    /* Configure 1st available PPI channel to stop TIMER0 counter on TIMER1 COMPARE[0] match,
     * which is every even number of seconds.
     */
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel1,
                                          nrf_drv_timer_event_address_get(&amp;amp;m_timer1,
                                                                          NRF_TIMER_EVENT_COMPARE0),
                                          nrf_drv_timer_task_address_get(&amp;amp;m_timer0,
                                                                         NRF_TIMER_TASK_STOP));
    APP_ERROR_CHECK(err_code);

    /* Configure 2nd available PPI channel to start TIMER0 counter at TIMER2 COMPARE[0] match,
     * which is every odd number of seconds.
     */
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel2);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel2,
                                          nrf_drv_timer_event_address_get(&amp;amp;m_timer2,
                                                                          NRF_TIMER_EVENT_COMPARE0),
                                          nrf_drv_timer_task_address_get(&amp;amp;m_timer0,
                                                                         NRF_TIMER_TASK_START));
    APP_ERROR_CHECK(err_code);

    // Enable both configured PPI channels
    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel2);
    APP_ERROR_CHECK(err_code);
}



/** @brief Function for Timer 0 initialization.
 *  @details Timer 0 will be stopped and started by Timer 1 and Timer 2 respectively using PPI.
 *           It is configured to generate an interrupt every 100ms.
 */
static void timer0_init(void)
{
    // Check TIMER0 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_62500Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer0, &amp;amp;timer_cfg, timer0_event_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer0,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer0,
                                                             PPI_EXAMPLE_TIMER0_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   true);
}
static void timer1_init(void)
{
    // Check TIMER1 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_62500Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer1, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer1,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrfx_timer_ms_to_ticks(&amp;amp;m_timer1,
                                                             PPI_EXAMPLE_TIMER1_INTERVAL ),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}


/** @brief Function for Timer 2 initialization.
 *  @details Initializes TIMER2 peripheral to generate an event every 2 seconds. The events are
 *           generated at odd numbers of seconds after starting the example (3, 5, 7 ...) and they
 *           are used to start TIMER0 via PPI: TIMER2-&amp;gt;EVENT_COMPARE[0] triggers TIMER0-&amp;gt;TASK_START.
 */
static void timer2_init(void)
{
    // Check TIMER2 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_62500Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer2, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer2,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrfx_timer_ms_to_ticks(&amp;amp;m_timer2,
                                                             PPI_EXAMPLE_TIMER2_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}


/** @brief Function for Timer 1 initialization.
 *  @details Initializes TIMER1 peripheral to generate an event every 2 seconds. The events are
 *           generated at even numbers of seconds after starting the example (2, 4, 6 ...) and they
 *           are used to stop TIMER0 via PPI: TIMER1-&amp;gt;EVENT_COMPARE[0] triggers TIMER0-&amp;gt;TASK_STOP.
 */
 /*
static void timer3_init(void)
{
    // Check TIMER1 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer3, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer3,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer3,
                                                             PPI_EXAMPLE_TIMER3_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}


/** @brief Function for Timer 2 initialization.
 *  @details Initializes TIMER2 peripheral to generate an event every 2 seconds. The events are
 *           generated at odd numbers of seconds after starting the example (3, 5, 7 ...) and they
 *           are used to start TIMER0 via PPI: TIMER2-&amp;gt;EVENT_COMPARE[0] triggers TIMER0-&amp;gt;TASK_START.
 */
 /*
static void timer4_init(void)
{
    // Check TIMER2 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer4, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer4,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer4,
                                                             PPI_EXAMPLE_TIMER4_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}
*/


//////END pasting





#if SELF_TEST
const nrf_drv_timer_t test_timer = NRF_DRV_TIMER_INSTANCE(4);

static void run_self_test_pin(uint32_t pin_no, uint32_t us_on, uint32_t us_off)
{
    uint32_t err_code;
    static nrf_ppi_channel_t ppi_ch_test_pin_run, ppi_ch_test_pin_run2;
    
    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_32;
    err_code = nrf_drv_timer_init(&amp;amp;test_timer, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_timer_extended_compare(&amp;amp;test_timer, 0, us_on,          0,                               false);
    nrf_drv_timer_extended_compare(&amp;amp;test_timer, 1, us_on + us_off, TIMER_SHORTS_COMPARE1_CLEAR_Msk, false);
    
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_SELFTEST] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                             GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                                             pin_no &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
                                             
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_test_pin_run);
    nrfx_ppi_channel_assign(ppi_ch_test_pin_run,
                            nrf_drv_timer_compare_event_address_get(&amp;amp;test_timer, 0),
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_CLR[GPIOTE_CH_SELFTEST]);
    nrfx_ppi_channel_enable(ppi_ch_test_pin_run);
    
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_test_pin_run2);
    nrfx_ppi_channel_assign(ppi_ch_test_pin_run2,
                            nrf_drv_timer_compare_event_address_get(&amp;amp;test_timer, 1),
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_SET[GPIOTE_CH_SELFTEST]);
    nrfx_ppi_channel_enable(ppi_ch_test_pin_run2);
    
    nrf_drv_timer_clear(&amp;amp;test_timer);
    nrf_drv_timer_resume(&amp;amp;test_timer);
}
#endif


static void gpiote_capture_init(void)
{
    uint32_t err_code;
    static nrf_ppi_channel_t ppi_ch_gpiote_capture;
    static nrf_ppi_channel_t ppi_ch_gpiote_restart;
    
    // Optionally, enable pullup or pulldown on the input pin
    //nrf_gpio_cfg_input(SAMPLE_PIN, NRF_GPIO_PIN_PULLUP);

    // Allocate two PPI channels
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_gpiote_capture);
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_gpiote_restart);
    
    // Configure the capture timer
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = TIMER_PRESCALER;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
    err_code = nrf_drv_timer_init(&amp;amp;capture_timer, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    // The GPIOTE driver doesn&amp;#39;t support two GPIOTE channels on the same pin, so direct register access is necessary
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_CAPTURE] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                            GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                                            SAMPLE_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_RESTART] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                            GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                                            SAMPLE_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;

    // Assign a PPI channel to capture the current timer state and store it in CC register 0
    nrfx_ppi_channel_assign(ppi_ch_gpiote_capture, 
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE], 
                            nrf_drv_timer_capture_task_address_get(&amp;amp;capture_timer, 0));
    
    // Assign a second PPI channel to restart the timer when a new pulse is detected
    nrfx_ppi_channel_assign(ppi_ch_gpiote_restart, 
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_RESTART], 
                            nrf_drv_timer_task_address_get(&amp;amp;capture_timer, NRF_TIMER_TASK_CLEAR));
    
    // Enable both PPI channels                
    nrfx_ppi_channel_enable(ppi_ch_gpiote_capture);
    nrfx_ppi_channel_enable(ppi_ch_gpiote_restart);

    // Make sure the GPIOTE capture in event is cleared. This will be  used to detect if a capture has occured. 
    NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE] = 0;
    
    // Start the timer
    nrfx_timer_resume(&amp;amp;capture_timer);
}


static uint32_t timer_capture_value_get(void)
{
    // Make sure the capture event occured before checking the capture register
    if(NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE] != 0)
    {
        // Clear the capture event
        NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE] = 0;
        
        // Return the stored capture value in the timer
        return nrf_drv_timer_capture_get(&amp;amp;capture_timer, 0);
    }
    else
    {
        // In case no capture occured, return 0
        return 0;
    }
}

/** @brief Function for main application entry.
 */
int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
      ppi_init();
    timer0_init(); // Timer used to increase m_counter every 100ms.
    timer1_init(); // Timer to generate events on even number of seconds - stopping Timer 0
    timer2_init();
    //timer3_init(); // Timer to generate events on even number of seconds - stopping Timer 0
   // timer4_init(); // Timer to generate events on odd number of seconds - starting Timer 0
    
    NRF_LOG_INFO(&amp;quot;Pulse capture example started&amp;quot;);


    gpiote_capture_init();
    
#if SELF_TEST
    run_self_test_pin(LED_1, 678, 10);
#endif

    while (true)
    {
        uint32_t captured_pulse_length = timer_capture_value_get();
        
        if(captured_pulse_length &amp;gt; 0)
        {
            NRF_LOG_INFO(&amp;quot;Capture value: %i us&amp;quot;, (captured_pulse_length * (1 &amp;lt;&amp;lt; TIMER_PRESCALER) / 16));
        }
        else NRF_LOG_INFO(&amp;quot;No capture detected&amp;quot;);
        
        nrf_delay_ms(500);
        NRF_LOG_FLUSH();
    }
}


/** @} */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/vibe"&gt;Vidar Berg&lt;/a&gt;&amp;nbsp; Thanks a lot for your support. Its working now with this code. But I need to work on it to make it flexible and will get back to you with more details. Thanks again, you made my day.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448914?ContentTypeID=1</link><pubDate>Thu, 05 Oct 2023 04:08:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a59ffcd0-6f73-4879-a62f-6f2030360615</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;You are calling&amp;nbsp;nrf_drv_timer_init() at line 294 with the callback argument set to &amp;#39;0&amp;#39;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448899?ContentTypeID=1</link><pubDate>Wed, 04 Oct 2023 20:39:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9fb9ecc6-aa3c-4146-babe-91c2d314757e</guid><dc:creator>Khalil Ahmad</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/** @file
* @defgroup temperature_example_main main.c
* @{
* @ingroup temperature_example
* @brief Temperature Example Application main file.
* @details
* This file contains the source code for a sample application using the temperature sensor.
* This contains workaround for PAN_028 rev2.0A anomalies 28, 29,30 and 31. PAN 43 is not covered.
*  - PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly
*  - PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register.
*  - PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs.
*  - PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module
*  - PAN_028 rev2.0A anomaly 43 - TEMP: Using PPI between DATARDY event and START task is not functional.
*
*/
#include &amp;lt;stdint.h&amp;gt;

#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;

#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#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;

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

const nrf_drv_timer_t capture_timer = NRF_DRV_TIMER_INSTANCE(3);

#define SAMPLE_PIN                      3
#define TIMER_PRESCALER                 NRF_TIMER_FREQ_1MHz
#define GPIOTE_CH_CAPTURE               0
#define GPIOTE_CH_RESTART               1
#define GPIOTE_CH_SELFTEST              2

#define SELF_TEST                       1

/////editing pasting from PPI Example


#define PPI_EXAMPLE_TIMERS_PHASE_SHIFT_DELAY   (1)// (10)    // 1s = 10 * 100ms (Timer 0 interrupt)
#define PPI_EXAMPLE_TIMER0_INTERVAL             (100)//(100)   // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER3_INTERVAL             (2000)//(2000)  // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER4_INTERVAL             (2000)//(2000)  // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER1_INTERVAL             (2000)//(2000)  // Timer interval in milliseconds
#define PPI_EXAMPLE_TIMER2_INTERVAL             (2000)//(2000)  // Timer interval in milliseconds


static const nrf_drv_timer_t m_timer0 = NRF_DRV_TIMER_INSTANCE(0);
static const nrf_drv_timer_t m_timer3 = NRF_DRV_TIMER_INSTANCE(1);
static const nrf_drv_timer_t m_timer4 = NRF_DRV_TIMER_INSTANCE(2);
static const nrf_drv_timer_t m_timer1 = NRF_DRV_TIMER_INSTANCE(3);
static const nrf_drv_timer_t m_timer2 = NRF_DRV_TIMER_INSTANCE(4);
//static const nrf_drv_timer_t m_timer4 = NRF_DRV_TIMER_INSTANCE(2);
//const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);

static nrf_ppi_channel_t m_ppi_channel1;
static nrf_ppi_channel_t m_ppi_channel2;

static volatile uint32_t m_counter;

static void timer0_event_handler(nrf_timer_event_t event_type, void * p_context)
{
    ++m_counter;
}

/* Timer event handler. Not used since Timer1 and Timer2 are used only for PPI. */
static void empty_timer_handler(nrf_timer_event_t event_type, void * p_context)
{
}


/** @brief Function for initializing the PPI peripheral.
*/
static void ppi_init(void)
{
    uint32_t err_code = NRF_SUCCESS;

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    /* Configure 1st available PPI channel to stop TIMER0 counter on TIMER1 COMPARE[0] match,
     * which is every even number of seconds.
     */
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel1,
                                          nrf_drv_timer_event_address_get(&amp;amp;m_timer3,
                                                                          NRF_TIMER_EVENT_COMPARE0),
                                          nrf_drv_timer_task_address_get(&amp;amp;m_timer0,
                                                                         NRF_TIMER_TASK_STOP));
    APP_ERROR_CHECK(err_code);

    /* Configure 2nd available PPI channel to start TIMER0 counter at TIMER2 COMPARE[0] match,
     * which is every odd number of seconds.
     */
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel2);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel2,
                                          nrf_drv_timer_event_address_get(&amp;amp;m_timer4,
                                                                          NRF_TIMER_EVENT_COMPARE0),
                                          nrf_drv_timer_task_address_get(&amp;amp;m_timer0,
                                                                         NRF_TIMER_TASK_START));
    APP_ERROR_CHECK(err_code);

    // Enable both configured PPI channels
    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel2);
    APP_ERROR_CHECK(err_code);
}


/** @brief Function for Timer 0 initialization.
 *  @details Timer 0 will be stopped and started by Timer 1 and Timer 2 respectively using PPI.
 *           It is configured to generate an interrupt every 100ms.
 */
static void timer0_init(void)
{
    // Check TIMER0 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer0, &amp;amp;timer_cfg, timer0_event_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer0,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer0,
                                                             PPI_EXAMPLE_TIMER0_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   true);
}
static void timer1_init(void)
{
    // Check TIMER1 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_62500Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer1, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer1,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrfx_timer_ms_to_ticks(&amp;amp;m_timer1,
                                                             PPI_EXAMPLE_TIMER1_INTERVAL ),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}


/** @brief Function for Timer 2 initialization.
 *  @details Initializes TIMER2 peripheral to generate an event every 2 seconds. The events are
 *           generated at odd numbers of seconds after starting the example (3, 5, 7 ...) and they
 *           are used to start TIMER0 via PPI: TIMER2-&amp;gt;EVENT_COMPARE[0] triggers TIMER0-&amp;gt;TASK_START.
 */
static void timer2_init(void)
{
    // Check TIMER2 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_62500Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer2, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer2,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrfx_timer_ms_to_ticks(&amp;amp;m_timer2,
                                                             PPI_EXAMPLE_TIMER2_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}


/** @brief Function for Timer 1 initialization.
 *  @details Initializes TIMER1 peripheral to generate an event every 2 seconds. The events are
 *           generated at even numbers of seconds after starting the example (2, 4, 6 ...) and they
 *           are used to stop TIMER0 via PPI: TIMER1-&amp;gt;EVENT_COMPARE[0] triggers TIMER0-&amp;gt;TASK_STOP.
 */
static void timer3_init(void)
{
    // Check TIMER1 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer3, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer3,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer3,
                                                             PPI_EXAMPLE_TIMER3_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}


/** @brief Function for Timer 2 initialization.
 *  @details Initializes TIMER2 peripheral to generate an event every 2 seconds. The events are
 *           generated at odd numbers of seconds after starting the example (3, 5, 7 ...) and they
 *           are used to start TIMER0 via PPI: TIMER2-&amp;gt;EVENT_COMPARE[0] triggers TIMER0-&amp;gt;TASK_START.
 */
static void timer4_init(void)
{
    // Check TIMER2 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer4, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;m_timer4,
                                   NRF_TIMER_CC_CHANNEL0,
                                   nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer4,
                                                             PPI_EXAMPLE_TIMER4_INTERVAL),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
}


//////END pasting





#if SELF_TEST
const nrf_drv_timer_t test_timer = NRF_DRV_TIMER_INSTANCE(4);

static void run_self_test_pin(uint32_t pin_no, uint32_t us_on, uint32_t us_off)
{
    uint32_t err_code;
    static nrf_ppi_channel_t ppi_ch_test_pin_run, ppi_ch_test_pin_run2;
    
    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_32;
    err_code = nrf_drv_timer_init(&amp;amp;test_timer, &amp;amp;timer_cfg, 0);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_timer_extended_compare(&amp;amp;test_timer, 0, us_on,          0,                               false);
    nrf_drv_timer_extended_compare(&amp;amp;test_timer, 1, us_on + us_off, TIMER_SHORTS_COMPARE1_CLEAR_Msk, false);
    
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_SELFTEST] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                             GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                                             pin_no &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
                                             
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_test_pin_run);
    nrfx_ppi_channel_assign(ppi_ch_test_pin_run,
                            nrf_drv_timer_compare_event_address_get(&amp;amp;test_timer, 0),
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_CLR[GPIOTE_CH_SELFTEST]);
    nrfx_ppi_channel_enable(ppi_ch_test_pin_run);
    
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_test_pin_run2);
    nrfx_ppi_channel_assign(ppi_ch_test_pin_run2,
                            nrf_drv_timer_compare_event_address_get(&amp;amp;test_timer, 1),
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_SET[GPIOTE_CH_SELFTEST]);
    nrfx_ppi_channel_enable(ppi_ch_test_pin_run2);
    
    nrf_drv_timer_clear(&amp;amp;test_timer);
    nrf_drv_timer_resume(&amp;amp;test_timer);
}
#endif

static void gpiote_capture_init(void)
{
    uint32_t err_code;
    static nrf_ppi_channel_t ppi_ch_gpiote_capture;
    static nrf_ppi_channel_t ppi_ch_gpiote_restart;
    
    // Optionally, enable pullup or pulldown on the input pin
    //nrf_gpio_cfg_input(SAMPLE_PIN, NRF_GPIO_PIN_PULLUP);

    // Allocate two PPI channels
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_gpiote_capture);
    nrfx_ppi_channel_alloc(&amp;amp;ppi_ch_gpiote_restart);
    
    // Configure the capture timer
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = TIMER_PRESCALER;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
    err_code = nrf_drv_timer_init(&amp;amp;capture_timer, &amp;amp;timer_cfg, 0);
    APP_ERROR_CHECK(err_code);

    // The GPIOTE driver doesn&amp;#39;t support two GPIOTE channels on the same pin, so direct register access is necessary
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_CAPTURE] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                            GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                                            SAMPLE_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_RESTART] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                            GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                                            SAMPLE_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;

    // Assign a PPI channel to capture the current timer state and store it in CC register 0
    nrfx_ppi_channel_assign(ppi_ch_gpiote_capture, 
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE], 
                            nrf_drv_timer_capture_task_address_get(&amp;amp;capture_timer, 0));
    
    // Assign a second PPI channel to restart the timer when a new pulse is detected
    nrfx_ppi_channel_assign(ppi_ch_gpiote_restart, 
                            (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_RESTART], 
                            nrf_drv_timer_task_address_get(&amp;amp;capture_timer, NRF_TIMER_TASK_CLEAR));
    
    // Enable both PPI channels                
    nrfx_ppi_channel_enable(ppi_ch_gpiote_capture);
    nrfx_ppi_channel_enable(ppi_ch_gpiote_restart);

    // Make sure the GPIOTE capture in event is cleared. This will be  used to detect if a capture has occured. 
    NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE] = 0;
    
    // Start the timer
    nrfx_timer_resume(&amp;amp;capture_timer);
}


static uint32_t timer_capture_value_get(void)
{
    // Make sure the capture event occured before checking the capture register
    if(NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE] != 0)
    {
        // Clear the capture event
        NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_CAPTURE] = 0;
        
        // Return the stored capture value in the timer
        return nrf_drv_timer_capture_get(&amp;amp;capture_timer, 0);
    }
    else
    {
        // In case no capture occured, return 0
        return 0;
    }
}

/** @brief Function for main application entry.
 */
int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
      ppi_init();
    timer0_init(); // Timer used to increase m_counter every 100ms.
    timer1_init(); // Timer to generate events on even number of seconds - stopping Timer 0
    timer2_init();
    timer3_init(); // Timer to generate events on even number of seconds - stopping Timer 0
    timer4_init(); // Timer to generate events on odd number of seconds - starting Timer 0
    
    NRF_LOG_INFO(&amp;quot;Pulse capture example started&amp;quot;);


    gpiote_capture_init();
    
#if SELF_TEST
    run_self_test_pin(LED_1, 678, 10);
#endif

    while (true)
    {
        uint32_t captured_pulse_length = timer_capture_value_get();
        
        if(captured_pulse_length &amp;gt; 0)
        {
            NRF_LOG_INFO(&amp;quot;Capture value: %i us&amp;quot;, (captured_pulse_length * (1 &amp;lt;&amp;lt; TIMER_PRESCALER) / 16));
        }
        else NRF_LOG_INFO(&amp;quot;No capture detected&amp;quot;);
        
        nrf_delay_ms(500);
        NRF_LOG_FLUSH();
    }
}


/** @} */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Still the same error on the com port. can you please check the code and give your feedback.Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448749?ContentTypeID=1</link><pubDate>Wed, 04 Oct 2023 07:17:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:108d3dfe-aac2-40f4-9a94-659996468cd2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I see. It seems like the project has not been&amp;nbsp;tested with the &amp;#39;Debug&amp;#39; build configuration where ASSERTs are enabled. Either way, the solution is to define a dummy timer callback like in the official SDK example.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* Timer event handler. Not used since Timer1 and Timer2 are used only for PPI. */
static void empty_timer_handler(nrf_timer_event_t event_type, void * p_context)
{
}

static void timer1_init(void)
{
    ...
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;m_timer1, &amp;amp;timer_cfg, empty_timer_handler);
    APP_ERROR_CHECK(err_code);
    ...&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448748?ContentTypeID=1</link><pubDate>Wed, 04 Oct 2023 07:06:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5625efa-626e-42f4-9d70-2784d63f99ce</guid><dc:creator>Khalil Ahmad</dc:creator><description>&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1696403137130v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I tested using SDK versions v16.0.0 and v15.3.0 but results are same&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to capture the pulse at GPIO</title><link>https://devzone.nordicsemi.com/thread/448487?ContentTypeID=1</link><pubDate>Mon, 02 Oct 2023 10:46:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25704eeb-ee0e-4601-8bb3-e79be9aa673c</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The projects are developed using SDK versions v16.0.0 and v15.3.0, respectively. This is the reason they don&amp;#39;t build out-of-the-box with SDK 17.1.0.&amp;nbsp;&lt;/p&gt;
[quote user=""]for this I found following examples but both did not work for me.&amp;nbsp;&lt;a title="Pulse capture Example" href="https://github.com/too1/nrf52-gpiote-pulse-capture"&gt;https://github.com/too1/nrf52-gpiote-pulse-capture&lt;/a&gt;&amp;nbsp;and when I run the program, I get following error.[/quote]
&lt;p&gt;The assert is raised because&amp;nbsp;nrf_drv_timer_init() is not providing a callback.&amp;nbsp;&lt;/p&gt;
[quote user=""]But after lots of tries failed to get it work. even its showing lot of errors, and when all errors fixed it was not downloading to the board.[/quote]
&lt;p&gt;The SoftDevice version in SDK 17.1.0 occupies more flash memory,&amp;nbsp;which means&amp;nbsp;the application must start at a higher address&amp;nbsp;in&amp;nbsp;flash.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>