<?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>Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84434/frequency-counter-on-nrf52805</link><description>Hi, I want to use an NRF52805 with a voltage to frequency detector. If I understand the datasheet, there is one timer/counter and RTC on that chip. Is it possible to set the RTC as the timing gate, and use the T/C as an input pulse counter through the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Mar 2022 11:49:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84434/frequency-counter-on-nrf52805" /><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/355523?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 11:49:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ef064df-de8f-4159-bdad-fd9145fbf8f8</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;To add a figure/image to a DevZone reply, go to the Insert dropdown menu, choose &amp;quot;Image/Video/File&amp;quot; and press the &amp;quot;Upload&amp;quot; button. I&amp;#39;ve experienced that users before hasn&amp;#39;t realized that this is a button.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1646128134133v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;It seems like you&amp;#39;re mixing the nRFConnect SDK and the nRF5 SDK code structures quite a bit in your example project, which is likely what&amp;#39;s causing trouble for you. As the nRFConnect SDK is RTOS based there will be quite a few changes from the old SDK. If you&amp;#39;re new to the nRFConnect SDK I would suggest checking out &lt;a href="https://devzone.nordicsemi.com/nordic/b/archives/posts/nrf-connect-sdk-tutorial---part-1-ncs-v1-4-0"&gt;this tutorial series&lt;/a&gt;&amp;nbsp;to get familiar if that&amp;#39;s the case.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/355214?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 10:13:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c307acf-cb34-462c-a92a-83bda080a1dd</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;Thanks for the reply.&lt;/p&gt;
&lt;p&gt;As you can see from above, it seems as if it&amp;#39;s actually the fact that the clock defaults to an RF based one, rather than the crystal clock. It makes sense since with GPIOTE and PPI,&amp;nbsp;&lt;strong&gt;all the counting operation is done in hardware&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I really wish I could figure out how to attach a figure to a post here. Essentially, what I do is:&lt;/p&gt;
&lt;p&gt;1) Timer1 is a timer that generates a 1s &amp;quot;enable window&amp;quot;. Timer 2 is a counter.&lt;/p&gt;
&lt;p&gt;2) I do so by attaching in PPI counter2&amp;#39;s &amp;quot;start&amp;quot; to a compare value &amp;quot;1&amp;quot; of timer1, and attaching its &amp;quot;stop&amp;quot; to a compare value of&amp;nbsp; &amp;quot;62501&amp;quot; - one beyond 1s in my clock source setting.&lt;/p&gt;
&lt;p&gt;3) Once a count within a frame of 1s finishes, The compare of the &amp;quot;enable window&amp;quot; end triggers an interrupt. However, do notice that the timing of this interrupt isn&amp;#39;t critical. The counter is stopped anyway, and a winding of timer1 will not happen for a while, so interrupt priority isn&amp;#39;t a big issue.&lt;/p&gt;
&lt;p&gt;4) I do need to stress out that despite it not being reported, the imprecise counting of signals above ~750KHz (1.3us) requires a walkaround. Here also syntax is slightly different from documentation:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;*(&lt;/span&gt;&lt;span&gt;volatile&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;uint32_t&lt;/span&gt;&lt;span&gt;&amp;nbsp;*)(NRF_GPIOTE_BASE +&amp;nbsp;&lt;/span&gt;&lt;span&gt;0x600&lt;/span&gt;&lt;span&gt;&amp;nbsp;+ (&lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;span&gt;&amp;nbsp;* &lt;strong&gt;NRFX_GPIOTE_CHANNELS_USED&lt;/strong&gt;)) =&amp;nbsp;&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also, the syntax to request the HFCLK is different for nRF connect (VS NRF51).&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/355177?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 08:08:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9070d1dc-392d-4cd6-b757-e4095eb64d1c</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Sorry about the late reply.&lt;/p&gt;
&lt;p&gt;Yes sorry, it shouldn&amp;#39;t be a HW issue since you&amp;#39;re using the nRF52 DK for development. Glad to hear you were able to improve the rate somewhat.&lt;/p&gt;
&lt;p&gt;Regarding the RC clock source, this is a LF clock source, but either way the external LF clock will be used by default when using the nRF52 DK.&lt;/p&gt;
&lt;p&gt;What pins are you using for the RTC in the BLE_NUS application? I&amp;#39;m guessing that the fluctuations you&amp;#39;re seeing are affected by the SoftDevice having a higher priority than the RTC peripheral, you can try &lt;a href="https://infocenter.nordicsemi.com/topic/sds_s140/SDS/s1xx/processor_avail_interrupt_latency/exception_mgmt_sd.html"&gt;increasing the priority&lt;/a&gt; level of your RTC if it is time critical. (interrupt level 2 or 3 is the highest allowed for peripherals).&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/355168?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 07:03:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80f89283-906a-4f7f-a06a-d1c0be41271e</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;Excellent suggestion! I didn&amp;#39;t understand that by default the crystal source might be unused..&lt;/p&gt;
&lt;p&gt;OK, I *think* I sorted this out. I was using a previous example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1; //Start high frequency clock
	while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0)
	{
		//Wait for HFCLK to start
	}
	NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0; //Clear event&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and assumed that this will force start the crystal clock. For some reason it doesn&amp;#39;t. Online I saw that is NRF51 this was recommended to do with&amp;nbsp;sd_clock_hfclk_request();&lt;/p&gt;
