element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
BeagleBoard
  • Products
  • Dev Tools
  • Single-Board Computers
  • BeagleBoard
  • More
  • Cancel
BeagleBoard
Blog BeagleBone Control Stepper Motors with PRU - Part 5: It Works
  • Blog
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
BeagleBoard requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
Author: Jan Cumps
Date Created: 2 Aug 2019 5:58 PM
Views: 243
Likes: 5
Comments: 4
Related
Recommended

BeagleBone Control Stepper Motors with PRU - Part 5: It Works

Jan Cumps
Jan Cumps
2 Aug 2019

I'm trying here is to let the real-time units of the BeagleBone generate the signals for a stepper motor.

In this post: it works! Let's put everything together.

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

 

 

Initialise the Sleep and Reset Signals

 

The pins P9_11 and P9_13 are used. I'm controlling them from the Linux command line.

 

BB MUXBB P9Driver function
GPIO_3011nSleep
GPIO_3113Reset

 

To start, set sleep on and reset off

 

sudo -i

# sleep on

echo out > /sys/class/gpio/gpio30/direction
echo 0 > /sys/class/gpio/gpio30/value

# reset off

echo out > /sys/class/gpio/gpio31/direction
echo 0 > /sys/class/gpio/gpio31/value

 

Set the PRU MUX signals and Load PRU Firmware

 

See the post on pin assignments for the PRU. I'm assuming that you created the binary in this post.

 

config-pin P9_31 pruout  
config-pin P9_29 pruout 

 

cp /home/debian/bin/bb_PRU_STEPPER.out /lib/firmware/bb_PRU_STEPPER.out  
echo 'bb_PRU_STEPPER.out' > /sys/class/remoteproc/remoteproc1/firmware  
echo 'start' > /sys/class/remoteproc/remoteproc1/state 

 

Initialise the Stepper Motor Driver via SPI

 

I'm assuming that you installed the SPI overlay as explained in this post and created the binary in this post.

 

/home/debian/bin/bb_LINUX_STEPPER_SPI

 

 

Wake Up the Stepper Motor Driver

 

# sleep off

echo 1 > /sys/class/gpio/gpio30/value

 

At this point everything is prepared, and you are ready to ....

 

Tell PRU to Step the Motor

 

This is it! Let's take 20 steps back and forth:

 

echo "120" > /dev/rpmsg_pru30  
echo "020" > /dev/rpmsg_pru30 

 

 

Submit as many commands as you want.

 

Motor Heat

Once you disable sleep mode, the motor will pull 600 mA. It's locked in position. It will get hot.

If you don't play with the motor, or your device doesn't need the motor be kept locked in position, put the driver back to sleep:

 

cd /sys/class/gpio/gpio30  
echo 0 > value 

 

 

 

 

Finished? Clean Up.

 

echo 'stop' > /sys/class/remoteproc/remoteproc1/state 

 

config-pin P9_31 default  
config-pin P9_29 default 

 

 

Related blog:
BeagleBone Control Stepper Motors with PRU - Part 1: Intentions
BeagleBone Control Stepper Motors with PRU - Part 2: Test Driving Outputs
BeagleBone: Enable SPI with Overlay and from Command Line
BeagleBone Control Stepper Motors with PRU - Part 3: Hardware Provisioning and Wiring
BeagleBone Control Stepper Motors with PRU - Part 4: SPI Setup
BeagleBone Control Stepper Motors with PRU - Part 5: It Works
Anonymous

