Attiny85 As a Step/Dir Stepper Motor Controller

Somewhere in Greece, someone did something never done beforeā€¦
Seen those things before?
Thing: 1
Thing: 2
Thing: 3
Oh, you have! You bought one of them you say? Ohā€¦ Donā€™t worry, I did too.
They did the job, yeah. But we paid for them much. Really much. And while our whole project would cost less than 60 bucks or euros without them, they slapped as in the face, then took our money and ran ā€¦ our precious motorsā€¦
The revenge has comeā€¦Attiny85 As a Step-Dir Stepper Motor Controller
We all love steppers! They do some really nice things.
1) They ran great CNC systems, that make all kinds of goods!
2) They play music, sometimes better than humans!
Basically They do only those two things but they are enoughā€¦
We, people, often control them via computers or microcontrollers and make them do those nice things and live happily together.
Steppers differ from DC motors structurally and behaviorally. They have 4 control wires (instead of 2) and, in order to make the rotor move, you have to apply voltage to some combinations of them, and change the combinations over small (really small) time intervals (maybe every 0.01 seconds or less).
Why is that, you may ask. But it is for PRECISION! The god of productive machinery! Every time you drive the stepper wires with a correct combination the rotor moves by a certain amount of degreesā€¦ That way you can tell where the rotor is by just measuring how many such voltage combinations you have applied to the motor. Knowing the position of something without any kind of feedback is Really Something!!!
(You can read much more here. There is a decent explanation of microstepping inside. the thing that this project CANā€™T do at the time of writing)

Step 2: Stating the Problemā€¦

So, as you may have realized, steppers are a hassle to use and control. All those wires, voltages, combinations and degrees/step are simply too much for a human to control.
And when it comes to CNCing, computers find it hard too. It is difficult even for computers, to control all the above combined with the needs of a CNC device: steady velocity, measured acceleration, simultaneous motion and taking a note of every rotor at any given time.
But when we face problems with multitasking we have the most elegant solution (when it comes to engineering):
Split the tasks to more than one worker. And that happened. The computer got rid of anything that has to do with voltages and combinations of wires. A simple interface was given to the computer so it could communicate with the motor. An interface that only contains 2 signals. A Step signal that every time it goes High (edge triggering) the motor has to move 1 ā€œstepā€ and a Direction signal that decides at which direction would be the step (ex: High for CW, Low for CCW).
So this is the Step/Dir interface.
Now a second device was needed to translate the Step/Dir signals to actual 4-wire signals, move the motor and generally do the hard work. This device is the Stepper Controller. And as of today, only one type of this device exists commercially: the hardware one. It uses H-bridges along with some kind of hardware logic, and other tricks ending up to quite complicated device. So it isnā€™t that cheap tooā€¦ They can reach even 60 euros or more for multiple motors.
So, the first reaction when I got an idea about how to program Attinies was ā€œWhy hasnā€™t anyone made a software controller, by just coding the combinations in an Attiny85ā€ (There have been some success with Attiny2313 by another Instructable and a sole attempt with Attiny85 that isnā€™t very satisfying)
Attiny85 is a microcontroller. It contains a processor, some RAM, some free space, to save and load things, and offers some of its processorā€™s register bits as IO pins.
Here lies the problem. Attiny85 has 8 pins at its DIP package, 2 of them being power supply. And you may assume that the rest are pure IO. Thatā€™s wrong. Well, almost, wrongā€¦ The 5 of the remaining pins are IO and there is that 1 pin that is used for RESET (if you bring it Low the microcontroller will restart). To make things worse, RESET pin is connected to some register, so it has the potential to BE an IO pin. There is also a fuse inside the microcontroller that decides if this pin is used for RESET or IO. BUT if you change the fuse (the famous RSTDSBL) to use the pin as IO, the microcontroller canā€™t be reset again and, on top of it, it canā€™t be reprogrammed.
Now, back to the stepper controller device. It needs 2 pins, to read the incoming Step and Dir signals, and 4 to connect the stepper motor wires (or the base of some transistors to amplify the power delivered to the motor) and do the actual voltage combinations. So a controller needs (*at least*) 6 pins.
You see it, donā€™t you? The way god created things has made our little Attiny85 to be incapable of being used as a stepper controller properly. Until Nowā€¦

Step 4: The CircuitSchematic Attiny85 As a Step-Dir Stepper Motor Controller

For more detail: Attiny85 As a Step/Dir Stepper Motor Controller


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top