&lt;p&gt;***annoyingly*** the nRF connect SDK API is different and ***undocumented***. Neither are examples nor explanations in the API that does exist what the sd request has turned into.&lt;/p&gt;
&lt;p&gt;What did it for me is putting in my main() function (after BT and uart service have started) the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;mpsl_clock_hfclk_request(&amp;amp;hfclk_started_callback);
	uint32_t is_running = 0;
	while (is_running==0){
	mpsl_clock_hfclk_is_running(&amp;amp;is_running);
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This requires a definition of cb function (I put it before main())&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void hfclk_started_callback(){

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I then used an Arduino configured as a clock source (WITH A RESISTIVE DIVIDER! IT&amp;#39;S WORKING AT 5V, DONT BURN YOUR INPUT PIN!) as follows (this is the Arduino code):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;const int freqOutputPin = 9;   // OC1A output pin for ATmega32u4 (Arduino Micro)
const int ocr1aval  = 7; 

void setup()
{
    pinMode(freqOutputPin, OUTPUT);
    
    TCCR1A = ( (1 &amp;lt;&amp;lt; COM1A0));
   
    TCCR1B = ((1 &amp;lt;&amp;lt; WGM12) | (1 &amp;lt;&amp;lt; CS10));

    TIMSK1 = 0;
    
    OCR1A = ocr1aval;    
}

void loop()
{
   
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Results over 400 samples with 1MHz clock input&lt;/p&gt;
&lt;p&gt;Before requesting HF clock: Average Frequency&amp;nbsp;997968.1Hz, STDEV=277.6Hz (ppm)&lt;/p&gt;
&lt;p&gt;&lt;span&gt;After requesting HF clock: Average Frequency 999351.7&lt;/span&gt;&lt;span&gt;Hz, STDEV=&lt;strong&gt;0.45Hz&lt;/strong&gt; (ppm)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;FYI&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/355163?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 04:06:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4849ded7-dfcd-4fc3-be4d-4625a47060a7</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;Isn&amp;#39;t the BT uart example using the DK52&amp;#39;s HS crystal by default? What is the procedure to switch?&lt;/p&gt;
&lt;p&gt;Tnx&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/355150?ContentTypeID=1</link><pubDate>Sun, 27 Feb 2022 21:56:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df13093a-a2d0-4008-b178-59a52014abbf</guid><dc:creator>Daniel Chisholm</dc:creator><description>&lt;p&gt;If you are getting wild variations, make sure you are using crystal (HFCLK I think?) not RC as your high speed clock source.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/355140?ContentTypeID=1</link><pubDate>Sun, 27 Feb 2022 14:02:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0819e9a0-b8e9-4e61-a4d9-1d3b35fed434</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;Well.. partial success in timing improvement. Apparently the errata that&amp;#39;s relevant to NRF52840 is relevant for NRF52810, and I assumed that it will also hold here.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Ferrata_nRF52840_Rev2%2FERR%2FnRF52840%2FRev2%2Flatest%2Fanomaly_840_155.html&amp;amp;cp=3_0_1_0_1_10"&gt;Nordic Semiconductor Infocenter&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I added this to main:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;//solve errata for event above 750khz&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; *(&lt;/span&gt;&lt;span&gt;volatile&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint32_t&lt;/span&gt;&lt;span&gt; *)(NRF_GPIOTE_BASE + &lt;/span&gt;&lt;span&gt;0x600&lt;/span&gt;&lt;span&gt; + (&lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;span&gt; * NRFX_GPIOTE_CHANNELS_USED)) = &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Now I can measure up to about 3.7MHz accurately, and above 4MHz The count becomes inaccurate, but not zero anymore.&amp;nbsp;&lt;/span&gt;Still a bit low as Arduino can do up to 5MHz with a 16MHz clock (FreqCount library).&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;What baffles me is that I now ported this code to a BLE app with NUS, and I&amp;#39;m getting very inaccurate counts. A dead-on 1MHz source is counted as ~1028000 with large variations. With just the counter code the count was at a steady 1MHz. What&amp;#39;s going on? this is supposed to be a purely HW counter implementation.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Any help will be greatly appreciated.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Cheers!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/354746?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 09:29:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42deb973-6a3f-43bb-a4b5-07beda150792</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;Hi Simon, thanks again for the reply.&lt;/p&gt;
&lt;p&gt;I am not using any hardware, just the nrf52-DK, with a wire connecting directly the clock-gen pin to the counter pin.. no need to review anything since it&amp;#39;s your kit..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/354723?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 07:31:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc5b765e-f97a-4582-aa27-493d82299aea</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;1. I see. Sorry, I didn&amp;#39;t catch that in your last reply. Do you get any error messages when setting this value to less than 3?&lt;/p&gt;
&lt;p&gt;2. If you&amp;#39;d like, we can do a HW review of your design for you to make sure that your design doesn&amp;#39;t have any obvious issues. You can create a private ticket and upload schematics and gerber files, and we&amp;#39;ll get right on it.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/354372?ContentTypeID=1</link><pubDate>Tue, 22 Feb 2022 13:43:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77207715-3302-45db-b7f4-14e597ba681b</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks, I know. My point was that if I change the compare value to less than 3, the count value shows always zero.&lt;/p&gt;
&lt;p&gt;I looked in the nrf52-DK schematic files and couldn&amp;#39;t find anything that would suggest why this would occur. I&amp;#39;ve also moved the test clock pin to p0.12 to shorten the line and avoid LED load, to no avail. I will check with an oscilloscope once I can. In the meantime any insights will be welcome!&lt;/p&gt;
&lt;p&gt;Thanks again&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/354308?ContentTypeID=1</link><pubDate>Tue, 22 Feb 2022 10:38:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c47fea7-7182-4d15-8aeb-e46a49f8805c</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;4. It seems like NRF_TIMER0-&amp;gt;CC[0] is set to 3, which I think will set the timer to run at 8/3 MHz. Can you try tweaking this to 1 for example? Where exactly did you find this gpio_clock_8m() function? It doesn&amp;#39;t seem familiar and I can&amp;#39;t find it in the nRFConnect nor nRF5 SDKs.&lt;/p&gt;
&lt;p&gt;5. I&amp;#39;m sorry you&amp;#39;re having trouble, what IDE are you using exactly, Visual Studios Code&amp;nbsp;or SEGGER Embedded Studios? We&amp;#39;re constantly working on adding more sample projects and drivers to the nRF Connect SDK and are striving to make it as user friendly as possible.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/354224?ContentTypeID=1</link><pubDate>Mon, 21 Feb 2022 20:22:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9ef73e0-4246-4b05-aa3e-73c96d3a39f5</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;OK. I think I got the thing working, might be just good enough for my purpose:&lt;/p&gt;
&lt;p&gt;1. I took the aforementioned example and made a simple change: I basically have gate start and end capture values for Timer1. These events trigger counter2 start/stop, respectively.&lt;/p&gt;
&lt;p&gt;2. This way, the measurement is purely hardware. Result read is done in interrupt, but that doesn&amp;#39;t really matter, as it&amp;#39;s executed after count is done.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3. I&amp;#39;m attaching the example I&amp;#39;ve made if anyone is interested. It includes another pin that generates an output for testing (below). Tested on NRF-connect desktop, VS code, 1.9.0&lt;/p&gt;
&lt;p&gt;4. For some reason, &lt;strong&gt;I&amp;#39;m only able to capture up to 2.66MHz (8/3). Any guess why&lt;/strong&gt;? I can&amp;#39;t see why it would be a hardware limitation, and supposedly nothing is done in software, but I&amp;#39;ll have another look.&lt;/p&gt;
&lt;p&gt;5. Regarding IDE. I&amp;#39;m very new to working with NRF products and I am EXTREMELY frustrated with the API. The samples are lacking, many samples don&amp;#39;t support many boards, and the API has zero documentation. This results reverting mainly to NRF5-based examples which only add to the confusion. I hope that the IDE will become more friendly in the future.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 * Copyright (c) 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @file Sample app to demonstrate PWM.
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;

#define TST_CLK_PIN 17 //this is led 0 pin on nrf52-dk
#define FREQ_MEASURE_PIN 11

void gpio_clock_8m(uint32_t pin_number)
{
    
    NRF_TIMER0-&amp;gt;PRESCALER = 0; // 16MHz
    NRF_TIMER0-&amp;gt;SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;
    NRF_TIMER0-&amp;gt;CC[0] = 3; //1 for 16/2=8MHz for, 2 for 8/2=4MHz, 4 for 4/2=2MHz etc..
	NRF_TIMER0-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_16Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);	
	//using config [1] since [0]
    NRF_GPIOTE-&amp;gt;CONFIG[1] = GPIOTE_CONFIG_MODE_Task | (pin_number &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos) |
                            (GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos);

    /*Connect TIMER event to GPIOTE out task*/
	NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; 3;
    *(&amp;amp;(NRF_PPI-&amp;gt;CH3_EEP)) = (uint32_t) &amp;amp;NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0];
    *(&amp;amp;(NRF_PPI-&amp;gt;CH3_TEP)) = (uint32_t) &amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[1];
    NRF_PPI-&amp;gt;CHENSET |= 1 &amp;lt;&amp;lt; 3;

    /*Starts clock signal*/
    NRF_TIMER0-&amp;gt;TASKS_START = 1;
}

static void timer_init() //gate timer
{
	NRF_TIMER1-&amp;gt;TASKS_STOP = 1; //trigger stop
	NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Timer; //mode timer
	NRF_TIMER1-&amp;gt;PRESCALER = 8;	// Fhck / 2^8 
	//total gate time of timer 62500 - 1s
	NRF_TIMER1-&amp;gt;CC[0] = 62501;	//end gate count
	NRF_TIMER1-&amp;gt;CC[1] = 1;	//start gate count. don&amp;#39;t start at 0 to no start on clear.
	
	NRF_TIMER1-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_16Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);	
	
	NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1; //trigger zero timer
	NRF_TIMER1-&amp;gt;INTENSET = (TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos); //interrupt on end gate count
	
	NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0; //rest event flag for gate end
	NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1] = 0; //rest event flag for gate start
}

