<?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>Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49987/configuring-nrf52840-for-counting-input-frequency-of-upto-5mhz</link><description>Hello, 
 I want to configure my nRF52840 development kit for counting input pulses on one of the GPIOs (Pin 13) in this case. I am using SEGGER Embedded Studio as IDE. 
 Here I am using PPI, GPIOTE and TIMER for this configuration. I have configured GPIOTE</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 19 Jul 2019 21:50:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49987/configuring-nrf52840-for-counting-input-frequency-of-upto-5mhz" /><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199606?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 21:50:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a58a0659-b955-43c9-a560-bf9ec50389a5</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Unfortunately, there&amp;#39;s no peripheral in nrf52 that is able to read parallel data and save it to RAM, you can only read GPIO register. This makes things more interesting )&amp;nbsp; If you&amp;#39;re lucky and CPU power will suffice, you can write a pure software routine in assembly that will do this task. All interrupts should be disabled for the time of reading a stream; if you need to hold a BLE connection, request a timeslot (see Timeslot API). Pass CLK signal through a flip-flop to divide its frequency by two - thus you&amp;#39;ll have to handle one CLK transition instead of rise+fall.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If data bus is connected to P1.0-P1.7, CLK to P1.8, the rough assembly routine will look like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;AcquireData
	ldr r1, P1_IN
	ldr r2, DestinationArray
	ldr r3, #(ByteCount/2)
wait1
	ldrb r0, [r1]
	tst r0, #(1 &amp;lt;&amp;lt; 8)   ; waiting for CLK transition 0-1
	beq wait1
	strb r0, [r2],#1
	subs r3, #1
wait2
	ldrb r0, [r1]
	tst r0, #(1 &amp;lt;&amp;lt; 8)   ; waiting for CLK transition 1-0
	bne wait2
	strb r0, [r2],#1
	cbnz r3, wait1
    bx lr&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199589?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 18:14:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eea07503-47f0-44e3-bb21-fa3ee6ed3454</guid><dc:creator>Aliasgar Surti</dc:creator><description>&lt;p&gt;The requirement goes like this. We want to capture parallel data from camera sensor.&lt;/p&gt;
