{"id":1745,"date":"2017-03-08T21:49:49","date_gmt":"2017-03-08T21:49:49","guid":{"rendered":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/"},"modified":"2017-03-08T21:49:49","modified_gmt":"2017-03-08T21:49:49","slug":"mcode-programming-mdrive-io","status":"publish","type":"page","link":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/","title":{"rendered":"MCode: Programming MDrive I\/O"},"content":{"rendered":"\n\n\n<div class=\"wp-block-group alignwide is-layout-flow wp-block-group-is-layout-flow\" style=\"margin-top:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40)\">\n\t<h3 class=\"wp-block-heading\">Global or Local variables<\/h3>\n\n\r\nLike All MDrive variables, the I\/O point configuration can be declared two ways:\r\n\n<ol class=\"wp-block-list\"><li>Globally<\/li><li>Locally<\/li><\/ol>\n\n\r\n\n<strong> Global: <\/strong>\n\n  Global I\/O configurations, are declared outside the main body of the program. These are more typical and are used when you want the I\/O point to have the same function at all times.\r\n\r\n\n<strong> Local:  <\/strong>\n\n Local configurations are declared inside the body of the program and are stored in RAM, thus may be changed on the fly. An example would be where you may want an input to output to perform one function in part of the program and another in a different part of the program.\r\n\r\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"299\" src=\"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/global-vs-local.gif\" alt=\"\" class=\"wp-image-1742\"\/><\/figure>\n\n\r\n\n<h3 class=\"wp-block-heading\">Event triggering<\/h3>\n\n\r\nThe most common use of the I\/O is to trigger events within a system:\r\n\n<ul class=\"wp-block-list\"><li><strong> Inputs: <\/strong>  to trigger events internal to the MDrive program.<\/li><li><strong> Outputs: <\/strong>  to trigger events within a machine or system.<\/li><\/ul>\n\n\r\n\n<h3 class=\"wp-block-heading\">Input example:<\/h3>\n\n\r\nThe following program example shows an input used to trigger an internal event:\r\n\r\nThe following program will move the axis to an absolute position based upon the state of I\/O 1 and will hold that position until the state changes.\r\n\r\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"257\" height=\"173\" src=\"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/event-trigger.gif\" alt=\"\" class=\"wp-image-1743\"\/><\/figure>\n\n\r\n\r\nIn this example, the program will use a conditional branch (BR) to activate the event. Input-driven events may also use the Call Subroutine (CL) command in a similar fashion.\r\n\n<pre class=\"wp-block-code\"><code><pre class=\"lang:vbnet mark:1,9,10 decode:true\" title=\"Triggering an input event\">S1=0,0,0       'setup io point\r\n\r\n'***program***\r\nPG 100        'enter program mode at address 100\r\nLB SU         'label program to start on power on\r\nLB ba         'label ba is a loop point\r\n\r\n'*** input event actions***\r\nBR bb, I1=1   'conditional branch to bb if input 1=1\r\nBR bc, I1=0   'conditional branch to ba if input 1=0\r\n\r\n'*** input event 1***\r\nLB bb         ' create process bb\r\nMA 51200      'move to absolute position 51200\r\nH0            'hold until motion ceases\r\nBR ba         'loop to ba\r\n\r\n'*** input event 0***\r\nLB bc         'create process bb\r\nMA 0          'move to absolute position 0\r\nH0            'hold until motion ceases\r\nBR ba         'loop to ba\r\n\r\n'***end***\r\nE\r\nPG\r\n<\/pre><\/code><\/pre>\n\n\r\n\n<h3 class=\"wp-block-heading\">Output event<\/h3>\n\n\r\nThe following program example shows an output used to trigger an external event. A real-world example may be that the MDrive performs and completes a task, when complete the program will activate an output to trigger an external process, such as executing a program in a second system MDrive.\r\n\n<pre class=\"wp-block-code\"><code><pre class=\"lang:vbnet mark:1,2,12,16-17,21 decode:true\" title=\"Triggering an output event with an input\">S1=0,0,0  'setup IO1\r\nS2=16,0,0 'setup IO2\r\n\r\n'***program***\r\nPG 100\r\nLB SU\r\nLB ba     'label ba as return point\r\nMR 512000\r\nH0\r\n\r\n'***initiate external event***\r\nO2=1          'set output 2 active\r\n\r\n'***wait for input to restart***\r\nLB bb         ' label bb as loop point\r\nBR bb, I1=0   'loop to bb, input 1 inactive\r\nBR bc, I1=1    'branch to bc, input 1 active\r\n\r\n'***restart program on input event***\r\nLB bc          'label bc as clear O2\r\n02=0           'set output 2 inactive\r\nBR ba          'restart program\r\nE\r\nPG\r\n<\/pre><\/code><\/pre>\n\n\r\n\n<h3 class=\"wp-block-heading\">Using a Bank of I\/O<\/h3>\n\n\r\nThe MDrive I\/O can read inputs and write outputs as a group in Binary Coded Decimal (BCD).\r\n\r\nThe I\/O may be connected as shown below. For purposes of example, we have used switches for inputs and LED&#8217;s for outputs. All are configured as general purpose, active when low, sinking.\r\n\r\nFor this example we will use two basic programs:\r\n\n<ul class=\"wp-block-list\"><li><strong>Inputs:<\/strong> A program that will perform a specific move based on the input decimal value.<\/li><li><strong>Outputs:<\/strong> A program that will cause the outputs to operate as a binary up counter.<\/li><\/ul>\n\n\r\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"550\" height=\"294\" src=\"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/group_io.gif\" alt=\"\" class=\"wp-image-1744\"\/><\/figure>\n\n\r\n\n<h3 class=\"wp-block-heading\">Move on BCD Input Example<\/h3>\n\n\r\nThe following application will move the motor to a variety of positions based upon a binary input to I\/O 1-4. One of the things this application shows is one of the new Microstep Resolution settings that give the ability to set motion to occur in 0.001\u02da increments. The program does a calculation after each move to show motor position in degrees. To make the web view shorter, the example below omits many repetitive branch routines for the various moves. See the\n\n<a href=\"https:\/\/www.novantaims.com\/support\/mdrive\/programs\/mxt\/bcd_in.mxt\">full program<\/a>\n\n to view.\r\n\n<pre class=\"wp-block-code\"><code><pre class=\"lang:vbnet decode:true \" title=\"Move on BCD Input Example\">'******Global Setup Parameters****\r\nS1=0,0,0  'I1-4 set as GP,LOW Active, sinking\r\nS2=0,0,0\r\nS3=0,0,0\r\nS4=0,0,0\r\nP=0\r\nMs=180    'Microstep Res to 0.001 deg\/ustep\r\n\r\n'******Main Program*********\r\nPG 1\r\nLB aa\r\nR1=Il          'Set register 1 = inputs 4-1\r\nBR z1,R1=0     'conditional branches based\r\nBR za,R1=1     'upon the value of IL\r\nBR zb,R1=2\r\nBR zc,R1=3\r\nBR zd,R1=4\r\nBR ze,R1=5\r\nBR zf,R1=6\r\nBR zg,R1=7\r\nBR zh,R1=8\r\nBR zi,R1=9\r\nBR zj,R1=10\r\nBR zk,R1=11\r\nBR zl,R1=12\r\nBR zm,R1=13\r\nBR zn,R1=14\r\nBR zo,R1=15\r\nBR aa\r\n\r\n'*******Program Motion Components*******\r\n\r\nLB z1\r\nBR aa, P=0     'branch to main prog, position=0\r\nMA 0           'index to abs. pos. 0\r\nH              'Suspend prog. until move completes\r\nCL zz          'call the print position sub.\r\nBR aa          'BR to main prog when complete\r\n\r\nLB za          'same as above\r\nBR aa, P=36000\r\nMA 36000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zb\r\nBR aa, P=-36000\r\nMA -36000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zc\r\nBR aa, P=18000\r\nMA 18000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zd\r\nBR aa, P=-27000\r\nMA -27000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB ze\r\nBR aa, P=9000\r\nMA 9000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zf\r\nBR aa, P=-9000\r\nMA -9000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zg\r\nBR aa, P=4500\r\nMA 4500\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zh\r\nBR aa, P=-4500\r\nMA -4500\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zi\r\nBR aa, P=3000\r\nMA 3000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zj\r\nBR aa, P=-3000\r\nMA -3000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zk\r\nBR aa, P=6000\r\nMA 6000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zl\r\nBR aa, P=-6000\r\nMA -6000\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zm\r\nBR aa, P=7500\r\nMA 7500\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zn\r\nBR aa, P=-7500\r\nMA -7500\r\nH\r\nCL zz\r\nBR aa\r\n\r\nLB zo\r\nBR aa, P=0\r\nMA 0\r\nH\r\nCL zz\r\nBR aa\r\n\r\n'****Print Position Subroutine****\r\nLB zz\r\nR2=P\/100       'set register 2 to position\/100,\r\n               'this will display degrees as the unit\r\n               'of measure for motor position\r\nPR \"Position Selected = \",R1\r\nPR \"Absolute Position (Degrees) = \",R2\r\nRT\r\n\r\nE\r\nPG<\/pre><\/code><\/pre>\n\n\r\n\n<h3 class=\"wp-block-heading\">Binary up counter &#8211; BCD output example<\/h3>\n\n\r\nThe following program example shows the use of the lower output bank as a binary up-counter. IO1 &#8211; IO4 are setup as general purpose outputs, active when HIGH, sinking. The main program will set the outputs, store the decimal equivalent of the outputs, and index the motor a multiple of the output state. Once complete it will increment the register and repeat until the value of the register =15 (binary 1111). It will then clear the register, set the outputs to 0, and restart the process.\r\n\n<pre class=\"wp-block-code\"><code><pre class=\"lang:vbnet decode:true \" title=\"Binary up counter - BCD output example\">'***Global Setup Parameters***\r\nS1=16,1,0\t'O1-4 Set as GP, High Active, Sinking\r\nS2=16,1,0\t \r\nS3=16,1,0\t \r\nS4=16,1,0\t \r\n \t \r\n'***Main Program***\r\nPG 1\t \r\nLB aa\t \r\nCL xx, R1&lt;15\t'Call sub xx R1 less than 15\r\nCL zz, R1=15\t'Call sub zz R1 equal 15\r\nBR aa\t \r\n \t \r\n'***Subroutines***\r\nLB xx\t'subroutine increments R1, moves motor\r\nR1=R1 1\t'multiple of R1 value\r\nOl=R1\t'sets output group to R1\r\nH 1000\t'hold program execution for 1 sec.\r\nMR R1*100000\t'move relative R1 x 100000 steps\r\nH\t'hold until motion completes\r\nRT\t'return from subroutine\r\n \t \r\nLB zz\t'subroutine to resets R1 to 0\r\nR1=0\t'and restart process\r\nRT\t'return from subroutine\r\n \t \r\nE\t \r\nPG<\/pre><\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Global or Local variables Event triggering Input example: Output event Using a Bank of I\/O Move on BCD Input Example Binary up counter &#8211; BCD output example<\/p>\n","protected":false},"author":102,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-1745","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>MCode: Programming MDrive I\/O - Robotics &amp; Automation<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MCode: Programming MDrive I\/O\" \/>\n<meta property=\"og:description\" content=\"Global or Local variables Event triggering Input example: Output event Using a Bank of I\/O Move on BCD Input Example Binary up counter &#8211; BCD output example\" \/>\n<meta property=\"og:url\" content=\"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/\" \/>\n<meta property=\"og:site_name\" content=\"Robotics &amp; Automation\" \/>\n<meta property=\"og:image\" content=\"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/global-vs-local.gif\" \/>\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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/\",\"url\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/\",\"name\":\"MCode: Programming MDrive I\\\/O - Robotics &amp; Automation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2026\\\/01\\\/global-vs-local.gif\",\"datePublished\":\"2017-03-08T21:49:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/#primaryimage\",\"url\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2026\\\/01\\\/global-vs-local.gif?quality=85&strip=all\",\"contentUrl\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2026\\\/01\\\/global-vs-local.gif?quality=85&strip=all\",\"width\":350,\"height\":299},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/mcode-programming-mdrive-io\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MCode: Programming MDrive I\\\/O\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/#website\",\"url\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/\",\"name\":\"Robotics & Automation\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/novanta.com\\\/robotics-automation\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"MCode: Programming MDrive I\/O - Robotics &amp; Automation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/","og_locale":"en_US","og_type":"article","og_title":"MCode: Programming MDrive I\/O","og_description":"Global or Local variables Event triggering Input example: Output event Using a Bank of I\/O Move on BCD Input Example Binary up counter &#8211; BCD output example","og_url":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/","og_site_name":"Robotics &amp; Automation","og_image":[{"url":"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/global-vs-local.gif","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/","url":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/","name":"MCode: Programming MDrive I\/O - Robotics &amp; Automation","isPartOf":{"@id":"https:\/\/novanta.com\/robotics-automation\/#website"},"primaryImageOfPage":{"@id":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/#primaryimage"},"image":{"@id":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/#primaryimage"},"thumbnailUrl":"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/global-vs-local.gif","datePublished":"2017-03-08T21:49:49+00:00","breadcrumb":{"@id":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/#primaryimage","url":"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/global-vs-local.gif?quality=85&strip=all","contentUrl":"https:\/\/novanta.com\/robotics-automation\/wp-content\/uploads\/sites\/3\/2026\/01\/global-vs-local.gif?quality=85&strip=all","width":350,"height":299},{"@type":"BreadcrumbList","@id":"https:\/\/novanta.com\/robotics-automation\/mcode-programming-mdrive-io\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/novanta.com\/robotics-automation\/"},{"@type":"ListItem","position":2,"name":"MCode: Programming MDrive I\/O"}]},{"@type":"WebSite","@id":"https:\/\/novanta.com\/robotics-automation\/#website","url":"https:\/\/novanta.com\/robotics-automation\/","name":"Robotics & Automation","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/novanta.com\/robotics-automation\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/novanta.com\/robotics-automation\/wp-json\/wp\/v2\/pages\/1745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/novanta.com\/robotics-automation\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/novanta.com\/robotics-automation\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/novanta.com\/robotics-automation\/wp-json\/wp\/v2\/users\/102"}],"replies":[{"embeddable":true,"href":"https:\/\/novanta.com\/robotics-automation\/wp-json\/wp\/v2\/comments?post=1745"}],"version-history":[{"count":0,"href":"https:\/\/novanta.com\/robotics-automation\/wp-json\/wp\/v2\/pages\/1745\/revisions"}],"wp:attachment":[{"href":"https:\/\/novanta.com\/robotics-automation\/wp-json\/wp\/v2\/media?parent=1745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}