Interface Stepper motor with STM32
A stepper motor divides full rotation into number of equal steps. It finds great application in the fields of Robotics. Today, in this tutorial, we will learn how to interface stepper motor with STM32.
Stepper motors generally comes along with an IC ULN2003. This IC is used to drive motor because microcontroller pins are unable to provide sufficient current to drive these motors. There are three different types of stepping modes used for stepper motors:-
- Wave Drive
- Full Drive
- Half Drive
In this mode only one stator electromagnet is energized at a time. It has the same number of steps as the full step drive. The motor takes 2048 STEPS to complete 1 revolution, which means 2048/4 = 512 sequences per Revolution.
In this mode two stator electromagnets are energized at a time and the motor runs at full torque. Two phases are energized at the same time, and motor have more Torque than the Wave Drive. The motor takes 2048 STEPS to complete 1 revolution, which means 2048/4 = 512 sequences per Revolution.
In this mode, one and two phases are energized alternatively. This mode is used to increase the angular resolution of the motor but the torque is reduced. The Torque remains somewhere in between the Wave Drive and Full Drive. The motor takes 4096 STEPS to complete 1 revolution, which means 2048/8 = 512 sequences per Revolution.
Some Insight into the CODE
First of all create the delay in microseconds. If you don’t understand this part goto https://controllerstech.com/create-1-microsecond-delay-stm32/
Define the number of steps the motor takes for 1 revolution
The above function to set the RPM of the Motor. We have to use it instead of delay.
Above is the function for the Half Drive. The stepper takes 8 steps to complete 1 sequence in half drive.
The function to move the stepper by some angle. Here we can also control the direction and RPM.
Basically, the motor takes 512 sequences to complete 1 revolution. That means 512 sequences for 360 degrees. This converts to 0.703125 degrees per sequence. Using this, we can calculate the sequences required for the particular angle.
. . . . . DOWNLOAD . . . . .
You can buy me acontrollerstech
coffeeSensor by clicking DONATE OR Just click DOWNLOAD to download the code
- WavePlayer using STM32 Discovery January 16, 2021
- How to use SPI in LPC2148 December 26, 2020
- STM32 ADC MULTI CHANNEL WITHOUT DMA December 24, 2020
- Send and Receive data to PC without UART (STM32 USB COM) December 10, 2020
- STM32 GPIO INPUT Configuration December 4, 2020
- STM32 GPIO OUTPUT Config using REGISTERS November 24, 2020