<?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>Kernel threads, one thread at 0.1 Hz the other at 50 Hz.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110476/kernel-threads-one-thread-at-0-1-hz-the-other-at-50-hz</link><description>Good afternoon, 
 
 I am developing with the nrf connect SDK and I want to implement the Zephyr RTOS in my project. This is cause i have a &amp;quot;main&amp;quot; thread that needs to run at 50 Hz and i have an aditional thread that only needs to run at 0.1 Hz. However</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 24 Apr 2024 06:24:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110476/kernel-threads-one-thread-at-0-1-hz-the-other-at-50-hz" /><item><title>RE: Kernel threads, one thread at 0.1 Hz the other at 50 Hz.</title><link>https://devzone.nordicsemi.com/thread/480328?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2024 06:24:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b081e496-5bb4-4edc-83c3-f25d4e52e0c8</guid><dc:creator>Niels Redegeld</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the quick response. I have figured it out now, I have no idea what the problem was at first but I have fixed it using timers like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*****************************
 * SLAM Ortho 2024
 * Author: Niels Redegeld
 * main.c
 *****************************/
#include &amp;quot;core.h&amp;quot;
// #include &amp;quot;ble.h&amp;quot;
#include &amp;quot;main.h&amp;quot;
// #include &amp;quot;rotation.h&amp;quot;
// #include &amp;quot;device.h&amp;quot;
// #include &amp;quot;force.h&amp;quot;
// #include &amp;quot;battery.h&amp;quot;
// #include &amp;quot;ads131.h&amp;quot;
// #include &amp;quot;gpio.h&amp;quot;
// #include &amp;quot;device_state.h&amp;quot;
// #include &amp;quot;clock.h&amp;quot;

struct k_timer thread1_timer;
struct k_timer thread2_timer;

void thread1_handler(struct k_timer *timer_id)
{
    // Thread 1 code here
    printk(&amp;quot;Thread 1 running at 2 Hz\n&amp;quot;);
}

void thread2_handler(struct k_timer *timer_id)
{
    // Thread 2 code here
    printk(&amp;quot;Thread 2 running at 1 Hz\n&amp;quot;);
}

int main(void)
{
    printk(&amp;quot;abc\n&amp;quot;);

    k_timer_init(&amp;amp;thread1_timer, thread1_handler, NULL);
    k_timer_init(&amp;amp;thread2_timer, thread2_handler, NULL);

    k_timer_start(&amp;amp;thread1_timer, K_MSEC(500), K_MSEC(500));   // 2 Hz
    k_timer_start(&amp;amp;thread2_timer, K_MSEC(1000), K_MSEC(1000)); // 1 Hz

    while (1)
    {
        // Main thread code if needed
        k_sleep(K_FOREVER);
    }

    return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This works great :)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Niels Redegeld.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kernel threads, one thread at 0.1 Hz the other at 50 Hz.</title><link>https://devzone.nordicsemi.com/thread/480189?ContentTypeID=1</link><pubDate>Tue, 23 Apr 2024 11:51:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86b29c94-c65c-4e63-a073-a88ce2240da8</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Niels,&lt;/p&gt;
&lt;p&gt;Each thread is separate from eachother, and there is no reason they would have to sleep the same ammount of time. I cannot say more about wha tyou have doen wrong without seeing some code, though. Can you show what you have done?&lt;/p&gt;
&lt;p&gt;You can learn the basics of Zephyr threads in &lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-7-multithreaded-applications/"&gt;lesson 7&lt;/a&gt; of the &lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/"&gt;nRF Connect SDK fundamentals course&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>