This is the uStepper Arduino library, providing software functions for the different features of the uStepper board.
- Features
- The uStepper library contains the following features:
- Second order acceleration profile, to provide smooth ramping of the speed and to avoid the motor stalling when demanding high speeds.
- Temperature measurement of the stepper driver chip by means of a NTC resistor placed beneath the chip.
- Measure the current position of the shaft (absolute, multiple revolutions)
- Measure the current speed of the motor
The library uses both timer one and timer two in order to function properly, meaning that unless the user of this library can accept the loss of some functionality, these two timers are unavailable and the registers associated with these timers should not be reconfigured.
Timer one is used for sampling the encoder in order to provide the ability to keep track of both the current speed and the angle moved since the board was reset (or a new home position was configured). Also the drop-in features missed step detection and correction is done in this timer.
Timer two is used to calculate the stepper acceleration algorithm.
- Warning
- In order to get some features working, it was necessary to write functions to control the I2C hardware in the MCU, since the build in wire library of Arduino uses interrupt which doesn't play well when used inside a timer interrupt routine. Therefore if the user of this library needs to use the I2C bus, the user should use the functions defined in this library instead of wire library !
- Installation
- To install the uStepper library into the Arduino IDE, perform the following steps:
- Download uStepper.zip
- Open the Arduino IDE
- Select sketch from the top menu
- Select include library
- Select add .ZIP library
- Navigate to where you downloaded uStepper.zip to and select
- The library contains support for driving the stepper, measuring temperature and reading out encoder data. Two examples are included to show the functionality of the library.
The library is tested with Arduino IDE 1.6.10
- Warning
- MAC users should be aware, that OSX does NOT include FTDI VCP drivers, needed to upload sketches to the uStepper, by default. This driver should be downloaded and installed from FTDI's website:
-
http://www.ftdichip.com/Drivers/VCP.htm
-
The uStepper should NOT be connected to the USB port while installing this driver !
-
This is not a problem for windows/linux users, as these drivers come with the arduino installation.
- Theory
The acceleration profile implemented in this library is a second order profile, meaning that the stepper will accelerate with a constant acceleration, the velocity will follow a linear function and the position will look like an S-curve (it will follow a linear function at top speed and a second order function during acceleration and deceleration). As a result, the position of the stepper motor will have continous and differentiable first and second derivatives.
The second order acceleration profile can be illustrated as follows (Source):
From the above picture it can be seen how the motor moves with this second order acceleration profile. The postion is depicted as orange, velocity as red and the acceleration as green.
The algorithm used is NOT designed by me, I ONLY implemented the algorithm! credit is therefore given to the appropriate author: Aryeh Eiderman.
for those interested, the deriviation of the algorithm used can be found at the following webpage (Which is neither owned nor affiliated with ON Development IVS in any way): Real Time Stepper Motor Linear Ramping Just by Addition and Multiplication
- Copyright
(C)2016 ON Development IVS
www.on-development.com
admin.nosp@m.istr.nosp@m.ation.nosp@m.@on-.nosp@m.devel.nosp@m.opme.nosp@m.nt.co.nosp@m.m
The code contained in this file is released under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
The code in this library is provided without warranty of any kind - use at own risk! neither ON Development IVS nor the author, can be held responsible for any damage caused by the use of the code contained in this library !
- To do list
- Clean out in unused variables
- Update comments
- Implement PID-controller into dropin feature
- Implement multiaxis feature between multiple uSteppers
- Add support for limit switches
- Split the library into multiple files
- Known Bugs
-
- Author
- Thomas Hørring Olsen (thoma.nosp@m.s@us.nosp@m.teppe.nosp@m.r.co.nosp@m.m)
- Change Log
- Version
- 0.4.5:
- Changed setup of Timer1 and Timer2, to allow for PWM generation on D3 and D8. See documentation of "pwmD3()" and "pwmD8()" functions in class "uStepper", for instructions.
- Changed setup of external interrupts for dropin feature, to be able to compile with arduino IDE 1.6.10.
- Updated board installation package to version 1.1.0, to be compliant with arduino IDE 1.6.10. Update uStepper board using package manager in Arduino IDE ("Tools->Board->Board Manager", scroll down to the uStepper board and choose update or install).
-
0.4.4:
- Added the attribute "used" to declarations of interrupt routines. This enables the library to be compiled in Arduino IDE 1.6.10
- Updated documentation of "uStepper::setup()"
-
0.4.3:
- Fixed bug where initial deceleration phase (used when changing speed setting or changing direction while motor is moving), would never be entered, causing motor to accelerate
-
0.4.2:
- Fixed bug with setHome() causing getAngleMoved() to return alternating values (offset by exactly 180 degrees) between resets.
- Fixed bug in runContinous(), where direction of the motor did not get updated if the function was called with the motor standing still.
-
0.4.1:
- Fixed bug with getAngleMoved() returning alternating values (offset by exactly 180 degrees) between resets.
- Added keywords
- Updated pin connection description for Drop-in example
-
0.4.0:
- Added Drop-in feature to replace stepsticks with uStepper for error correction
- Fixed bug in stepper acceleration algorithm, making the motor spin extremely slow at certain accelerations. Also this fix reduced the motor resonance
- Implemented an IIR filter on the speed measurement, to smooth this out a bit.
-
0.3.0:
- Added support for speed readout
- Added support for measuring the shaft position with respect to a zero reference. (absolute within multiple revolutions)
-
0.2.0:
- Complete rewrite of the stepper algorithm in assembler
- Changed from fixed point to floating point variables, due to the need for more precision
- Removed the getSpeed() method, as it didn't work, and therefore it would make more sense to remove it and re-add it when i get the time to fix it
- Added a few doxygen comments
- Added a new method (getStepsSinceReset()), which returns all steps performed since reset of the uStepper. positive values corresponds to steps in clockwise direction, while negative values corresponds to steps in counterclockwise direction.
-
0.1.0: