<?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>nRF52 timer as counter, Adafruit Feather</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62633/nrf52-timer-as-counter-adafruit-feather</link><description>This question has been asked before. I have been using the previous threads to cobble together what is below. I opened a new ticket as reopening (really) old threads is generally frowned upon. I am trying to get the hardware counter of and nRF52 on an</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Jun 2020 11:23:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62633/nrf52-timer-as-counter-adafruit-feather" /><item><title>RE: nRF52 timer as counter, Adafruit Feather</title><link>https://devzone.nordicsemi.com/thread/255498?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 11:23:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e4c269b6-da19-4a23-86a4-d0bd8da2dae0</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;The TIMER, GPIOTE, and PPI peripherals are identical on the 832 and 840 so that&amp;#39;s a reasonable assumption.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 timer as counter, Adafruit Feather</title><link>https://devzone.nordicsemi.com/thread/255406?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 07:12:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9c49c57-b922-449c-815d-7594d7a7d1f5</guid><dc:creator>arlenn</dc:creator><description>&lt;p&gt;The above code has small problems, but I think the biggest problem was my misuse of the static variable.&amp;nbsp; I think the compiler should have probably complained but it didn&amp;#39;t.&amp;nbsp; So it is working. Yay.&lt;br /&gt;&lt;br /&gt;Below is the result.&amp;nbsp; This is tested working on an Adafruit Feather nRF25832, but should probably work on an 840 as well?&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define FREQ_MEASURE_PIN 7u
#define PPI_CHANNEL 1u

void setup() {
  Serial.begin(115200);
  pinMode(LED_RED, OUTPUT);
  initCounter();
}

void loop() 
{  
  readCounter();
  digitalToggle(LED_RED);
  delay(1000);
}

void readCounter()
{
  static int counts;
  NRF_TIMER2-&amp;gt;TASKS_CAPTURE[0] = 1;
  counts = NRF_TIMER2-&amp;gt;CC[0];
  Serial.print(&amp;quot;pulses: &amp;quot;); Serial.println(counts);
  //NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;                  
  //NRF_TIMER2-&amp;gt;TASKS_START = 1;
}

void initCounter()
{    
  NRF_P0-&amp;gt;PIN_CNF[FREQ_MEASURE_PIN] = GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos |
                                      GPIO_PIN_CNF_INPUT_Connect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos |
                                      GPIO_PIN_CNF_PULL_Pullup &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos |
                                      GPIO_PIN_CNF_SENSE_Low &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos;

  NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; PPI_CHANNEL;
  NRF_PPI-&amp;gt;CH[PPI_CHANNEL].EEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[PPI_CHANNEL];
  NRF_PPI-&amp;gt;CH[PPI_CHANNEL].TEP = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_COUNT;

  NRF_GPIOTE-&amp;gt;CONFIG[PPI_CHANNEL] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                    FREQ_MEASURE_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos |
                                    GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos; 

  NRF_TIMER2-&amp;gt;TASKS_STOP = 1;   
  NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;
  NRF_TIMER2-&amp;gt;MODE = TIMER_MODE_MODE_LowPowerCounter &amp;lt;&amp;lt; TIMER_MODE_MODE_Pos;
  NRF_TIMER2-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos;
  NRF_TIMER2-&amp;gt;TASKS_START = 1;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 timer as counter, Adafruit Feather</title><link>https://devzone.nordicsemi.com/thread/255341?ContentTypeID=1</link><pubDate>Tue, 16 Jun 2020 16:17:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fd30a4a-d31b-4bdb-8bfc-5ded5364ec58</guid><dc:creator>arlenn</dc:creator><description>&lt;p&gt;Thanks for your help.&amp;nbsp; I have actually tried it both ways.&amp;nbsp; There were examples showing both, but it is good to know it is required. adding the &amp;amp; doesn&amp;#39;t improve the situation in my case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 timer as counter, Adafruit Feather</title><link>https://devzone.nordicsemi.com/thread/255173?ContentTypeID=1</link><pubDate>Tue, 16 Jun 2020 08:28:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4699acd9-4ff3-446f-9666-bc14219c41f1</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;it seems the most common mistake when using PPI directly:&amp;nbsp;missing &amp;amp; operator&lt;/p&gt;
&lt;p&gt;NRF_PPI-&amp;gt;CH[6].EEP = (uint32_t) &lt;strong&gt;&amp;amp;&lt;/strong&gt;NRF_GPIOTE-&amp;gt;EVENTS_IN[6];&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>