This repository contains an example to generate steps via function generator with the Stepper Driver Reference Design. This design is based on the Multiphase Power Board, the original code example is linked in related documentation. This demo was used to make both code sets.
In Full-Step mode, the motor rotates complete mechanical steps at once - for a standard 200 full-steps/revolution stepper motor, this would be 1.8 degrees for a sub-step. The motor's two coils are powered sequentially in four full-steps. The sequence determines the stepper motor's direction of rotation. Full-Step mode is simple to control, but can cause vibration and noise due to the larger step angle. Another drawback of using this mode is that the stepper motor's current consumption is maximized, with the lowest efficiency. This mode is often used in applications where the drive algorithm simplicity is more important than the smoothness of operation or precision.
In Half-Step mode, four intermediate steps are inserted between the four full-steps, which makes the stepper motor rotate by half of its full-step angle. This effectively doubles the number of mechanical steps per revolution - for a standard 200 full-steps/revolution stepper motor, this would be 0.9 degrees for a complete step, resulting in a smoother operation and less vibration compared to the Full-Step mode. This mode strikes a balance between simplicity, efficiency, smoothness and current consumption.
The Microstep mode divides the full-step angle into even smaller steps, providing even smoother operation and higher precision. The number of microsteps per full-step can vary, but common values are 8, 16, 32, or even 256 microsteps per full-step. Even though this mode requires the most complex control algorithms, the current consumption is lower than in Full-Step and Half-Step modes, with the highest precision, the least vibration and lowest noise. Microstepping is often used in applications where precision and smoothness of operation are paramount, such as in CNC machines.
- AVR® EB Product Page
- AVR EB Code Examples on GitHub
- AVR EB Stepper Example Code on GitHub
- Stepper Driver Reference Design
- MPLAB® X IDE v6.20 or newer
- AVR-Ex DFP-2.10.205 or newer Device Pack
- MPLAB XC8 compiler v3.00
- MPLAB Code Configurator (MCC) v 5.5.0
- AVR EB Curiosity Nano
- Stepper Driver Board
- Bipolar Stepper Motor (such as XY42STH34-035A). This PCB is designed to mount to the back of a NEMA 17 motor (42 mm x 42 mm)
- A Power Supply ( 12 - 24V nominal and 1 - 3A current capability, depending on the chosen motor)
The first application mimics the interface of common stepper driver ASICs with STEP
and DIR
inputs. The DIR
input controls the direction of rotation, while the STEP
input is pulsed to advance the motor. There is also an onboard potentiometer for setting the current limit. The current limit is implemented using two Analog Comparators (AC) being OR'ed together in the Configurable Custom Logic (CCL) peripheral to generate a FAULT signal that shuts down the Waveform EXtension (WEX) for the remainder of the PWM cycle. The start of the next PWM waveform will clear the fault.
The second application is a customized version of this demo to match the custom PCB.
Note: For a standard 200 full-steps/revolution stepper motor, 1.8 mechanical degrees represent 360 electrical degrees (360 electrical degrees/200-steps is 1.8 mechanical degrees).
Before using a stepper motor, set the constants in the stepper.h
file
There are a few motor specific options that need to be addressed when swapping motors:
R
: motor winding resistance expressed in [ohm]
I_OUT
: Motor Peak Current expressed in [mA]
To change the stepping mode, uncomment the corresponding macro in stepper.h
.
Then, if using the potentiometer current limit, monitor the signals OUT1 and OUT2 on the pin header (1V/A) with an oscilloscope while adjusting to set the appropriate level.
This project can be replicated in MCC, with the exception of the stepper.h
and stepper.c
files. These will have to be imported from this project.
- Global Interrupts Enable: Enabled
- Prescaler enabled: Disabled
- Sample Duration : 255
- ADC Enable: Enabled
- Left Adjust: Enabled
- Start command: Start a conversion immediately
- Free Running: Enabled
- ADC Positive Channel Selection: ADC Input 20
- ADC Negative Channel Selection: Ground
- Positive input MUX Selection: Positive Pin 4
- Negative input MUX Selection: Negative Pin 3
- Positive input MUX Selection: Positive Pin 6
- Negative input MUX Selection: Negative Pin 3
- BOD Operation in Active Mode: Enabled in continuous mode
- BOD Level: 2.7 V
- BOD Operation in Sleep Mode: Disabled
- Enable CCL: Enabled
For LUT0 - Connect the LUT as above, and edit the LUT configurations.
- Enable LUT: Enabled
- Clock Selection: OSCHF
- Gate Type: OR
- Timer Enable: Enabled
- Waveform Generation Mode: SINGLESLOPE
- Scaling Mode: BOTTOM
- Amplitude Control Enable: Enabled
- Generate ISR: Enabled
- Overflow Interrupt Enable: Enabled
- Global Override Settings for Waveform Outputs : All outputs enabled
- Deadtime inserion Channel 0-3: Enabled
- Requested Dead-time Low Side: 0.2us
- Requested Dead-time High Side: 0.2us
- Fault Input A Enable: Enabled
- Fault Event Input A Blanking Enable: Enabled
-
(Generators): Channel 1 CCL_LUT0 ->
-
(Channels): Channel 1 ->
-
(Users): WEX A
The original example was designed to move multiple steps in a single operation. Because of this, single step causes some functions to have degraded performance. Macros such as SPEED_LIMIT
and STEPS_TO_SUBSTEP
can be adjusted to modify the performance, but will impact the behavior of single step.
SPEED_LIMIT
adjusts the delay between each step, instead of allowing the motor to go fasterSTEPS_TO_SUBSTEP
improves the smoothness of motion, but causes the motor to advance more than expected
Below are images of the Over Current Protection (OCP) limiting the motors current based on the position of the potentiometer.
350 mA Testing
Without Current Limiting
With Current Limiting
3 A Testing
Without Current Limiting
With Current Limiting
Below are images taken during the 3A Motor Testing, it should be noted that the board may get warm.
This GIF shows the stepper motor hooked up to a function generator. It also shows here the LED and direction change made by the DIR pin being set.
This GIF shows the second example, which has the motor change its speed and direction via software. The speed and steps can be changed in software.
This has shown the benefits of using the AVR EB as a stepper motor controller. More information about this reference design is available from microchip