<?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>How to correct the sampling time?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60466/how-to-correct-the-sampling-time</link><description>Dear everyone, 
 
 My platform is SDK16 and IDE is KEIL V5.25. 
 I set timer 2 to 104uS to sample a serial data. It isn&amp;#39;t UART data, no start bit and stop bit.The start bytes are 0x55,0x55,0x01,0x01. But The sample time and data rate aren&amp;#39;t very match</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 Apr 2020 03:15:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60466/how-to-correct-the-sampling-time" /><item><title>RE: How to correct the sampling time?</title><link>https://devzone.nordicsemi.com/thread/246954?ContentTypeID=1</link><pubDate>Tue, 28 Apr 2020 03:15:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ab7c52d-bfd0-48cc-8e9c-73d7eef01eb9</guid><dc:creator>Ted</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt; I change the mode of timer 2 to counter. But it cannot generate an interrupt. How to make it to generate an interrupt at count mode?&lt;/p&gt;
&lt;p&gt;void lf_rf_timer_init(void)&lt;br /&gt;{&lt;br /&gt; uint32_t err_code = NRF_SUCCESS;&lt;/p&gt;
&lt;p&gt;// setup timer parameter&lt;br /&gt; nrf_drv_timer_config_t timer_cfg = {&lt;br /&gt; .frequency = (nrf_timer_frequency_t)NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH, &lt;br /&gt; .mode = (nrf_timer_mode_t)&lt;strong&gt;NRF_TIMER_MODE_COUNTER,&lt;/strong&gt;&lt;br /&gt; .bit_width = (nrf_timer_bit_width_t)NRF_TIMER_BIT_WIDTH_32,&lt;br /&gt; .interrupt_priority = 5, // more high priority, default is 6&lt;br /&gt; .p_context = NULL&lt;br /&gt; };&lt;br /&gt; // setup timer 2 to count mode for RF sampling&lt;br /&gt; err_code = nrf_drv_timer_init(&amp;amp;m_timer2, &amp;amp;timer_cfg, m_timer2_event_handler);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;// RF data sample interrupt&lt;br /&gt; nrf_drv_timer_extended_compare(&lt;br /&gt; &amp;amp;m_timer2, NRF_TIMER_CC_CHANNEL0, nrf_drv_timer_us_to_ticks(&amp;amp;m_timer2, us), NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);&lt;br /&gt; nrf_drv_timer_enable(&amp;amp;m_timer2);&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to correct the sampling time?</title><link>https://devzone.nordicsemi.com/thread/245979?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 09:03:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fc85656-0396-48d5-8c3d-d1ab0ce709bd</guid><dc:creator>Ted</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt; The unit of timer library is in mini-second. I cannot use timer library, because my sample time is 104uS. It more faster than the functions they was provided by timer library. I change&amp;nbsp;&lt;span&gt;TIMER2-&amp;gt;CC register and set it back to 0x680 (104uS) for next sampling. The data still cannot be read correctly. The duration between gpio interrupt generates and interrupt service subroutine is around 20uS. So change the register of NRF_TIMER2-&amp;gt;CC cannot sample data at 104us correctly. Do you have any suggestions?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;void tda5235_sample_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)&lt;br /&gt;{&lt;br /&gt; NRF_TIMER2-&amp;gt;CC[0] = 0x240;&amp;nbsp; &amp;nbsp; &amp;nbsp;// --&amp;gt; correct time, after falling edge of data.&lt;br /&gt; NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt; lf_rf_task.items.rewrite_sample_time = 1;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;void m_timer2_event_handler(nrf_timer_event_t event_type, void* p_context)&lt;br /&gt;{&lt;br /&gt; if(lf_rf_task.items.rewrite_sample_time == 1)&lt;br /&gt; {&lt;br /&gt; NRF_TIMER2-&amp;gt;CC[0] = 0x680;&amp;nbsp; &amp;nbsp;//set it back to 0x680 (104uS)&lt;br /&gt; NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt; lf_rf_task.items.rewrite_sample_time = 0;&lt;br /&gt; &lt;/span&gt;&lt;span&gt;......&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to correct the sampling time?</title><link>https://devzone.nordicsemi.com/thread/245973?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 08:45:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6a36c74-872a-4e4a-baf4-a30f8a4986ce</guid><dc:creator>Ted</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt; The unit of timer library is in mini-second. I cannot use timer library, because my sample time is 104uS. It more faster than the functions they was provided by timer library. I change&amp;nbsp;&lt;span&gt;TIMER2-&amp;gt;CC register and set it back to 0x680 (104uS) for next sampling. The data still cannot be read correctly. Do you have any suggestions?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;void tda5235_sample_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)&lt;br /&gt;{&lt;br /&gt; NRF_TIMER2-&amp;gt;CC[0] = 0x240;&amp;nbsp; &amp;nbsp; &amp;nbsp;// --&amp;gt; correct time, after falling edge of data.&lt;br /&gt; NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt; lf_rf_task.items.rewrite_sample_time = 1;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;void m_timer2_event_handler(nrf_timer_event_t event_type, void* p_context)&lt;br /&gt;{&lt;br /&gt; if(lf_rf_task.items.rewrite_sample_time == 1)&lt;br /&gt; {&lt;br /&gt; NRF_TIMER2-&amp;gt;CC[0] = 0x680;&amp;nbsp; &amp;nbsp;//set it back to 0x680 (104uS)&lt;br /&gt; NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt; lf_rf_task.items.rewrite_sample_time = 0;&lt;br /&gt; &lt;/span&gt;&lt;span&gt;......&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to correct the sampling time?</title><link>https://devzone.nordicsemi.com/thread/245848?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 13:17:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b753e7f-dc78-4080-954b-393e6d8c0db0</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Ted,&lt;/p&gt;
&lt;p&gt;I think you misunderstood how the Timer works.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void tda5235_sample_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    NRF_TIMER2-&amp;gt;TASKS_COUNT = 100; //  it is ineffective.
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;TASKS_COUNT does not take the count of the counter to a number after which you expect a timeout. All TASKS_XXX in the nRF device only take a value of 1. It means that for 1, trigger that particular task. When you are writing 100 to TASKS_COUNT you are basically trying to write binary&amp;nbsp;1100100 into it. Since it is only 1 bit register, you are effectively writing 0 into it. And this TASKS only work in COUNTER mode.&lt;/p&gt;
&lt;p&gt;I guess what you are trying to do is to get a timer callback after 100 ticks. If that is what you are trying to do then probably you need to set this in TIMER2-&amp;gt;CC register and restart the timer.&lt;/p&gt;
&lt;p&gt;I strongly suggest you not to access the registers of the timers directly and use the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Flib_timer.html&amp;amp;cp=7_1_3_52"&gt;timer library&lt;/a&gt;&amp;nbsp;instead.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>