static void counter_init() //actual counter
{
	NRF_TIMER2-&amp;gt;TASKS_STOP = 1;	//trigger stop
	NRF_TIMER2-&amp;gt;MODE = TIMER_MODE_MODE_Counter; //counter
	NRF_TIMER2-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_24Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);
	NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1; //trigger zero counter
	NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0; //reset event for compare
}

//counter input pin setting
static void gpiote_init(uint32_t pin)
{
	NRF_GPIOTE-&amp;gt;CONFIG[0] 	= 	0x01 &amp;lt;&amp;lt; 0; 								// MODE: Event
	NRF_GPIOTE-&amp;gt;CONFIG[0] 	|= 	pin &amp;lt;&amp;lt; 8;								// Pin number
	NRF_GPIOTE-&amp;gt;CONFIG[0] 	|= 	GPIOTE_CONFIG_POLARITY_LoToHi	&amp;lt;&amp;lt; 16;		// Event rising edge 	
}

//hardware trigger: stop of counter on event of end timer1 gate
static void ppi_timer_stop_counter_init()
{
	NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; 2; //channel
	*(&amp;amp;(NRF_PPI-&amp;gt;CH2_EEP)) = (uint32_t)&amp;amp;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0]; //attach end gate event
	*(&amp;amp;(NRF_PPI-&amp;gt;CH2_TEP)) = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_STOP; //to counter stop trigger
	NRF_PPI-&amp;gt;CHENSET |= 1 &amp;lt;&amp;lt; 2; //set channel
}

