element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Pi Chef Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Pi Chef Design Challenge
  • More
  • Cancel
Pi Chef Design Challenge
Blog Automatic Dough Shaper - Blog #5 Motor Control
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: a_davis_22
  • Date Created: 8 Mar 2018 1:15 AM Date Created
  • Views 679 views
  • Likes 8 likes
  • Comments 4 comments
  • psoc4
  • automatic dough shaper
  • stepper motor control
  • pi chef design challenge
  • a4988
Related
Recommended

Automatic Dough Shaper - Blog #5 Motor Control

a_davis_22
a_davis_22
8 Mar 2018

In order to cut the dough into shapes, my project uses an XY plotter type of set up. The platform will move back and forth as the Y axis and the cutting head will sit above the platform and move across the platform perpendicular to the Y axis motion. These both need to be able to move to exact positions. Typically in XY plotter projects like mine, stepper motors are used to get this precision.

 

Stepper motors come in a few different varieties; I chose to use a four wire bipolar motor.

 

image

 

As I understand it, these motors have different coil windings that create electromagnetic fields. My motor has 4 wires, which means two coils. Each time a coil is turned on, the motor rotates to align with that coil. So by alternating how each coil is turned on, the motor will end up going in a circle one step at a time. Wikipedia has a great animation of this. Using some tricky powering, these motors can turn in smaller increments than one step. This is called micro-stepping.

 

In looking up how to control stepper motors with a PSoC, I found project #045 which used 3 PWM blocks to control one motor. I thought that was more complicated than it needed to be, especially since I wanted to control 3 motors independently. I figured that there's a more convenient way, probably using a stepper motor driver chip. After searching around I decided to buy some A4988 Stepstick stepper motor driver breakout boards to control my motors. This article from How to Mechatronics was a great help in understanding how to use them.

 

image

image

These boards use Step and Direction input pins to control the motor. The direction can be changed by setting the direction pin high or low, and the step pin moves the stepper motor one step for each pulse sent to it. The sleep and reset pins are activated with a low signal. In order to have the board enabled, these pins have to be high. The sleep pin has a pull up resistor (which makes its default setting high), so connecting them together allows the board to be enabled. The MS1, MS2, and MS3 pins control if the motor moves in full step or micro stepping mode. It uses a binary code to choose the stepping mode. Since I'm going to do full steps I don't need to connect these pins. The enable pin is also active low and by setting it high I can choose when there is power on the motors, but for the first test, I just left it enabled. Vmot and the gnd pin next to it are the connections for the motor's power supply. This power supply will need a capacitor in between the voltage and ground in order to protect the board against power spikes. I'm using a 10uF capacitor. Since my capacitor is electrolytic, I've properly connected the negative side to the ground pin. 2B, 2A, 1B, 1A are the pins that actually connect to the motor's wires. As I learned from this website, my motors have this color scheme for the wires: red and blue connect to one coil (A) and green and black connect to the other (B).  If the wires are not connected properly, the motor may get damaged. VDD and gnd are the pins that connect to the micro-controller's power (3.3V or 5V).

Here's my set up.

 

image

 

Using the A4988 board I can set the direction and then send a PWM signal to the step pin to move the motor. My motors are NEMA17 and take 200 steps to complete a full resolution. By measuring how many pulses I send I can stop the motor when it's at the correct position. This requires only one PWM block per motor. I felt like that simplified things considerably.

 

In trying to set up the control from the PSoC I couldn't find any helpful solutions online, so I had to work on creating my own. I wanted to set the direction and number of pulses, turn on the PWM, and then turn off the PWM when the pulses are done. I first tried implementing this in software, using an interrupt to signal when the pulses were done, but it's been years since I wrote an interrupt service routing (ISR) and I'm better at figuring out hardware. So I decided to try a hardware solution instead. This is what I came up with.

image

In software, the direction pin is first set, and then the control register is given the number of pulses that will be sent. The PWM is also enabled in software and each pulse sends an ouput into the clock of the 8-bit counter. This counter is always enabled, so it just counts on each "clock" signal. When that count reaches the same as the control register value, the compare sends a high signal, which then becomes inverted and subsequently disables the PWM, effectively allowing the motor to run for an exact number of steps. Since the control register is only  8 bits, this only works with steps less than 256. (The code is attached.)

 

image

 

I hooked everything up, booted the program onto my PSoC and tested it out!

 

Nothing.

 

so I tried again.

 

It smelled a little like something was burning, but I couldn't see anything wrong... Then I couldn't get the computer to recognize my PSoC. And after some puzzling I realized that I had accidentally connected the motor's 12v power supply to the same side of the breadboard as the PSoC power to the A4988! I completely burned up my microcontroller! And probably my A4988 too. sheesh.

I guess I learned my lesson. Be extremely careful about where you put the power!

Attachments:
PSoC4_Therm_Motor1.cyprj.Archive01.zip
  • Sign in to reply

Top Comments

  • dougw
    dougw over 7 years ago +2
    I know that smell - It is such a sinking feeling. Full kudos for blogging about it though - it can be really tough to publish problems. Those depressing moments are not only a great teacher, they also…
  • beacon_dave
    beacon_dave over 7 years ago +2
    Ouch ! Perhaps Ben Heck Show episode 249 may be of interest ? Episode 249: Ben Heck's Magic Smoke Preventor Episode On a positive note, at least microcontrollers are relatively cheap items to replace these…
  • mcb1
    mcb1 over 7 years ago +1
    OOps!. That sudden feeling of Duuh. They say we learn from our mistakes and I'm betting that you won't make that one again. Mark
  • genebren
    genebren over 7 years ago

    I learn so much more from my mistakes than from my accomplishment. So I would guess, if you are anything like me, you learn a lot as a result of this experiment.  Don't ever let your mistakes keep you from trying new and difficult things!

    Good job and keep trying!

    Gene

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 7 years ago

    Ouch !

     

    Perhaps Ben Heck Show episode 249 may be of interest ?

    Episode 249: Ben Heck's Magic Smoke Preventor Episode

     

    On a positive note, at least microcontrollers are relatively cheap items to replace these days.

     

    You should be able to test the A4988 driver board in isolation - just manually pulse the input rather than driving it from a microcontroller.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 7 years ago

    OOps!.

    That sudden feeling of Duuh.

     

    They say we learn from our mistakes and I'm betting that you won't make that one again. image

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 7 years ago

    I know that smell - It is such a sinking feeling. Full kudos for blogging about it though - it can be really tough to publish problems.

    Those depressing moments are not only a great teacher, they also make successes that much sweeter.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube