<?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>54L15 Timer Interrupt cost too high. How to reduce interrupt cost?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/128568/54l15-timer-interrupt-cost-too-high-how-to-reduce-interrupt-cost</link><description>As title 
 Situration: 
 1. Timer00 
 2. every 4us interrupt occur 
 
 result: 
 1. Enter Timer interrupt cost 700ns 
 2. Leave Timer interrupt cost 200ns 
 3. Totol cost: 1.04us 
 
 How to reduce inrerrupt cost from 1.04us to around 200ns? 
 
 Austi</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 01 Jul 2026 06:11:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/128568/54l15-timer-interrupt-cost-too-high-how-to-reduce-interrupt-cost" /><item><title>RE: 54L15 Timer Interrupt cost too high. How to reduce interrupt cost?</title><link>https://devzone.nordicsemi.com/thread/568630?ContentTypeID=1</link><pubDate>Wed, 01 Jul 2026 06:11:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d82468c4-eecf-4758-84cc-8a6ee4dfe3f2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Austin,&lt;/p&gt;
&lt;p&gt;If you use&amp;nbsp;GPIOs to measure the timing it is important that you use pins from the fast P2 port and that you use direct register access to set or clear the pin to minimise latency and jitter introduced by your measurement.&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#include&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;hal/nrf_gpio.h&amp;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;&lt;span&gt;nrf_gpio_cfg_output(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;NRF_GPIO_PIN_MAP&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;9&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;// Code to clear P2.09&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;NRF_P2&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;OUTCLR&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;9&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;// Code to set P2.09&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;NRF_P2-&amp;gt;OUTSET = (1 &amp;lt;&amp;lt; 9);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Another alternative is to use the timing functions available in Zephyr and print the measured result&amp;nbsp;out on UART:&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/kernel/timing_functions/index.html"&gt;https://docs.zephyrproject.org/latest/kernel/timing_functions/index.html&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;[quote user="Austin (S.F.)"]&amp;nbsp;It is a real-time application. Because that, I have some calculate and response immidiatly.[/quote]
&lt;p&gt;I understand that timing is critical but&amp;nbsp;in some situations you can achieve shorter latencies by not using interrupts.&lt;/p&gt;
[quote user="Austin (S.F.)"]It seems zero latency for IRQs no work.[/quote]
&lt;p&gt;&amp;quot;zero latency&amp;quot; will not make any difference for your test as there aren&amp;#39;t any other interrupts that overlap with your TIMER interrupt anyway.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 54L15 Timer Interrupt cost too high. How to reduce interrupt cost?</title><link>https://devzone.nordicsemi.com/thread/568596?ContentTypeID=1</link><pubDate>Tue, 30 Jun 2026 10:55:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1ec7da7-fc3d-4e3d-a2d8-642f214efcca</guid><dc:creator>Austin (S.F.)</dc:creator><description>&lt;p&gt;Hi Vidar&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; I added &amp;quot;&lt;span&gt;CONFIG_ZERO_LATENCY_IRQS&lt;/span&gt;&lt;span&gt;=y&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; And the code as below&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrfx_timer_t timer00_inst = NRFX_TIMER_INSTANCE(NRF_TIMER_INST_GET(TIMER00_IDX));

static void timer00_handler(nrf_timer_event_t event_type, void *p_context)
{
    if (event_type == NRF_TIMER_EVENT_COMPARE0)
    {
        LED_R_toggle;
        test_bit = GET_AD_IN_1_DATA;
    }
}

ISR_DIRECT_DECLARE(timer00_direct_isr)
{
    nrfx_timer_irq_handler(&amp;amp;timer00_inst);  
    return 0;  
}