//hardware trigger: start of counter on event of begin timer1 (gate) event.gate
static void ppi_timer_start_counter_init()
{
	NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; 4;// channel
	*(&amp;amp;(NRF_PPI-&amp;gt;CH4_EEP)) = (uint32_t)&amp;amp;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1]; //attach gate start event
	*(&amp;amp;(NRF_PPI-&amp;gt;CH4_TEP)) = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_START; //to counter start trigger
	NRF_PPI-&amp;gt;CHENSET |= 1 &amp;lt;&amp;lt; 4;
}


static void ppi_gpiote_counter_init()
//hardware attachment for the gpiote that was selected above
{
	NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; 1;
	*(&amp;amp;(NRF_PPI-&amp;gt;CH1_EEP)) = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[0]; //attach pin change
	*(&amp;amp;(NRF_PPI-&amp;gt;CH1_TEP)) = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_COUNT;//to one count
	NRF_PPI-&amp;gt;CHENSET |= 1 &amp;lt;&amp;lt; 1;
}

//gate end interrupt handler. Count is done at hardware and percice interrupt execution isnt critical
void TIMER1_IRQHandler(void) 
{
	if (NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] != 0) //end gate event
	{
		NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0; //reset end gate flag
		NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1] = 0; //reset start gate flag
		NRF_TIMER2-&amp;gt;TASKS_CAPTURE[0] = 1; //trigger get counter value
				
		printk(&amp;quot;cc: %dHz\n&amp;quot;, NRF_TIMER2-&amp;gt;CC[0]); //report to serial console
      	
		NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1; //reset timer
		NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1; //reset counter
						
		NRF_TIMER1-&amp;gt;TASKS_START = 1; //start next count gate		
    }
}