&lt;p&gt;The data from the camera sensor would be in sync with pixel clock. And we have to sample the 8 bit data on one of the nRF IO port&amp;#39;s at every rising edge of the pixel clock. For our requirement, the pixel clock comes around 3-5MHz. This is the rate at which data would be coming to the kit.&lt;/p&gt;
&lt;p&gt;So in short, at every rising edge of the pulse, we want to get data from IO port and store it to an array or something.&lt;/p&gt;
&lt;p&gt;Is this possible by using task-event concept?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199554?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 13:36:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e1755d9-33fc-47e3-9003-1db721755afa</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;You mention that your input frequency is about 5 MHz (about 12 CPU cycles).&amp;nbsp;An interrupt requires 12 cycles for stacking + 12 cycles for unstacking + some time for your handling code. You have no CPU resources for your task...&amp;nbsp; but 52840 has a good task-event concept that allows to handle such cases directly by hardware. Could you give more details about required logic when you detect a pulse?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199542?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 13:02:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9dfdf23-d991-4120-9b7c-b2f88fac0003</guid><dc:creator>Aliasgar Surti</dc:creator><description>&lt;p&gt;Thanks for your reply.&lt;/p&gt;
&lt;p&gt;Now we&amp;nbsp;are able to count required frequency when we don&amp;#39;t trigger an interrupt on every pulse. Thanks to your suggestions.&lt;/p&gt;
&lt;p&gt;However, for our end goal, we want to perform some task/logic on every rising edge of the pulse which we counted. Without using interrupt it doesn&amp;#39;t seem to be achievable as due to interrupts, we are not able to count the input pulses accurately.&lt;/p&gt;
&lt;p&gt;Is there a way where we can achieve the end goal? Do we compulsorily need to use interrupt for performing some task when we detect rising edge or there is a way?&lt;/p&gt;
&lt;p&gt;Any logic or pseudo code or demo will be helpful here.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199513?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 11:47:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f8d51e4-4a6f-4596-9245-9b77f54637c8</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I suggest you try the workaround for Errata&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF52840_Rev2/ERR/nRF52840/Rev2/latest/anomaly_840_155.html?cp=3_0_1_0_1_10"&gt;[155] GPIOTE: IN event may occur more than once on input edge&lt;/a&gt;. By keeping the clock on you might be able to capture more level shifts.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Do you have a scope of the input signal at different frequencies? I want to see if the signal is capacitively loaded.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199493?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 10:44:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d24de078-8ce2-445a-9629-89e35dfc5f90</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;I didn&amp;#39;t suppose&amp;nbsp;you will get timer interrupt. Timer increments its value at GPIOTE event - why do you waste a lot of CPU cycles just to duplicate its work? When you need a counter value, call&amp;nbsp;nrf_drv_timer_capture(), say, to channel 1 and then read CC[1].&lt;/p&gt;
&lt;p&gt;Concerning frequency limit, maybe the answer from&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/18844/what-is-low-power-counter-mode"&gt;this&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/a&gt;thread will help:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;In the low power counter mode the hfclk is not requested until the COUNT task is trigerred, at that point the hfclk is requested for 1 clock clycle. So in practice this is a low power counter.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So for each COUNT event, timer will start hfclk, wait until it get stabilized, increment counter, then stop hfclk. Try to call&amp;nbsp;nrf_drv_clock_hfclk_request() at start, this will turn on hfclk forever (of course, power consumption will increase).&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199464?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2019 08:53:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09f011d7-464e-4450-80a6-f4903f9bf6b4</guid><dc:creator>Aliasgar Surti</dc:creator><description>&lt;p&gt;Thanks for your reply,&lt;/p&gt;
&lt;p&gt;No the requirement is not of getting interrupt at every 16th pulse. We want interrupt for every pulse so that counter can get increment and we get the frequency of the input signal.&lt;/p&gt;
&lt;p&gt;I tried you suggestion above. Also used&amp;nbsp;&lt;span&gt;nrf_drv_timer_capture() in the timer interrupt handler. However I am not getting timer interrupt. However I am getting GPIOTE interrupt here and its counter gets incremented. But as I stated previously, it can only count frequency up to 120kHz instead applying frequency of 3MHz on the gpio configured for GPIOTE.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Below are the changes we made as per your comment:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void timer0_event_handler(nrf_timer_event_t event_type, void * p_context)
{
    m_counter = nrf_drv_timer_capture(&amp;amp;m_timer0,NRF_TIMER_CC_CHANNEL0);
}

static void timer0_init(void)
{
    // Check TIMER0 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
    timer_cfg.mode = NRF_TIMER_MODE_LOW_POWER_COUNTER;
    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);
}

&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Are the changes made fine?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Why still I am not able to get timer interrupt? Is there any further configuration to be made?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If possible, is there any demo for counting pulses of 3MHz on GPIO pin of nRF52840 dev kit from which we can take reference from?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configuring nRF52840 for counting input frequency of upto 5MHz.</title><link>https://devzone.nordicsemi.com/thread/199328?ContentTypeID=1</link><pubDate>Thu, 18 Jul 2019 14:10:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:064de040-a60c-4dd3-9701-59a20d5a659d</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;hmm, you&amp;#39;re applying&amp;nbsp;&lt;span&gt;nrf_drv_timer_us_to_ticks() to a timer in counter mode... in fact, you&amp;#39;ll get&amp;nbsp; a value 16 here, so interrupt will be called for every 16th pulse, is this what you expected?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Instead of using interrupt,&amp;nbsp;you can&lt;span&gt;&amp;nbsp;&lt;/span&gt;configure a timer without CLEAR shortcut and read&lt;span&gt;&amp;nbsp;&lt;/span&gt;counter&lt;span&gt;&amp;nbsp;&lt;/span&gt;value directly from timer&amp;nbsp;with&amp;nbsp;&lt;span&gt;nrf_drv_timer_capture().&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>