int8_t Timer00_init(void)
{
    //pick 1 or 2 to test the difference
    //1. use this
    IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(TIMER00_IDX)), 
                0,
                nrfx_timer_irq_handler,
                &amp;amp;timer00_inst,
                0);


    //2. or this
    IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(TIMER00_IDX)),
                       0,
                       timer00_direct_isr,   
                       0);                   

    uint32_t base_frequency = NRF_TIMER_BASE_FREQUENCY_GET(timer00_inst.p_reg);
    nrfx_timer_config_t config = NRFX_TIMER_DEFAULT_CONFIG(base_frequency);
    config.bit_width = NRF_TIMER_BIT_WIDTH_32;
    config.p_context = &amp;quot;4us&amp;quot;;

    nrfx_timer_init(&amp;amp;timer00_inst, &amp;amp;config, timer00_handler);
    nrfx_timer_clear(&amp;amp;timer00_inst);

    uint32_t desired_ticks = nrfx_timer_us_to_ticks(&amp;amp;timer00_inst, TIME_TO_INT);
    desired_ticks = desired_ticks + 8;

    nrfx_timer_extended_compare(&amp;amp;timer00_inst, NRF_TIMER_CC_CHANNEL0, desired_ticks,
                                NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrfx_timer_enable(&amp;amp;timer00_inst);
    printk(&amp;quot;Timer status: %s\r\n&amp;quot;,
           nrfx_timer_is_enabled(&amp;amp;timer00_inst) ? &amp;quot;enabled&amp;quot; : &amp;quot;disabled&amp;quot;);

    return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When using 1. and remark 2., the result as below. The Timer 00 cost 1.53us .&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1782816603403v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;When using 2. remak 1., the result as below. The Timer 00 cost 1.595us .&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1782816779589v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do you have better way to reduce the cost?&lt;/p&gt;
&lt;p&gt;It seems zero latency for IRQs no work.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Austin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 54L15 Timer Interrupt cost too high. How to reduce interrupt cost?</title><link>https://devzone.nordicsemi.com/thread/568522?ContentTypeID=1</link><pubDate>Mon, 29 Jun 2026 08:18:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d43597d7-717b-453b-b5d1-f407fb899882</guid><dc:creator>Austin (S.F.)</dc:creator><description>&lt;p&gt;Hi Vidar&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Yes, I really need the timer interrupt to preempt my code.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;It is a real-time application. Because that, I have some calculate and response immidiatly.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;I will try this &amp;quot; direct ISA&amp;quot;. After I testing it , I will let you know the result.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Austin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 54L15 Timer Interrupt cost too high. How to reduce interrupt cost?</title><link>https://devzone.nordicsemi.com/thread/568520?ContentTypeID=1</link><pubDate>Mon, 29 Jun 2026 07:42:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bebb7e6a-889c-401b-a4dc-aec39593b3cd</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;This is a continuation of this thread here:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/128563/nrf54l15-sb_config_bootloader_mcuboot-y-makes-main-gpio-toggle-stop"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/128563/nrf54l15-sb_config_bootloader_mcuboot-y-makes-main-gpio-toggle-stop&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
[quote user=""]How to reduce inrerrupt cost from 1.04us to around 200ns?[/quote]
&lt;p&gt;To reduce the overhead you can define your ISR as &amp;quot;direct&amp;quot; with no rescheduling on return:&amp;nbsp;&lt;a href="https://nrfconnectdocs.nordicsemi.com/ncs/latest/zephyr/kernel/services/interrupts.html#defining-a-direct-isr"&gt;https://nrfconnectdocs.nordicsemi.com/ncs/latest/zephyr/kernel/services/interrupts.html#defining-a-direct-isr&lt;/a&gt;. Building with&amp;nbsp;&lt;span&gt;CONFIG_SPEED_OPTIMIZATIONS&lt;/span&gt;&lt;span&gt;=y may also help shave off a few CPU cycles. But what I was trying to ask in the previous thread is whether you really need the timer interrupt to preempt your code. Given the short interval, it may make more sense to poll the TIMER counter register instead.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 54L15 Timer Interrupt cost too high. How to reduce interrupt cost?</title><link>https://devzone.nordicsemi.com/thread/568503?ContentTypeID=1</link><pubDate>Sat, 27 Jun 2026 11:37:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5ba5a74-30fe-48f7-91bb-9d7f68bbf82b</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Smells like an X/Y problem. What are you actually trying to do?&lt;/p&gt;
&lt;p&gt;Interrupt timing is&amp;nbsp;&lt;em&gt;horrible&lt;/em&gt; when you turn on the radio/BT stack.&lt;/p&gt;
&lt;p&gt;If you need that strict of a timing, try to do the work in hardware (PWM peripherial or FLPR).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>