void main(void)
{
	NVIC_EnableIRQ(TIMER1_IRQn); //enable timer1 interrupt
	IRQ_DIRECT_CONNECT(TIMER1_IRQn, 3, TIMER1_IRQHandler, 0); //link interrupt flag to handler
    NVIC_SetPriority(TIMER1_IRQn, 3); //set interrupt execution priority

	struct device *dev;//port container for gpio management
	dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;); //on nrf52805 all GPIOs are on port0
	/**/
	gpio_pin_configure(dev, FREQ_MEASURE_PIN, GPIO_INPUT|GPIO_ACTIVE_HIGH|GPIO_PULL_DOWN); //p0.11 freq in

	//init freq count hardware
	counter_init();
	timer_init();
	gpiote_init(FREQ_MEASURE_PIN);
	ppi_gpiote_counter_init();
	ppi_timer_stop_counter_init();
	ppi_timer_start_counter_init();

	//test clock hardware
	gpio_clock_8m(TST_CLK_PIN);

	//start freq count task
	NRF_TIMER1-&amp;gt;TASKS_START = 1;
	while (1) {
				//manage loop
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/354180?ContentTypeID=1</link><pubDate>Mon, 21 Feb 2022 14:21:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f67e07a1-05f0-4041-8768-c3a9ce1da5af</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see why what you describe can&amp;#39;t be done at least, just make sure you mark the timers/counters with different priorities so they won&amp;#39;t be conflicting with one another. The PPI example in the DevZone ticket you linked to is more than 6 years old at this point, and is therefore older than the nRF52805 altogether, so the SDK used there will not be compatible with your nRF52805. It&amp;#39;s fine if you want to use the nRF5 SDK rather than the nRFConnect SDK, as the nRF52 series are supported by both, so it depends on what you want. You can se&lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/nrf-connect-sdk-and-nrf5-sdk-statement"&gt;e this statement&lt;/a&gt; on the state of the two SDKs.&lt;/p&gt;
&lt;p&gt;If you decide to go for the nRF5 SDK, you will need to use a newer version (I recommend v17.1.0) but you can use the same principles explained by Susheel in the old thread if you find it helpful.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/353996?ContentTypeID=1</link><pubDate>Sat, 19 Feb 2022 21:18:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df9796de-ac23-4a28-a382-2e847c582781</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;OK, a few days with an NRF52-DK at hand I have a few more questions:&lt;/p&gt;
&lt;p&gt;1. I see that there is a guy who did implement a counter similarly to what I want, using 2xtimers, events, tasks, and ppi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/9036/measuring-input-gpio-pin-frequency-with-soft-device-running"&gt;here&lt;/a&gt;. I&amp;#39;m not 100% OK with the solution since: (a) the tasks of the counter and timer are both started from main. This does not guarantee a consistent timing for the counter and gate functions. (b) Likewise counter is read from a timer interrupt.&lt;/p&gt;
&lt;p&gt;2. What i&amp;#39;d like to do is as follows: (a) Clear Timer0 -&amp;gt; (b) on Timer0 start generate event to start Counter1 -&amp;gt; (c) On Timer0 CC generate event to stop counter -&amp;gt; (d) on stop Counter1 generate event to stop Timer0&lt;/p&gt;
&lt;p&gt;3. Can this be done? i.e. can I generate an event on Timer0 start and link it to Counter1 start? Also, can (d) be done? I have nothing against generating events (c) and (d) together from Timer0 CC with FORK if its easier.&lt;/p&gt;
&lt;p&gt;4. I noticed that the ppi example that I attached above can&amp;#39;t locate the required ENUMs, unless I add #include&amp;lt;hal/nrf_gpiote.h&amp;gt;. Should I use this piece of code? I am using VS code on NRF connect and had problems utilyzing the ADC when I inclused &amp;lt;hal/nrf_saadc.h&amp;gt;. If not, is there a good PPI/EVENT example for nrf connect?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any help will be appreciated!&lt;/p&gt;
&lt;p&gt;Matan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/351544?ContentTypeID=1</link><pubDate>Mon, 07 Feb 2022 13:09:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2456d022-2e7f-439d-8a31-83dfaff42dbc</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Indeed, the nRF52805 has 3 32-bit timers with counter mode and 2 RTCs available. If you see section &lt;strong&gt;4.2.4 Instantiation&amp;nbsp;&lt;/strong&gt;in the&lt;a href="https://infocenter.nordicsemi.com/pdf/nRF52805_PS_v1.3.pdf"&gt; product specification&lt;/a&gt; you can see what base addresses they use, so there should be no issues using two timers in your application.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Frequency counter on NRF52805</title><link>https://devzone.nordicsemi.com/thread/351430?ContentTypeID=1</link><pubDate>Sun, 06 Feb 2022 11:02:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:863481b5-63d6-4c55-9cb6-3ce11cf7920b</guid><dc:creator>matangk</dc:creator><description>&lt;p&gt;OK... following more replies I see that this IC should have 3 timer/counters and 2 RTCs. Can someone please confirm that 2 Timer/Counters can be configured, one as a gate and one as a pulse counter to perform this task?&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>