<?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>Issuse when trying to connect a pwm peripheral and a hardware timer 2 peripheral using P</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/121814/issuse-when-trying-to-connect-a-pwm-peripheral-and-a-hardware-timer-2-peripheral-using-p</link><description>Hello everyone, 
 I am a EE student and this problem came up during my first big project in zephyr. I&amp;#39;m trying to connect a pwm peripheral (pwm1) to the timer 2 hardware timer in zephyr. The idea is to have the timer in the counter mode and have it increment</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 30 May 2025 10:18:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/121814/issuse-when-trying-to-connect-a-pwm-peripheral-and-a-hardware-timer-2-peripheral-using-p" /><item><title>RE: Issuse when trying to connect a pwm peripheral and a hardware timer 2 peripheral using P</title><link>https://devzone.nordicsemi.com/thread/537503?ContentTypeID=1</link><pubDate>Fri, 30 May 2025 10:18:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77026783-9518-46b5-bfa1-7b4ee52c8fd5</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Jana,&lt;/p&gt;
&lt;p&gt;I do not immediately spot any issue here, the PPI connection betwene the PWM event and timers count task seems good. Does the&amp;nbsp;SEQEND event on PWM1 occur at all?&lt;/p&gt;
&lt;p&gt;There is no fundamental difference between the timer in timer and counter mode (the only difference is if the pulse that incremetns the internal counter comes from the clock or the count task. I would still reocmmend using the driver as I refered to before (just because that makes things more flexible and readable). I did a quick and dirty change to the sample to show that the timer also gives interrupts in counter mode (here the task is triggered from the main loop for simplicity in the example).&lt;/p&gt;
&lt;p&gt;Diff from the &lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/blob/13ac55b5b52c905642e9c54f069109d188aa5840/nrfx/samples/src/nrfx_gppi/one_to_one"&gt;one_to_one PPI sample&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="diff"&gt;diff --git a/nrfx/samples/src/nrfx_gppi/one_to_one/main.c b/nrfx/samples/src/nrfx_gppi/one_to_one/main.c
index 89c157e..985ae43 100644
--- a/nrfx/samples/src/nrfx_gppi/one_to_one/main.c
+++ b/nrfx/samples/src/nrfx_gppi/one_to_one/main.c
@@ -143,6 +143,7 @@ int main(void)
     nrfx_timer_t timer_inst = NRFX_TIMER_INSTANCE(TIMER_INST_IDX);
     uint32_t base_frequency = NRF_TIMER_BASE_FREQUENCY_GET(timer_inst.p_reg);
     nrfx_timer_config_t timer_config = NRFX_TIMER_DEFAULT_CONFIG(base_frequency);
+    timer_config.mode = NRF_TIMER_MODE_COUNTER;
     timer_config.bit_width = NRF_TIMER_BIT_WIDTH_32;
     timer_config.p_context = &amp;quot;Some context&amp;quot;;
 
@@ -152,8 +153,8 @@ int main(void)
     nrfx_timer_clear(&amp;amp;timer_inst);
 
     /* Creating variable desired_ticks to store the output of nrfx_timer_ms_to_ticks function. */
-    uint32_t desired_ticks = nrfx_timer_ms_to_ticks(&amp;amp;timer_inst, TIME_TO_WAIT_MS);
-    NRFX_LOG_INFO(&amp;quot;Time to wait: %lu ms&amp;quot;, TIME_TO_WAIT_MS);
+    uint32_t desired_ticks = 10;
+    NRFX_LOG_INFO(&amp;quot;Ticks to wait: %u&amp;quot;, desired_ticks);
 
     /*
      * Setting the timer channel NRF_TIMER_CC_CHANNEL0 in the extended compare mode to clear
@@ -182,6 +183,8 @@ int main(void)
     while (1)
     {
         NRFX_EXAMPLE_LOG_PROCESS();
+        k_sleep(K_MSEC(100));
+        NRF_TIMER0-&amp;gt;TASKS_COUNT = 1;
     }
 }
 
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;With this, you can see that the timer in counter mode works and you get the event and interrupt that toglge the LED every second (adjust the number of ticks for the CC register or the sleep time to change the time).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issuse when trying to connect a pwm peripheral and a hardware timer 2 peripheral using P</title><link>https://devzone.nordicsemi.com/thread/537324?ContentTypeID=1</link><pubDate>Wed, 28 May 2025 09:01:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31710af9-33dd-4b12-b21e-c627570bce9b</guid><dc:creator>jklaric</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;Thanks for providing examples. However, they take me on a bit of a different path. I managed to run them, but in these examples the timer is started in a timer mode and not in the counter mode. I truly believe that my issue lies somewhere there. The pwm generation I think is all right because I probed it. However, my counter (timer) is absolutely useless. It never increases.... I lowered the pwm to 5Hz and made it so that the variable PWM_COUNT_THRESHOLD is now only 10 cycles. Here&amp;#39;s the way I start the counter timer thing, maybe there&amp;#39;s a huge problem there that I just don&amp;#39;t see:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#if defined(__ZEPHYR__)
    IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(TIMER_INST_IDX)), IRQ_PRIO_LOWEST,
                NRFX_TIMER_INST_HANDLER_GET(TIMER_INST_IDX), 0, 0);
    #endif
    nrfx_err_t status;
    (void)status;
    uint8_t gppi_channel;
    
    NRF_TIMER2-&amp;gt;MODE = TIMER_MODE_MODE_Counter;
    NRF_TIMER2-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit;
    NRF_TIMER2-&amp;gt;CC[0] = PWM_COUNT_THRESHOLD;
    NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;
 
    NRF_TIMER2-&amp;gt;INTENSET = TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos;
    
    IRQ_DIRECT_CONNECT(TIMER2_IRQn, 0, timer2_irq_handler, 0);
    irq_enable(TIMER2_IRQn);
    
    status = nrfx_gppi_channel_alloc(&amp;amp;gppi_channel);
    NRFX_ASSERT(status == NRFX_SUCCESS);

    nrfx_gppi_channel_endpoints_setup(gppi_channel,
        (uint32_t)&amp;amp;NRF_PWM1-&amp;gt;EVENTS_SEQEND[0],
        (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_COUNT);
    
    nrfx_gppi_channels_enable(BIT(gppi_channel));
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and here&amp;#39;s my callback:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void timer2_irq_handler(nrf_timer_event_t event_type,void * p_context) {
    LOG_INF(&amp;quot;In timer 2 irq\n&amp;quot;);
    if  (event_type == NRF_TIMER_EVENT_COMPARE0){

        LOG_INF(&amp;quot;In if of timer 2 irq\n&amp;quot;);
    
        counter=counter+1;
        LOG_INF(&amp;quot;counter %u\n&amp;quot;, counter);
        NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0; 
        
        NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;
        
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you know anything more about getting the IRQ to fire when the timer is in counter mode and you see what I&amp;#39;m doing wrong in its initialization please let me know.&lt;/p&gt;
&lt;p&gt;Jana&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issuse when trying to connect a pwm peripheral and a hardware timer 2 peripheral using P</title><link>https://devzone.nordicsemi.com/thread/537156?ContentTypeID=1</link><pubDate>Tue, 27 May 2025 11:50:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3aaff469-3017-48cb-9619-9a49bddcd748</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Jana,&lt;/p&gt;
&lt;p&gt;The nRF5340 has DPPI, and to use a driver for it you should use the GPPI driver which works with both PPI and DPPI. There are &lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/blob/ecea8cdbd1a7d557563b47ad304ee9ba7a8709e5/nrfx/samples/src/nrfx_gppi"&gt;two&amp;nbsp;examples here&lt;/a&gt;, that demonstrate use with a TIMER.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>