<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/101898/timer-2-capture-at-low-frequency-input</link><description>I am currently using a Capture Event on Timer 2. I will post my initialization code for that event. I am sending a square wave (incoming wave is 10Vpp with a 2.5 V offset and 50% duty cycle signaled down to a 3V input for the nrf52832 GPIOTE input) to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Jul 2023 18:08:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/101898/timer-2-capture-at-low-frequency-input" /><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/437358?ContentTypeID=1</link><pubDate>Wed, 19 Jul 2023 18:08:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fe835ea-916a-42bd-8ed9-2f93d69f175d</guid><dc:creator>inspiringdev123</dc:creator><description>&lt;p&gt;I have it set up as follows to stop the first timer after 100ms and capture the value of the second timer (pulse counter). The CC value is always 0 and is not recording the pulses now.&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;//setup a timer for Speedo/Tach pulses
    nrf_drv_timer_config_t timer_cfg2 = NRF_DRV_TIMER_DEFAULT_CONFIG; //default settings should use NRF_TIMER_FREQ_8MHz, changable in sdk_config.h
    timer_cfg2.frequency = NRF_TIMER_FREQ_62500Hz;
    timer_cfg2.bit_width = NRF_TIMER_BIT_WIDTH_16;
    timer_cfg2.interrupt_priority = APP_IRQ_PRIORITY_HIGH;

    err_code = nrf_drv_timer_init(&amp;amp;system_timer_cc_0_2, &amp;amp;timer_cfg2, system_timer_cc_0_2_handler);
    APP_ERROR_CHECK(err_code);

    //set up timer compare on CC[1] for 100ms interval on Timer 2
    nrf_drv_timer_extended_compare(&amp;amp;system_timer_cc_0_2, NRF_TIMER_CC_CHANNEL1, PULSE_READ_INTERVAL, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);

    //setup a counter for Speedo/Tach pulses
    nrf_drv_timer_config_t timer_cfg3 = NRF_DRV_TIMER_DEFAULT_CONFIG; //default settings should use NRF_TIMER_FREQ_8MHz, changable in sdk_config.h
    timer_cfg3.bit_width = NRF_TIMER_BIT_WIDTH_32;
    timer_cfg3.mode = NRF_TIMER_MODE_LOW_POWER_COUNTER;
    timer_cfg3.interrupt_priority = APP_IRQ_PRIORITY_HIGH;

    err_code = nrf_drv_timer_init(&amp;amp;system_timer_cc_0_3, &amp;amp;timer_cfg3, system_timer_cc_0_3_handler);
    APP_ERROR_CHECK(err_code);

void system_timer_cc_0_3_init(void)
{
    uint32_t capture_task_addr;
    uint32_t compare_evt_addr;
    uint32_t gpiote_task_addr;
    uint32_t time_ticks;
    ret_code_t err_code;
    nrf_drv_gpiote_in_config_t in_config;

    /* CC[2]
     * Setup PPI tasks for GPIOTE and system timer channel[2]
     * for speedo/tach
    */

    //VCE: The below block needs to be called for each pin
    in_config.pull = NRF_GPIO_PIN_PULLDOWN; //User defined
    in_config.sense = NRF_GPIOTE_POLARITY_LOTOHI; //User defined
    in_config.hi_accuracy = true; //User defined
    in_config.is_watcher = false; //Don&amp;#39;t change this
    in_config.skip_gpio_setup = false; //Don&amp;#39;t change this

    //enable the pin for GPIOTE
    err_code = nrf_drv_gpiote_in_init(SPEEDO_TACHO_PIN_NUMBER, &amp;amp;in_config, speedo_tach_input_handler);
    APP_ERROR_CHECK(err_code);
    
    //setup a ppi channel to associate with the system_timer_cc_0_3 capture events
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;(ppi_channel[2]));
    APP_ERROR_CHECK(err_code);

    capture_task_addr = nrf_drv_timer_event_address_get(&amp;amp;system_timer_cc_0_3, NRF_TIMER_TASK_CAPTURE2);
    nrfx_gpiote_init(); 
    gpiote_task_addr = nrf_drv_gpiote_in_event_addr_get(SPEEDO_TACHO_PIN_NUMBER);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel[2],  gpiote_task_addr, capture_task_addr);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_enable(ppi_channel[2]);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_event_enable(SPEEDO_TACHO_PIN_NUMBER, true);

    //Once all system_timer_cc_0_3 shared peripherals are ready, enable the shared timer
    nrf_drv_timer_enable(&amp;amp;system_timer_cc_0_3);

}

