{"id":738,"date":"2024-06-22T16:17:38","date_gmt":"2024-06-22T16:17:38","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=738"},"modified":"2024-08-11T14:42:59","modified_gmt":"2024-08-11T14:42:59","slug":"stepper-motor-control","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=738","title":{"rendered":"Stepper Motor Control"},"content":{"rendered":"<p>Stepper motor is an electromagnetic device that converts digital pulses into mechanical shift rotation. It has high simplicity, since no brushes or contacts are presents, low cost, high reliability, high torque at low speed, and high accuracy of motion. Types of stepper motors-<\/p>\n<ol>\n<li>Bipolar Stepper Motor<\/li>\n<li>Unipolar Stepper Motor<\/li>\n<\/ol>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/Stepper-motor.png\" alt=\"\" width=\"590\" height=\"180\" \/><\/p>\n<p>The bipolar motor is activated when current in both directions through the windings and a full bridge driver is needed. The center tap on the unipolar motor allows a simple driving circuit, limiting the current flow to one direction. The main drawback with the unipolar motor is the limited capability to energize all the windings at any time, resulting in a lower torque compared to the bipolar motor. The unipolar stepper motor can be used as a bipolar motor by disconnecting the center tap.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The AVR pins cannot be used to drive the coils directly, since it can sink or source 20mA current only. So we need a driver and that is ULN2003A. It is a high voltage , high current Darlington pair array. It can be used to converts TTL(Transistor Transistor Logic) level input to desired input level.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/motor.png\" alt=\"\" width=\"590\" height=\"207\" \/><\/p>\n<h6>Full Vs Half stepping control logic<\/h6>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Stepper motor used in full-stepping mode powers one winding at a time. On the other hand by powering both windings simultaneous, the stepper motor is trapped between the positions obtained when full-stepping, also known as half-stepping.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/stepping.jpg\" alt=\"\" width=\"1022\" height=\"257\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/c-structure-1.jpg\" alt=\"\" width=\"200\" height=\"37\" \/><\/p>\n<\/p>\n<h5>Arrays-<\/h5>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 An array is a fixed-sized sequenced collection of elements of the same data type. Array is nothing but a table of collection of same data type. Following types of arrays are commonly used-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/array-300x83.jpg\" alt=\"\" width=\"280\" height=\"78\" \/><\/p>\n<ul>\n<li>Declaration of one dimensional array<\/li>\n<\/ul>\n<h6>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>data_type variable_name[size]=initialized<\/strong>;<\/h6>\n<p>If we doesn\u2019t initialized at begin the default value of all array elements should be zero.\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/1-dimentional-Array.jpg\" alt=\"\" width=\"1321\" height=\"106\" \/><\/p>\n<p>So size is number of storage that allocated in the memory location.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i.e. char name[20]=\u201dshani\u201d<\/p>\n<p>Here name is a character array that allocated 20bit of memory space, but in this case only 0-18 position will be filled with character and 19<sup>th<\/sup> character will be \u2018\u0000\u2019(null character). Although we allocate 20bit only 5bits are initialize so other remain 14bits contents zero that is \u2018\u0000\u2019(null character).<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 After declare the array, if we do not initialize the array than each element value should be zero.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i.e. int digit[8]&#8212;&#8211;&gt; all the value is zero<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 float data_point[3]={2.1,0};<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The 0 and 1 value is corresponding to 2.1 and 0 and other two element is automatically become zero. If we initialize more than the size then an error occur.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i.e. char name[10]=\u201dRUET EEE 09\u201d<\/p>\n<p>The declaration is illegal since there is an size error.<\/p>\n<p>Note that all other data type are initialize inside {} but character are initialize inside \u201c\u201d . Also note that a collection of character i.e. character array is string that will be discuss later.<\/p>\n<ul>\n<li>Declaration of Two dimensional array<\/li>\n<\/ul>\n<h6><strong>data_type array_name[row_size][column_size]=initialization;<\/strong><\/h6>\n<p>\u00a0i.e. double digit[3][2]<\/p>\n<p>This allocate memory space 4*3bits as shown in table.<\/p>\n<style>\/*! elementor - v3.22.0 - 17-06-2024 *\/<br \/>\n.elementor-widget-image{text-align:center}.elementor-widget-image a{display:inline-block}.elementor-widget-image a img[src$=\".svg\"]{width:48px}.elementor-widget-image img{vertical-align:middle;display:inline-block}<\/style>\n<p>\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"262\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/half-stepping-1024x419.jpg\" alt=\"\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/half-stepping-1024x419.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/half-stepping-300x123.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/half-stepping-768x314.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/half-stepping.jpg 1362w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t<\/p>\n<p>For Counter Clock Wise (CCW) direction the sequence is from 1 to 8 and for Clock Wise (CW) flow from 8 to 1.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/************************************************************************************************\n*************************************************************************************************\nThis program will drive the sepper motor in Full stepping \n\/*********************************************************************************************\/\n\/*****           Stepper Motor Counter Clock Wise (CCW) Direction 1-8                *********\/\n\/*****           Stepper Motor Clock Wise (CW) Direction          8-1                *********\/ \n\/*****                  | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |                            *********\/\n\/*****      Red     --- | + | + | + | + | + | + | + | + |                            *********\/\n\/*****      Orange  --- | - | - |   |   |   |   |   | - |                            *********\/\n\/*****      Yellow  --- |   | - | - | - |   |   |   |   |                            *********\/\n\/*****      Pink    --- |   |   |   | - | - | - |   |   |                            *********\/\n\/*****      Blue    --- |   |   |   |   |   | - | - | - |                            *********\/\n\/*********************************************************************************************\n************************************************************************************************\n***********************************************************************************************\/\n#include &quot;avr\/io.h&quot;\n#include &quot;util\/delay.h&quot;\n#define STEPPER_DDR \tDDRD\n#define STEPPER_PORT \tPORTD\n#define STEP            1024 \/\/90degree\nint motor_pattern_CCW&#x5B;8] = {0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};\nint motor_pattern_CW&#x5B;8] = {0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};\nint main(void)\n{\n DDRB&amp;=~(1&lt;&lt;DDB0);\n STEPPER_DDR |= 0x0f; \/\/ making PORTD as output\n unsigned int index=0;\n while(1)\n    {\n\t  if(PINB&amp;(1&lt;&lt;PINB0)) STEPPER_PORT = motor_pattern_CCW&#x5B;index++];\n\t  else STEPPER_PORT = motor_pattern_CW&#x5B;index++];\n\t  index = index % 8;\n\t  _delay_ms(10);\n\t}\n\treturn 0;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-c918dbea wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-font-size has-medium-font-size\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Stepper-Motor-Control.rar\" style=\"border-radius:18px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Stepper-Motor-Control.rar\">Download the full program with proteus simulation<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Stepper motor is an electromagnetic device that converts digital pulses into mechanical shift rotation. It has high simplicity, since no brushes or contacts are presents, low cost, high reliability, high torque at low speed, and high accuracy of motion. Types of stepper motors- Bipolar Stepper Motor Unipolar Stepper Motor The bipolar motor is activated when [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-738","post","type-post","status-publish","format-standard","hentry","category-i-o-port-operations"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=738"}],"version-history":[{"count":63,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/738\/revisions"}],"predecessor-version":[{"id":2539,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/738\/revisions\/2539"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}