<?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>issue with timer interrupt handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/107132/issue-with-timer-interrupt-handler</link><description>Hi there, 
 please find the code 
 void Timer0Handler(nrf_timer_event_t event_type, void* p_context) { switch (event_type) { case NRF_TIMER_EVENT_COMPARE0: ++m_currentTick.l; //SigGenUpdate(); nrf_gpio_pin_toggle(MCU_MCU_BRIDGE_EN_PIN); break; case NRF_TIMER_EVENT_COMPARE1</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 08 Jan 2024 12:33:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/107132/issue-with-timer-interrupt-handler" /><item><title>RE: issue with timer interrupt handler</title><link>https://devzone.nordicsemi.com/thread/463134?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2024 12:33:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5e7ae5b-bf85-44ff-93a6-9dc619bb8869</guid><dc:creator>Saiteja_v</dc:creator><description>&lt;p&gt;Thanks for the update.&lt;/p&gt;
&lt;p&gt;Thanks for the detailed explanation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issue with timer interrupt handler</title><link>https://devzone.nordicsemi.com/thread/463099?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2024 10:26:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e50af504-d54d-42b3-91b4-b4ff2b1261bb</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is not possible to get interrupt from ticks2 every 51us and still get interrupt from tick1 at 1ms, the timer will be running from 0 (cleared) until it hits the given CC to generate compare event. If you want a new compare event to happen 51us in the future after COMPARE1, you need to set a new compare value at ticks_COMPARE1 + ticks_51us. You can set the new CC value in the same compare channel, or use one of the other available channels. Note that once you hit COMPARE0 (1ms) and you clear the timer, you also need to reset CC1 to get 51us interrupt (might cause jitter as 1ms is not exactly dividable by 51us). Interrupt latency might affect the accuracy of the 51us interrupt, and this will take much CPU time to run the handler this often.&lt;/p&gt;
&lt;p&gt;An example, let&amp;#39;s say the timer runs at 1MHz:&lt;/p&gt;
&lt;p&gt;Initial:&amp;nbsp;CC0=1000 (1ms),&amp;nbsp;CC1=51 (51us)&lt;br /&gt;First interrupt (COMPARE1 - 51us): Update CC1 to 102 (51us + 51us)&lt;br /&gt;Second interrupt&amp;nbsp;&lt;span&gt;(COMPARE1 - 102us):&lt;/span&gt; &lt;span&gt;Update CC1 to 153 (51us + 51us&amp;nbsp;+ 51us)&lt;br /&gt;&lt;/span&gt;&lt;span&gt;...&lt;br /&gt;&lt;/span&gt;&lt;span&gt;19th interrupt (COMAPRE1 - 969us):&amp;nbsp;Update CC1 to&amp;nbsp;20 (20 * 51us - 1ms)&lt;br /&gt;&lt;/span&gt;&lt;span&gt;20th interrupt (COMPARE0 - 1ms): Clear timer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issue with timer interrupt handler</title><link>https://devzone.nordicsemi.com/thread/463049?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2024 04:29:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74458b4f-a9df-4f11-bb0c-3b11f9c89aba</guid><dc:creator>Saiteja_v</dc:creator><description>&lt;p&gt;&lt;strong&gt;Method-1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;void InitTimers(void)&lt;br /&gt;{&lt;br /&gt; uint32_t ticks1;&lt;br /&gt; uint32_t ticks2;&lt;br /&gt; uint32_t err_code = NRF_SUCCESS;&lt;br /&gt; m_currentTick.l = 0;&lt;/p&gt;
&lt;p&gt;nrfx_timer_config_t timer0_cfg = NRFX_TIMER_DEFAULT_CONFIG;&lt;br /&gt; timer0_cfg.frequency = NRF_TIMER_FREQ_16MHz;&lt;br /&gt; err_code = nrfx_timer_init(&amp;amp;timer0, &amp;amp;timer0_cfg, Timer0Handler);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;ticks1 = nrfx_timer_ms_to_ticks(&amp;amp;timer0, TIME(0.001));&lt;br /&gt; ticks2 = nrfx_timer_us_to_ticks(&amp;amp;timer0, TIME(0.051));&lt;/p&gt;
&lt;p&gt;nrfx_timer_extended_compare(&lt;br /&gt; &amp;amp;timer0, NRF_TIMER_CC_CHANNEL1, ticks1,NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);&lt;br /&gt;// &lt;br /&gt; nrfx_timer_compare(&lt;br /&gt; &amp;amp;timer0, NRF_TIMER_CC_CHANNEL2, ticks2,true);&lt;br /&gt; &lt;br /&gt; nrfx_timer_enable(&amp;amp;timer0);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;if iam using this kind of code iam getting both the frequencies are same.&lt;/p&gt;
&lt;p&gt;the output of tick1 is acquiring by tick2&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1704688002208v7.jpeg" /&gt;&lt;/p&gt;
&lt;p&gt;please find the output in the CRO iam toggling pin in the interrupt handler.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Method-2&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;void InitTimers(void)&lt;br /&gt;{&lt;br /&gt; uint32_t ticks1;&lt;br /&gt; uint32_t ticks2;&lt;br /&gt; uint32_t err_code = NRF_SUCCESS;&lt;br /&gt; m_currentTick.l = 0;&lt;/p&gt;
&lt;p&gt;nrfx_timer_config_t timer0_cfg = NRFX_TIMER_DEFAULT_CONFIG;&lt;br /&gt; timer0_cfg.frequency = NRF_TIMER_FREQ_16MHz;&lt;br /&gt; err_code = nrfx_timer_init(&amp;amp;timer0, &amp;amp;timer0_cfg, Timer0Handler);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;ticks1 = nrfx_timer_ms_to_ticks(&amp;amp;timer0, TIME(0.001));&lt;br /&gt; ticks2 = nrfx_timer_us_to_ticks(&amp;amp;timer0, TIME(0.051));&lt;/p&gt;
&lt;p&gt;nrfx_timer_compare(&lt;br /&gt; &amp;amp;timer0, NRF_TIMER_CC_CHANNEL1, ticks1, true);&lt;br /&gt;// &lt;br /&gt; nrfx_timer_extended_compare(&lt;br /&gt; &amp;amp;timer0, NRF_TIMER_CC_CHANNEL2, ticks2,NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK,true);&lt;br /&gt; &lt;br /&gt; nrfx_timer_enable(&amp;amp;timer0);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;only tick1 is working in this scenario&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1704688219817v1.jpeg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note: tick1 should generate 1ms interrupt and tick2 should generate 51us interrupt.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Please provide the solution to run two different interrupts with single timer using diff channels.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Thanks,&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;saiteja.v&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issue with timer interrupt handler</title><link>https://devzone.nordicsemi.com/thread/463048?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2024 03:52:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64d3524b-cb9b-4d45-80e4-6d08bbd8c828</guid><dc:creator>Saiteja_v</dc:creator><description>&lt;p&gt;#define SYSTICK 1000&lt;br /&gt;#define _ONE_SEC SYSTICK&lt;/p&gt;
&lt;p&gt;#define TIME(x) (const unsigned int) ((float)x*SYSTICK)&lt;/p&gt;
&lt;p&gt;This is the time macro function iam using..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issue with timer interrupt handler</title><link>https://devzone.nordicsemi.com/thread/462905?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2024 13:25:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daefca9a-8888-4c53-aa4d-f5927da41234</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The interrupts for the corresponding event should be enabled when you call&amp;nbsp;&lt;span&gt;nrfx_timer_compare()/nrfx_timer_extended_compare().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Note that you have to clear the timer for it to reset, this does not happen automatically when the event is hit (unless you use&amp;nbsp;nrfx_timer_extended_compare() with one of the&amp;nbsp;COMPAREx_CLEAR short masks). I noticed that you calculate&amp;nbsp;ticks1 using&amp;nbsp;nrfx_timer_&lt;strong&gt;ms&lt;/strong&gt;_to_ticks(), while ticks2 are calculated using&amp;nbsp;nrfx_timer_&lt;strong&gt;us&lt;/strong&gt;_to_ticks(), is this intentional? Without knowing what TIME() macro will output, I suppose ticks2 might occur before ticks1.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>