void system_timer_cc_0_2_handler (nrf_timer_event_t event_type, void * p_context)
{
    volatile uint32_t pulseCount;
    switch(event_type)
    {
        case NRF_TIMER_EVENT_COMPARE1:                    // call when timer 2 overflows
            NRF_TIMER3-&amp;gt;TASKS_CAPTURE[2] = 1;             // This is asking to capture the current counter into CC[2]
            pulseCount = NRF_TIMER3-&amp;gt;CC[2];               // counter value  at the instant when capture task was triggered is now ready to be read in CC[2]
            period = (uint32_t) ((1.0 / (float)pulses) * 100000);
            timerSetCC1(PULSE_READ_INTERVAL);
            pulses = 0;
            break;
            
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/437068?ContentTypeID=1</link><pubDate>Tue, 18 Jul 2023 14:36:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f1e83d6-5329-4d65-a406-980520cfd023</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Both can work, but my suggestion was the second one.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/437045?ContentTypeID=1</link><pubDate>Tue, 18 Jul 2023 13:40:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:897facf7-2d55-45b3-89a3-3086bfd63594</guid><dc:creator>inspiringdev123</dc:creator><description>&lt;p&gt;Are you saying to set up Timer2 as a counter and use the app timer to check every 10ms? Or set up Timer 2 as a counter and then set up another hardware timer to check?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/436913?ContentTypeID=1</link><pubDate>Tue, 18 Jul 2023 08:19:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94565721-242b-499e-90c5-cc22b226e61d</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I unfortunately don&amp;#39;t have time to try out your code, but an alternative you may consider is to connect&amp;amp;use the pin as a counter for e.g. timer4, and then you only instead peridically check the counter value of timer4 from another timer (running of 16MHz clock, e.g. every 10ms) to find how many counts have elasped during the 10ms period.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/436827?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2023 16:02:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35d304fd-043d-4521-9afa-a3dca56bcf1e</guid><dc:creator>inspiringdev123</dc:creator><description>&lt;p&gt;Yes that is true. The issue starts to occur around 50 Hz and below. There is a single jumpy reading causing the RPM&amp;#39;s to spike, but then it recovers and stays consistent.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/436825?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2023 16:01:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82e9232f-2c24-474f-b901-857048ed4f08</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;And, just so I don&amp;#39;t misunderstand anything, you say that 10Hz is problematic while 100Hz is okey?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/436824?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2023 15:59:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9ce0977-b80f-4791-8ff2-99ab8edd61a5</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Can you just make a test code that continously read the input and write it on a different pin in a while loop? Just to see if that reveal anything?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/436816?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2023 15:17:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e662e19-2569-4581-a5b9-355a326e37fc</guid><dc:creator>inspiringdev123</dc:creator><description>&lt;p&gt;Did both to no avail&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer 2 Capture at Low Frequency Input</title><link>https://devzone.nordicsemi.com/thread/436811?ContentTypeID=1</link><pubDate>Mon, 17 Jul 2023 15:00:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f1a5798-7740-4fb3-bf8f-38788eda45a0</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I must admit I didn&amp;#39;t look much at the code, but&amp;nbsp;can you try to change the PRESCALER value and check if the threshold&amp;nbsp;moves with the PRESCALER value?&lt;/p&gt;
&lt;p&gt;Alternatively can you try to use 32-bit timer instead of 16-bit timer? See BITMODE register.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>