NOTE: This is the legacy STM32 based design which was replaced by the single board, Raspberry Pi Pico design at https://github.com/zapta/simple_stepper_motor_analyzer.
https://github.com/zapta/legacy_stepper_motor_analyzer
Michael from the Teaching Tech youtube channel made a great video explaining how stepper motors work and used the Simple Stepper Motor Analyzer for some of the demonstrations.
Diagnosing the operation of stepper motor in 3D printers and CNC machines used to require stepper motor analyzers that costs thousands of dollar. Not anymore! The Simple Stepper Analyzer ('Analyzer' in short) brings these capabilities to every maker for a tiny fraction of the price and with a minimalist DIY electronic design that leaves the heavy lifting to the firmware.
The Analyzer is self contained, has two 4-wires pass-through connectors connecting the stepper motor, is powered from a common 5V charger with a micro USB cable, provides a simple to use graphical user interface with a 3.5" color touch screen, and provides a plethora of stepper motor measurements.
The Analyzer is provided to the community as a public domain reference design that can be built and used as is, or be customized with additional features or for a lower cost as desired. The hardware and firmware come with a liberal open source license (CC0) that allows commercial usages and doesn't require code source code sharing.
THE DESIGN IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DESIGN OR THE USE OR OTHER DEALINGS IN THE DESIGN.
NOTE: This pages outlines the open base construction options which is easier and straight forward. For a more involved and potentially more satisfying construction option, which is also featured in the Teaching Tech youtube video, see https://github.com/zapta/legacy_stepper_motor_analyzer/blob/master/case_option.md
The principle of operation is very simple, and so is the hardware design. The stepper motor is connected via 4 wire pass-though connectors that allow the Analyzer to monitor the current through the stepper's coils. The Analyzer's user low impedance current sensors that are galvanically isolated such does not interfere with the operation of the 3D printer or other equipment it monitors. The Analyzer measures the coils currents 100k times a second and uses firmware that analyzes the data, extracts the desired measurements, and present them on the screen. For example, this is how an analysis of the distribution of distance by speed distribution looks like:
NOTE: The two pass-through connectors of the Analyzer are symmetric and each can act as an input or output.
CAUTION: Always connect and disconnect stepper motors when their controller is not energized, to reduce the risk of damage to the controller due to high voltage spikes. The analyser itself is not subject to that risk since its uses galvanically isolated current sensors.
NOTE: The only requirement for proper wiring is that the two wires of one coil should go through pins pair 1,2 and the two wires of the other coil should go through pin pair 3,4. The Analyzer doesn't care about the +/- polarity of the wires in each pair, nor does it care which of the two pass-through connectors is on the controller side and which one is on the stepper side.
TRIVIA:: The pin out and the connector type of the Analyzer follows the Duet3D conventions, except that is uses right angle connector to save space.
The Home page is first page shown when the Analyzer is powered on. It provides summary information as well as access to the Settings page.
Field | Description |
---|---|
COIL 1 | Momentary coil 1 current in Amps. |
COIL 2 | Momentary coil 2 current in Amps. |
ERRORS | The number of phase errors detected so far. Phase errors happens when the current patterns are so distorted that a forward/backward movement cannot be determined. |
POWER | Indicates if the stepper motor is currently energized. This is determined by the sum of currents in they two coils. |
IDLES | The number of times that stepper motor change status from energized to non energized. |
STEPS | The distance the stepper moved so far. Each full step forward increments this value by one and each full step backward decrements it by one. When the stepper motor is energized, the display also shows fractional steps in resolution of 1/100th of a full step. |
HINT: The fractional step value cannot be reset because it is derived from the momentary currents in the two coils. Only the stepper motor driver can reset the fraction by positioning the stepper motor on an exact full step.
HINT: To swap forward/backward directions of the Analyzer use the Settings page. This does not affect the stepper motor itself.
Action | Description |
---|---|
Clear all data. | |
Open the Settings page. |
This is a special page that is accessible from the Home page and allows to calibrate the Analyzer. The settings are stored in a non volatile memory and are preserved when the Analyzer is turned off.
Data | Description |
---|---|
COIL 1 | The momentary current of stepper coil 1 in Amp units. Should be zero, or very close to zero, when the stepper motor is disconnected. |
COIL 2 | The momentary current of stepper coil 2 in Amp units. Should be zero, or very close to zero, when the stepper motor is disconnected. |
Action | Description |
---|---|
SET ZERO | Used to calibrate the zero reading of the current sensors. To do so, Disconnect the stepper motor and press this button. |
REVERSE STEPS DIRECTION | Changes the forward/backward step directions of the Analyzer. Does not affect the stepper motor itself. Having the correct direction is important for measurements such as the Retraction analysis. |
Press exist the Settings page. |
This page measure the stepper speed in units of full steps per second.
Data | Description |
---|---|
Speed Dial | The speed dial shows the momentary stepper speed in full steps per second units. Forward speed is on the right side and backward speed is on the left. |
Speed Value | This field shows the speed in a numeric form. IT is updated less frequently than the dial to allow easy reading. |
HINT: The Settings page allows to swap the forward/backward directions.
Action | Description |
---|---|
Clears all data. | |
Tap the dial | Toggles the dial's speed range. |
This page shows scrolling graph with the total number of full steps vs. time.
Data | Description |
---|---|
Distance Graph | This graph shows how the distance, in units of full steps, changes over time. |
Distance value | The numeric value of the distance in full steps. This fields is identical to the STEPS field in the Home page. |
Action | Description |
---|---|
Clears all data. | |
Tap the graph | Toggles the range of the vertical axis. |
This page is useful to analyze the retraction in of 3D printer extruder.
TRIVIA: The graph above was taken while testing a direct extruder printer with Thing #909901.
Data | Description |
---|---|
Retraction Graph | This graphs tracks the retraction of 3D extruder full step units. Retraction is defined as the filament length that was inside the extruder and is now retracted outside of the extruder. |
Retraction value | This field shows the current retraction level in a numeric form. |
Action | Description |
---|---|
Clear all data. | |
Tap the graph | Changes the range of the vertical axis. |
This page shows an histogram with the distributing of time by stepper speed. That is how much time was spent in each speed range. The values are normalized such that the longest bar is always at 100%.
Data | Description |
---|---|
Time Histogram | The horizontal axis indicates speed in full steps per second units. The height of each bar indicate the time of all steps in that speed range, with the length of the longest bar normalized to 100%. |
Action | Description |
---|---|
Clear all data. |
This page shows an histogram with the the distribution of distance by stepper speed.
Data | Description |
---|---|
Distance Histogram | The horizontal axis indicates speed in full steps per second units. The height of each bar indicate the distance or number of steps in that speed range, with the length of the longest bar normalized to 100%. |
Action | Description |
---|---|
Clear all data. |
This page measures the ability of the stepper motor's controller to maintain peak current at high speeds.
The screenshot below shows a healthy system where the peak current is virtually flat across the speed range.
The screenshot below shows a system that is not capable to maintain peak current and starves the stepper motor at high speeds, resulting in poor torque and possible skipped steps.
Data | Description |
---|---|
Peak Current Histogram | The horizontal axis indicates speed in full steps per second units. The height of each bar indicates the average peak current in Amps of steps that speed range. |
Action | Description |
---|---|
Clear all data. |
This page shows the current patterns in the two stepper coils.
The screenshot below shows a healthy system where the signals are nice and clean and reaches the target peak current.
The screenshot below is from a poor system where high speed results in distorted and insufficient current, resulting in loss of torque and a potential for skipped steps.
GENERAL INFORMATION: Each cycle of the stepper current pattern represent 4 full steps. The centers of those steps are at on the four vertical dotted lines where the currents of the two coils are identical, in the same or in opposite polarities. The transitions between the steps are on the 4 vertical solid lines where one of the coils is at zero current. This cycle of 4 full steps is sometimes referred to as a single 'electric rotation'. The analyzer computes the exact phase on this cycle using the standard trigonometric function atan2(current1, current2) which can also be calculated manually from the current readings in the Home page.
Data | Description |
---|---|
Current graph | The horizontal axis indicates time in milliseconds. The vertical axis indicate coil current level in Amps. The two graphs show the current patterns of the respective stepper coils. |
NOTE: The graph is updated only when sufficient stepper motor movement is detected.
Action | Description |
---|---|
Clear all data. | |
When running, pauses the display updates. | |
When paused, resume the display updates. | |
Tap the graph | This toggles the range of the horizontal axis. |
This page draws the current patterns of the two coils as a Lissajous curve which allows to examine visually distortions such as non sinusoidal current, phase distortion, and reduced amplitude.
In an ideal system, the graph is a perfect smooth circle, that doesn't change its size when the stepper's speed changes. Patterns that significantly diverge from that indicates a sub optimal configuration and operation.
Following picture shows a pattern from a well functioning system. The graph is round, reasonable smooth, and has sufficient size which indicates good current drive.
The horizontal axis indicates the coil 1 current and the vertical axis indicates coil 2 current. In this example, both span nicely between -2A to +2A.
The screenshot below is from a poor system where high speed results in distorted and insufficient current, resulting in loss of torque and a potential for skipped steps. The pattern is far from a clean circle and the shape has reduced size.
The screenshot below shows a sub optimal operation where a a speed increase of the stepper results in small (less current and torque) and even more distorted curve.
The screenshot below shows a well functioning system. The smaller size of the circle compare to the example above indicates that it operates on lower current.
The screenshot below show an operation of a stepper in full steps mode. The dimension of the pattern indicate good current feed, and the square shape is the best a full step driver can deliver.
The screenshot below show an operation of a stepper in half steps mode. The dimension of the pattern indicate good current feed, and the shape is somewhere between the square shape of full step mode and the round shape of micro stepping interpolation mode.
Data | Description |
---|---|
Lissajous curve | A Lissajous curve drawn from the current pattern of coil 1 (x) and coil2(y). |
Capture speed | Shows the signal capture time. Fast mode works better with fast moving steppers and slow mode works with slow moving steppers. Tap the graph to toggle. |
NOTES
Action | Description |
---|---|
Clear all data. | |
When running, pauses the display updates. | |
When paused, resume the display updates. | |
Tap the graph | This toggles the capture time between fast and slow speeds. |
Item | Specification |
---|---|
Power consumption | 5V, 175ma. |
Power connector | micro USB |
MCU | 32bit ARM STM32F401CE @ 84Mhz. |
Flashing | USB/DFU or SWD/Stlink V2. |
Data link | USB/Serial link available but not used. |
Current measurement | +/-2.5A per coil. +/-5A sensors available. |
Dimensions | 97 x 66 mm |
TFT Resolution | 480 x 320, Color. Landscape mode. |
Touch screen | Capacitive |
Sensor isolation | See ACS70331 data sheet |
Sampling rate | 100Khz per channel. |
Sampling resolution | 12bits |
Current accuracy | estimated at +/- 1% |
Max speed | Software dependent. Currently 2K full steps/sec. |
Step resolution | 1/100th of a full step. |
Partial steps measurement | Software dependent. Not implemented. |
Settings storage | On board EEPROM chip. |
GUI framework | LVGL library. R3G3B2 color depth. |
Programming language | C++ |
Programming IDE | Platform.io. Arduino/STM32. |
Cad package | Kicad. |
The electronic schematic, PCB layout, gerber files, and the firmware source files and released binary are all available on this github repository.
ERRATA: The current PCB version leaves the RD input on the TFT (pin 26) floating which can interfere with the operation of the display. One workaround is to patch the board with a resistor to pull the input to +3.3v (but not to +5V!!!). See the errata in the latest schematic for more details.
Instructions: Build the PCB, use DFU or SWD protocols to program the released binary into the Blackpill, plugin the TFT screen, power and use. See instructions below on how to flash the firmware release you can find on this github repository.
NOTE: These instructions are for the simpler version which uses an open frame base. For ordering parts and building the enclosed version see https://github.com/zapta/legacy_stepper_motor_analyzer/blob/master/case_option.md .
Flashing the Analyzer with firmware can be done in a few ways. For software developers we recommend using StLink V2 and SWD which are well supported by the platformio IDE and enable debugging ans single stepping. A simpler approach that is recommended for end users is to use the builtin DFU protocol of the Analyzer's STM32 processor such as the one we use here. Adafruit has a good description of the process. The only difference that to enable the DFU bootloader mode connect the analyzer to the computer while its BOOT0 on button on the back is pressed.
ONLINE LOADER: We also had good results with Google Chrome browser and this online loader https://devanlai.github.io/webdfu/dfu-util/ . The Analyzer should appear as STM32 BOOTLOADER and should be programmed with the configuration Internal Flash 0x08000000.
The source code of the Analyzer is available on this github repository. It is a STM32 C++ Platformio project that uses the Arduino framework. The user interface is based on the LVGL library and the project includes its own port to support TFT/Touch used. Knowledge of C++ and Platformio is required and is outside the scope of this document.
We provide here a 3D model of a simple open frame carrier. This design does not requires attaching the analyzer and the TFT board with screws or spacers and guarantees proper separation on the loose end. If you have an interesting design which you would like to share, please post in a model sharing site such as cults3d, thingiverse or grabcad and we will link it here.
This open frame base does not require any spacers between the two boards and was designed to prevent them from unintentionally touching each other.
The Analyzer is provided as a fully functional reference design and changes and the developers encourage improvement/modifications of the hardware and/or firmware are encouraged. This can include new features, new measurements and pages, extending the design to support 2 or 3 steppers at once to track the x/y/z of a 3D printer, reducing the hardware cost using less expensive screen TFT, or even eliminating the screen altogether and using the Analyzer as a dongle tethered to a computer via the existing USB/Serial link.
A: We could not achieve fast enough display refresh rate with SPI so switched to 16 bit parallel data transfers.
A: Yes, but it may require firmware changes.
A: Yes. The Analyzer has a USB/Serial output can a small Analyzer dongle can communicate with a computer program. This will require firmware changes.
A: Yes. The PCB was designed for both 0.1" header and 40 pins 1.0mm FFC cable connections. You will need a short (e.g. 60mm or less) type B ('reversed') FFC cable. Cables longer than let's say 100mm may introduce noises the will interfere with the operation of the display.
A: Most likely not. The reference design is provided for the community to change and mix.
A: Most likely not. The reference design is open source and you will need to find others to help you.
A: Use the github repository.
A: Of course. The Analyzer is isolated from the stepper wires and should not interfere with the operation of the printer.
A: At the time of writing this, the LVGL license is available here https://github.com/lvgl/lvgl/blob/master/LICENCE.txt. The Analyzer's developers are not affiliated with LVGL.
A: It's not needed. LVGL is supported by platform.io so the Analyzer's project is set for platform.io to fetch LVGL automatically.
A: The provided firmware assumes a 25Mhz crystal. For a 8Mhz crystal you will need to change the firmware.
A: Most like it will work with the provided firmware as is (and with no performance benefits), but we do not guarantee it. We may switch the official reference design to the STMF411CE/25Mhz if the STM32F401CE/25Mhz, which is less expensive, will not be available.
A: No, unless if you are willing to change the PCB.