Top Comments

  • DAB
    DAB over 2 years ago +1

    Great finish Jan.

     

    DAB

  • Jan Cumps
    Jan Cumps over 2 years ago +1

    The evaluation software for the DRV8711 stepper motor controller kit is very good.

     

    You can use it to test the driver IC (you need a MSP-EXP430G2MSP-EXP430G2 LaunchPad but that one is cheap)

     

    You can set motor…

  • clem57
    clem57 over 2 years ago

    I liked the tip about putting motor to sleep and avoid all the heat!

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 2 years ago

    Here's a shell script that loads latest PRU firmware and sets all pins.

    If you pass --test as parameter, it 'll move the motor 20 steps right and left

     

    Assumptions: you followed the blog (specific: copied the binaries for SPI and PRU to the /home/debian/bin folder and loaded the SPI overlay).

    Be sudo.

     

    to configure the bb:

    ./PRU_STEPPER.sh

     

    to also perform a test, then

    ./PRU_STEPPER.sh --test

     

     

    #!/bin/bash
    
    PRU_STEPPER_link="$(readlink -f /home/debian/bin/bb_PRU_STEPPER.out)"
    fw0_link=${PRU_STEPPER_link}
    
    if [ ${fw0_link} ];
    then
         echo "stop the program if running"
         echo 'stop' > /sys/class/remoteproc/remoteproc1/state 2>/dev/null
         rm /lib/firmware/am335x-pru0-fw &> /dev/null
    
         ln -s ${fw0_link} /lib/firmware/am335x-pru0-fw
    
         echo "load the firmware to PRU"
         echo 'am335x-pru0-fw' > /sys/class/remoteproc/remoteproc1/firmware
    
         echo "start the program"
         echo 'start' > /sys/class/remoteproc/remoteproc1/state
    
         echo ""
         echo "Firmware is running"
         echo ""
    else
         echo "Firmware .out files does not seem to exist. Did you place " ${PRU_STEPPER_link} "?"
         echo ""
    fi
    
    echo "sleep on"
    echo out > /sys/class/gpio/gpio30/direction
    echo 0 > /sys/class/gpio/gpio30/value
      
    echo "reset off"
    echo out > /sys/class/gpio/gpio31/direction
    echo 0 > /sys/class/gpio/gpio31/value
    
    echo "set pin 29 and 31 as PRU GPIO out"
    config-pin P9_31 pruout    
    config-pin P9_29 pruout    
    
    echo "initialise SPI"
    /home/debian/bin/bb_LINUX_STEPPER_SPI 
    
    echo "stepper motor control ready from PRU0"
    
    while test $# -gt 0
    do
         case "$1" in
            --test) 
         echo "test requested"
         echo "sleep off"  
         echo 1 > /sys/class/gpio/gpio30/value
    
         echo "motor move start"
         echo '120' > /dev/rpmsg_pru30
         echo '020' > /dev/rpmsg_pru30
         sleep 1s
         echo "motor move stop"
    
         echo "sleep on"
         echo 0 > /sys/class/gpio/gpio30/value        
                ;;
        esac
        shift
    done

     

    For heat dissipation reasons, I turn the motor in sleep mode when the script exits.

    To wake it up, execute:

    echo 1 > /sys/class/gpio/gpio30/value

     

    To make the motor take 20 steps, execute

    echo '020' > /dev/rpmsg_pru30

     

    To make it go back to sleep:

    echo 0 > /sys/class/gpio/gpio30/value

     

     

    I made this script to make development easier. I compile the binary in CCS then move it to the BB. A single command deploys and tests ...

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 2 years ago

    The evaluation software for the DRV8711 stepper motor controller kit is very good.

     

    You can use it to test the driver IC (you need a MSP-EXP430G2MSP-EXP430G2 LaunchPad but that one is cheap)

     

    You can set motor control parameters. They are dependent on the (current of the) motor you have,

    Several scenarios can be validated and played with.

    This helps to better understand the datasheet.

    It documents all the register settings and what they do. But getting smooth operation is not that easy by just staring at a PDF.

    With the GUI, you can observe the motor behaviour, and then check what configuration settings were applied to the driver:

     

    You can also evaluate the other way around. If you know the register values that a particular firmware uses, you can enter those values in the GUI.

    The registers are broken up in their meaningful entities. There's support to show the raw HEX values.

     

    You can change the registers in the GUI and write them to the driver IC. You can see the motor's behaviour under the circumstances directly.

    This works more intuitive than changing the code and running the firmware again.

    It also helps to find out what the maximum reliable speed is for your motor in a particular application and what an acceptable acceleration rate looks like.

     

    I used this program in this blog series to set up a smooth full-step motor pattern and to see what frequencies and accelerations are OK for my motor.

    It's part of the next step in the series, where I'll try to let the BB PRU calculate a nice smooth trapezoid velocity ramp.

     

     

    Real good evaluation utilities can give a head start. This GUI has done that in the past when I developed for the programmable timer controller of a Hercules MCU.

    I'm using (and appreciating) it again now for the BeagleBone's PRU programming.

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
  • DAB
    DAB over 2 years ago

    Great finish Jan.

     

    DAB

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube