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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 4: PIO
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 4 Apr 2025 2:08 PM Date Created
  • Views 905 views
  • Likes 8 likes
  • Comments 6 comments
Related
Recommended
  • pico
  • pico_eurocard
  • PIO

Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 4: PIO

Jan Cumps
Jan Cumps
4 Apr 2025

The Pico has a set of PIO co-processors. They are real-time controllers that can execute logic with deterministic timing. Ideal to run strict-timed sequences and state machines. And to implement extra peripherals.
In this series, I'm trying to use the PIO to control a TI DRV8711 stepper motor controller.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Follow up of   Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 3: GPIO .

The First 3 posts dealt with anything except the PIO part. Pin assignments and initialisation, SPI setup, DRV8711 driver and communication. This post handles the PIO.
Nothing new here. This post reuses everything from  the hackster project PIO Stepper Motor Control - an example that uses the Allegro A4988 stepper driver.

I selected that one because the PIO part is about as simple as it gets: generate a train of pulses. You can tell it the frequency and how many pulses. Then the state machine generates these for you. The pulses are sent to the stepper motor driver, and that takes care that the motor steps.

Here is the very summere PIO script:

.program stepper_1
;.side_set 1

.define public STD 1

.wrap_target
bitloop:
    out x, 1       ; Side-set still takes place when instruction stalls
    jmp !x do_zero ; Branch on the bit we shifted out
do_one:
    set pins 1     [STD + 3]
    set pins 0     [STD]
    jmp  bitloop   
do_zero:
    set pins 0   ; Or drive low, for a short pulse
.wrap

There is also the usual PIO init code in that file. Check the author's GitHub for the full listing. It's a good example if you are a beginning PIO designer.

All intelligence is in the main C code.

  • Set up of your motor configuration (in my case: 200 steps are a full 360°). 
  • logic to calculate how many steps to take to move from current position to the requested angle (left turn, right turn or shortest path)
  • hand over info to the PIO state machine

Here is that C code from the original author. My Pico project, with sources adapted for DRV8711, is attached at the end of this post.

Main differences:

  • DRV8711 requires SPI communication to set it up
  • I  use its microstep capability. I configured it to use 8 microsteps for a full single step
  • I run the PIO at 5 times the speed of the example
  • my motor has 200 steps per rotation. With the microsteps configuration that becomes 1600 steps. The original uses a stepper with 800 steps.

A lot more of the logic can be implemented inside the PIO, so that it becomes an autonomous motor manager. You could even try to make it perform speed ramp-up and -down.
But then, this post wouldn't be a simple PIO example anymore.

pio_drv8711_stepper.zip

That's it for this series. Enjoy.

  • Sign in to reply
  • Jan Cumps
    Jan Cumps 11 months ago

    If you want to directly control a H-bridge for a stepper motor, look at this PIO script: https://gist.github.com/cleverca22/fea42ae43e18b9e563a1578a7d54c03b. 

    It allows stepping and micro-stepping without a dedicated stepper motor driver. An H-bridge IC will do.

    • Cancel
    • Vote Up 0 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 © 2026 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