<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How does multitasking really work with loop()?]]></title><description><![CDATA[<p dir="auto">Got two tasks, both on separate core, loop only has a delay(500) in it<br />
all arrays are initialized to 0 on setup and loop looks like this:<br />
what happens is the m5 freeze after the first completed task 2</p>
<p dir="auto">void Oscillo()<br />
{<br />
//copy ADC samples to oscillo buffer<br />
for (int i = 0; i &lt; SAMPLES; i++)<br />
oscilloBuffer[i] = vSample[i];</p>
<pre><code>for (int i = 0; i &lt; SAMPLES; i++)
{
	oscilloBuffer[i] = vSample[i];
	if (i == 0)
	{
		M5.Lcd.drawPixel(i, 128 - oldOscilloBuffer[i] * .01, BLACK);  //clear
		M5.Lcd.drawPixel(i, 128 - oscilloBuffer[i] * .01, RED);
	}
	else
	{
		M5.Lcd.drawLine(i - 1, 128 - oldOscilloBuffer[i - 1] * .01, i, 128 - oldOscilloBuffer[i] * .01, BLACK); //clear
		M5.Lcd.drawLine(i - 1, 128 - oscilloBuffer[i - 1] * .01, i, 128 - oscilloBuffer[i] * .01, RED);
		//M5.Lcd.drawFastVLine (i, 128 - min(oldOscilloBuffer[i - 1], oldOscilloBuffer[i]) * .01, max(1,abs(oldOscilloBuffer[i]- oldOscilloBuffer[i-1])) * .01, BLACK);
		//M5.Lcd.drawFastVLine(i, 128 - min(oscilloBuffer[i - 1], oscilloBuffer[i]) * .01, max(1,abs(oscilloBuffer[i] - oscilloBuffer[i - 1])) * .01, RED);
	}
}

//copy to back buffer
for (int i = 0; i &lt; SAMPLES; i++)
	oldOscilloBuffer[i] = oscilloBuffer[i];
</code></pre>
<p dir="auto">}</p>
<p dir="auto">(by the way, how do I get the auto code parse in this forum to work? it's always missing the start of the method)</p>
]]></description><link>https://community.m5stack.com/topic/171/how-does-multitasking-really-work-with-loop</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 04:56:45 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/171.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Apr 2018 02:33:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How does multitasking really work with loop()? on Fri, 13 Apr 2018 05:52:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/calin" aria-label="Profile: calin">@<bdi>calin</bdi></a> freeze with no serial message.<br />
What is the IDLE task and how do I control all this?</p>
]]></description><link>https://community.m5stack.com/post/835</link><guid isPermaLink="true">https://community.m5stack.com/post/835</guid><dc:creator><![CDATA[daslolo]]></dc:creator><pubDate>Fri, 13 Apr 2018 05:52:42 GMT</pubDate></item><item><title><![CDATA[Reply to How does multitasking really work with loop()? on Fri, 13 Apr 2018 05:31:42 GMT]]></title><description><![CDATA[<p dir="auto">it freezes because of the watchdog get triggered if the loop is empty or if you use a task on core 0 and you don't handle the IDLE task on that core.<br />
You might even get some message about that in serial console.<br />
Something like<br />
"Task watchdog got triggered. The following tasks did not reset the watchdog in time:</p>
<ul>
<li>IDLE (CPU 0)"</li>
</ul>
]]></description><link>https://community.m5stack.com/post/834</link><guid isPermaLink="true">https://community.m5stack.com/post/834</guid><dc:creator><![CDATA[Calin]]></dc:creator><pubDate>Fri, 13 Apr 2018 05:31:42 GMT</pubDate></item><item><title><![CDATA[Reply to How does multitasking really work with loop()? on Fri, 13 Apr 2018 00:08:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/calin" aria-label="Profile: calin">@<bdi>calin</bdi></a> hahaha... wait, seriously?<br />
But I am not trying to replace the delay with something else. I'm trying to understand why the m5 freezes up under certain conditions when using tasks. Oh and if I lower delay below 500 it will freeze much faster.</p>
]]></description><link>https://community.m5stack.com/post/831</link><guid isPermaLink="true">https://community.m5stack.com/post/831</guid><dc:creator><![CDATA[daslolo]]></dc:creator><pubDate>Fri, 13 Apr 2018 00:08:43 GMT</pubDate></item><item><title><![CDATA[Reply to How does multitasking really work with loop()? on Thu, 12 Apr 2018 20:36:22 GMT]]></title><description><![CDATA[<p dir="auto">You can use something like</p>
<p dir="auto">TaskHandle_t taskHandle;<br />
void setup()<br />
{<br />
//some init functions<br />
}<br />
void loop()<br />
{<br />
if (taskHandle == NULL)<br />
{<br />
xTaskCreatePinnedToCore(<br />
yourTask,			  /* Task function. <em>/<br />
"yourTask",			  /</em> name of the task, a name just for humans <em>/<br />
xxxx,				  /</em> Stack size of task */<br />
(void <em>)&amp;pvParameter, /</em> parameter of the task <em>/<br />
y,					  /</em> priority of the task <em>/<br />
&amp;taskHandle,		  /</em> Task handle to keep track of the created task */<br />
z);					  /<em>cpu core number where the task is assigned</em>/<br />
}<br />
}</p>
<p dir="auto">inside the loop to create a task from loop<br />
This way you keep the loop busy too with the if statement :)</p>
]]></description><link>https://community.m5stack.com/post/830</link><guid isPermaLink="true">https://community.m5stack.com/post/830</guid><dc:creator><![CDATA[Calin]]></dc:creator><pubDate>Thu, 12 Apr 2018 20:36:22 GMT</pubDate></item><item><title><![CDATA[Reply to How does multitasking really work with loop()? on Thu, 12 Apr 2018 05:55:17 GMT]]></title><description><![CDATA[<p dir="auto">the tasks are started the task way from setup<br />
loop only contains delay because without delay the program freezes</p>
]]></description><link>https://community.m5stack.com/post/823</link><guid isPermaLink="true">https://community.m5stack.com/post/823</guid><dc:creator><![CDATA[daslolo]]></dc:creator><pubDate>Thu, 12 Apr 2018 05:55:17 GMT</pubDate></item><item><title><![CDATA[Reply to How does multitasking really work with loop()? on Thu, 12 Apr 2018 05:27:18 GMT]]></title><description><![CDATA[<p dir="auto">"loop()" is located inside a task:<br />
void loopTask(void *pvParameters)<br />
{<br />
setup();<br />
for(;;) {<br />
micros(); //update overflow<br />
loop();<br />
}<br />
}<br />
normal functions that run inside loop can't do multitasking.<br />
For multitasking you have to use RTOS  xTaskCreatePinnedToCore... to create a separate task<br />
check out the signal generator functions on my oscilloscope project to see an example of running tasks on different core.<br />
Oscilloscope run's inside loop, on core 1<br />
Signal generators run on core 0</p>
]]></description><link>https://community.m5stack.com/post/821</link><guid isPermaLink="true">https://community.m5stack.com/post/821</guid><dc:creator><![CDATA[Calin]]></dc:creator><pubDate>Thu, 12 Apr 2018 05:27:18 GMT</pubDate></item><item><title><![CDATA[Reply to How does multitasking really work with loop()? on Thu, 12 Apr 2018 03:05:12 GMT]]></title><description><![CDATA[<p dir="auto">I’m probably not the best resource to answer this, because I’m just getting started with programming in general... but from the little experience I have so far, delay is a blocking function. So nothing else will run until it completes the task. Something like mills or simpleTimer looks to be better.</p>
<p dir="auto"><a href="https://canvas.instructure.com/courses/1054116/pages/arduino-millis-and-simpletimer-instead-of-delay-and-blocking" target="_blank" rel="noopener noreferrer nofollow ugc">https://canvas.instructure.com/courses/1054116/pages/arduino-millis-and-simpletimer-instead-of-delay-and-blocking</a></p>
<p dir="auto">Also to get the code text formatted properly, I wrap it in three back ticks (before and after the code):   ```</p>
]]></description><link>https://community.m5stack.com/post/819</link><guid isPermaLink="true">https://community.m5stack.com/post/819</guid><dc:creator><![CDATA[world101]]></dc:creator><pubDate>Thu, 12 Apr 2018 03:05:12 GMT</pubDate></item></channel></rss>