{"id":3304,"date":"2025-04-18T04:29:13","date_gmt":"2025-04-18T04:29:13","guid":{"rendered":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?post_type=spl_knowledgebase&#038;p=3304"},"modified":"2025-06-10T09:22:08","modified_gmt":"2025-06-10T09:22:08","slug":"multitrack-basic-the-yieldtask-instruction","status":"publish","type":"spl_knowledgebase","link":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/","title":{"rendered":"MultiTrack (Basic): The YieldTask instruction"},"content":{"rendered":"\n<p>In the previous lesson I showed you how potentially\u00a0<em>blocking<\/em>\u00a0instructions like\u00a0<code><a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/programming-reference\/instructions-arranged-by-function\/fasttrack-instructions\/waiton-ii\/\">WaitOn<\/a><\/code>\u00a0and\u00a0<code><a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/programming-reference\/instructions-arranged-by-function\/fasttrack-instructions\/pause-tttt\/\">Pause<\/a><\/code>\u00a0will automatically cause a task switch, i.e. cause the task to\u00a0<em>yield<\/em>\u00a0so another task can run. But what if there are no such instructions being executed?<\/p>\n\n\n\n<p>The&nbsp;<code>YieldTask<\/code>&nbsp;instruction lets you force a task switch anywhere you like in your program. This is something you have to think about, for two reasons:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>If a task never yields, no other task will get a chance to run.<\/li>\n\n\n\n<li>If a MultiTrack task executes more than 255 instructions without yielding, the controller will suffer a fatal runtime error (we made it that way to force you to do the right thing!)<\/li>\n<\/ol>\n\n\n\n<p>To illustrate this, copy the following into SPLat\/PC and run it:<br><a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/cutting-and-pasting-code-from-the-splat-knowledge-base\/\">(Click here<\/a>\u00a0for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help\u00a0<code>(.chm)<\/code>\u00a0files)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">                LaunchTask  TaskA\n                LaunchTask  TaskB\n                RunTasksForever\n\nTaskA:          On          0\n                Pause       1\n                Off         0\n                Pause       1\n                GoTo        TaskA\n\nTaskB:          IncM        0\n                GoTo        TaskB\n<\/pre>\n\n\n\n<p>The program will &#8220;bomb out&#8221; after a short while. A&nbsp;<code>YieldTask<\/code>&nbsp;placed after the&nbsp;<code>IncM<\/code>&nbsp;instruction will allow it to run properly. Try it!<\/p>\n\n\n\n<p>Here&#8217;s an example of a task that uses\u00a0<code>YieldTask<\/code>. This task will monitor inputs 2 and 3 simultaneously. If input 2 comes on it increments\u00a0<a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/glossary-of-terms\/\">RAM<\/a>\u00a0location\u00a0<code>Count<\/code>. If input 3 comes on it decrements\u00a0<code>Count<\/code>. Having counted up or down it waits for both inputs to be off, then repeats.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CountFunc:       GoIfInOn    2,CountUp\n                 GoIfInOn    3,CountDn\n                 YieldTask               ;Give someone else a go\n                 GoTo        CountFunc   ;Loop and repeat\n\nCountUp:         IncM        Count\n                 GoTo        WaitForBothOff\n\nCountDn:         DecM        Count\nWaitForBothOff:  YieldTask\n                 GoIfInOn    2,WaitForBothOff\n                 GoIfInOn    3,WaitForBothOff\n                 GoTo        CountFunc\nCount:           mEQU        10            ;Declare the RAM variable\n\t\t\t<\/pre>\n\n\n\n<h6 class=\"wp-block-heading\">Exercise 1:<\/h6>\n\n\n\n<p>Combine the above task with the dual flasher example in the\u00a0<a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-quick-start-for-dummies\/\">earlier example<\/a>\u00a0and get it running. Take time to study what the\u00a0<code>YieldTask<\/code>\u00a0is doing.<\/p>\n\n\n\n<p>Hint: You can monitor\u00a0<code>Count<\/code>\u00a0at location 10 in the\u00a0<a href=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/glossary-of-terms\/#o415\">Data Memory<\/a>\u00a0window in SPLat\/PC (explore the Window menu if this is unfamiliar ground).<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Exercise 2:<\/h6>\n\n\n\n<p>The first loop of&nbsp;<code>CountFunc <\/code>(the first 4 instructions) uses one instruction more than necessary. Rearrange it so it only use 3 instructions. Hint: Move the&nbsp;<code>YieldTask <\/code>to the start of the loop, eliminate the unconditional&nbsp;<code>GoTo <\/code>and modify the remaining two conditional&nbsp;<code>GoTo<\/code>&#8216;s so it works. Note: In general you should not stress over minor inefficiencies like this one in your code. In fact, unless you are pushing the limits of available memory, some inefficiencies are a good investment if they make the code easier to read.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Exercise 3:<\/h6>\n\n\n\n<p>Consider the following rewritten snippet of code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">WaitForBothOff:  WaitOff     2\n                 WaitOff     3\n                 GoTo        CountFunc<\/pre>\n\n\n\n<p>This would seem to achieve the same result with a saving of 2 lines of code. However, the original will only &#8220;trip&#8221; when both inputs are off simultaneously. Work out why the the above snippet could &#8220;trip&#8221; with input 2 on and input 3 off.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous lesson I showed you how potentially\u00a0blocking\u00a0instructions like\u00a0WaitOn\u00a0and\u00a0Pause\u00a0will automatically cause a task switch, i.e. cause the task to\u00a0yield\u00a0so another task can run. But&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3299,"menu_order":1,"template":"","class_list":["post-3304","spl_knowledgebase","type-spl_knowledgebase","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MultiTrack (Basic): The YieldTask instruction - SPLat Controls<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MultiTrack (Basic): The YieldTask instruction - SPLat Controls\" \/>\n<meta property=\"og:description\" content=\"In the previous lesson I showed you how potentially\u00a0blocking\u00a0instructions like\u00a0WaitOn\u00a0and\u00a0Pause\u00a0will automatically cause a task switch, i.e. cause the task to\u00a0yield\u00a0so another task can run. But...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/\" \/>\n<meta property=\"og:site_name\" content=\"SPLat Controls\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-10T09:22:08+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/\",\"name\":\"MultiTrack (Basic): The YieldTask instruction - SPLat Controls\",\"isPartOf\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\"},\"datePublished\":\"2025-04-18T04:29:13+00:00\",\"dateModified\":\"2025-06-10T09:22:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials, application notes and white papers\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Tutorial: MultiTrack\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"MultiTrack (Basic): The YieldTask instruction\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"name\":\"SPLat Controls\",\"description\":\"OEM Embedded Machine Controllers\",\"publisher\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\",\"name\":\"SPLat Controls\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"contentUrl\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"caption\":\"SPLat Controls\"},\"image\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MultiTrack (Basic): The YieldTask instruction - SPLat Controls","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"MultiTrack (Basic): The YieldTask instruction - SPLat Controls","og_description":"In the previous lesson I showed you how potentially\u00a0blocking\u00a0instructions like\u00a0WaitOn\u00a0and\u00a0Pause\u00a0will automatically cause a task switch, i.e. cause the task to\u00a0yield\u00a0so another task can run. But...","og_url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/","og_site_name":"SPLat Controls","article_modified_time":"2025-06-10T09:22:08+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/","name":"MultiTrack (Basic): The YieldTask instruction - SPLat Controls","isPartOf":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website"},"datePublished":"2025-04-18T04:29:13+00:00","dateModified":"2025-06-10T09:22:08+00:00","breadcrumb":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/multitrack-basic-the-yieldtask-instruction\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/"},{"@type":"ListItem","position":2,"name":"Tutorials, application notes and white papers","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/"},{"@type":"ListItem","position":3,"name":"Tutorial: MultiTrack","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/tutorials-application-notes-and-white-papers\/tutorial-multitrack\/"},{"@type":"ListItem","position":4,"name":"MultiTrack (Basic): The YieldTask instruction"}]},{"@type":"WebSite","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","name":"SPLat Controls","description":"OEM Embedded Machine Controllers","publisher":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization","name":"SPLat Controls","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","contentUrl":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","caption":"SPLat Controls"},"image":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/3304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase"}],"about":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/types\/spl_knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/users\/1"}],"up":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/3299"}],"wp:attachment":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/media?parent=3304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}