<?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>Count Clock Pulses with PPI + Gpiote Then Change GPIO Depending on Count (NRF52810)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/38034/count-clock-pulses-with-ppi-gpiote-then-change-gpio-depending-on-count-nrf52810</link><description>I&amp;#39;m attempting to use PPI and Timer2 on the NRF52810 to count the clock pulses coming out of the SPIM driver. As there is no way to do this internally (as far as I know) I tied another GPIO pin to the clock pin. The idea being here is that I want to toggle</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 31 Aug 2018 07:37:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/38034/count-clock-pulses-with-ppi-gpiote-then-change-gpio-depending-on-count-nrf52810" /><item><title>RE: Count Clock Pulses with PPI + Gpiote Then Change GPIO Depending on Count (NRF52810)</title><link>https://devzone.nordicsemi.com/thread/146634?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 07:37:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f18a1c7-e3dd-433b-91f6-e454439ba6c0</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Oh, yes there are 4 per timer, I think you should be able to use compare0 register if you change the capture task to register 1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count Clock Pulses with PPI + Gpiote Then Change GPIO Depending on Count (NRF52810)</title><link>https://devzone.nordicsemi.com/thread/146628?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 07:26:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66f746a1-e532-449d-83ba-51db8ac05d68</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Thanks &lt;a href="https://devzone.nordicsemi.com/members/haakonsh"&gt;haakonsh&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I was under the impression that there were 4 capture/compare registers per timer. I&amp;#39;m actually using the first CC channel for PWM clock generation.&lt;br /&gt;&lt;br /&gt;Anyway thanks again for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count Clock Pulses with PPI + Gpiote Then Change GPIO Depending on Count (NRF52810)</title><link>https://devzone.nordicsemi.com/thread/146626?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 07:23:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2acb6087-0f34-4ecc-9b69-e8c16c838cb5</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Seems you figured it out while i was typing my reply, see me previous reply :3&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count Clock Pulses with PPI + Gpiote Then Change GPIO Depending on Count (NRF52810)</title><link>https://devzone.nordicsemi.com/thread/146624?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 07:20:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d62ef6ec-015d-4522-a52d-41dd1d187f9d</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;nrfx_timer_task_address_get(&amp;amp;m_counter, NRF_TIMER_TASK_CAPTURE0));&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I think you&amp;#39;ll need to use another capture register since you&amp;#39;re using capture/compare register 0 for the compare event. What I think is happening is that the compare register is overwritten at every clock cycle by the capture task. Why do you need to capture the timer value anyways? It will trigger a compare event when it reaches the value of the capture/compare register 0.&amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count Clock Pulses with PPI + Gpiote Then Change GPIO Depending on Count (NRF52810)</title><link>https://devzone.nordicsemi.com/thread/146623?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 07:18:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:feb7dad1-d662-48a1-b030-404e2275fb59</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Here&amp;#39;s the magic incantation that I found worked.&lt;/p&gt;
&lt;p&gt;The setup:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
  uint32_t err;

  // change to coutner
  nrfx_timer_config_t tmr_config = NRFX_TIMER_DEFAULT_CONFIG;
  tmr_config.mode = NRF_TIMER_MODE_COUNTER;
  tmr_config.bit_width = NRF_TIMER_BIT_WIDTH_32;

  // TODO: Configure counter. No timeout handler.
  err = nrfx_timer_init(&amp;amp;m_counter, &amp;amp;tmr_config, timer_handler_count);
  VERIFY_SUCCESS(err);

  // Input &amp;amp; output configuration
  nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
  nrfx_gpiote_out_config_t out_config =
      NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);

  // Init GPIO pins
  err = nrfx_gpiote_in_init(LIS2DH_INT_PIN, &amp;amp;in_config, clk_in_pin_handler);
  VERIFY_SUCCESS(err);

  err = nrfx_gpiote_out_init(LED_TRANS_PIN, &amp;amp;out_config);
  VERIFY_SUCCESS(err);

  // Enable tasks
  nrfx_gpiote_in_event_enable(LIS2DH_INT_PIN, false);
  nrfx_gpiote_out_task_enable(LED_TRANS_PIN);

  // Configure GPIO high on counter compare event
  err = nrfx_ppi_channel_alloc(&amp;amp;m_latch_in_channel);
  VERIFY_SUCCESS(err);

  // Configure output after counter compare
  err = nrfx_ppi_channel_alloc(&amp;amp;m_latch_out_channel);
  VERIFY_SUCCESS(err);

  // Assign the channel, input event, then counts the timer
  err = nrfx_ppi_channel_assign(
      m_latch_in_channel, nrfx_gpiote_in_event_addr_get(LIS2DH_INT_PIN),
      nrfx_timer_task_address_get(&amp;amp;m_counter, NRF_TIMER_TASK_COUNT));
  VERIFY_SUCCESS(err);

  // Sets the state of the trans pin after count compare
  err = nrfx_ppi_channel_assign(
      m_latch_out_channel,
      nrfx_timer_event_address_get(&amp;amp;m_counter, NRF_TIMER_EVENT_COMPARE1),
      nrfx_gpiote_out_task_addr_get(LED_TRANS_PIN));
  VERIFY_SUCCESS(err);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Using it:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;  // Enable these channels
  nrfx_ppi_channel_enable(m_latch_in_channel);
  nrfx_ppi_channel_enable(m_latch_out_channel);

  nrfx_gpiote_out_task_enable(LED_TRANS_PIN);

  // With reset.
  nrfx_timer_compare(&amp;amp;m_counter, NRF_TIMER_CC_CHANNEL1, 5, true);
  nrfx_timer_enable(&amp;amp;m_counter);
  nrfx_timer_clear(&amp;amp;m_counter);

  // The data!
  static uint8_t data[] = {0xaa, 0xaa};

  nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TX(data, 2);

  // Transfer test 16 bits
  nrfx_spim_xfer(&amp;amp;spi, &amp;amp;xfer_desc, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I was using the wrong compare event to toggle the output gpio. (should use&amp;nbsp;&lt;em&gt;nrfx_timer_event_address_get&lt;/em&gt;). To get the count I used this guy:&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;nrfx_timer_capture(&amp;amp;m_counter, NRF_TIMER_CC_CHANNEL1);&lt;/em&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Toggles at te 5th bit as expected. Though a little delayed.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1535699991386v1.png" alt=" " /&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>