This week I learned about output devices. I chose stepper motor as an output device since I will use it for my final project. First I tested with breadboard to see how stepper motor work, and made PCB for output device.
Assignment
group project: measure the power consumption of an output device
individual project: Add an output device to a microcontroller board you've designed and program it to do something
Learning outcomes:
Demonstrate workflows used in circuit board design and fabrication
Implement and interpret programming protocols
Have you:
Described your design and fabrication process using words/images/screenshots.
Explained the programming process/es you used and how the microcontroller datasheet helped you.
I am planning to use stepper motor for my final project so I decided to work with it for weekly assignment. I started to learn about stepper motor with tutorials and Fab Academy previous years’ documentation. Here are some useful tutorials:
A stepper motor is a motor that moves in discrete steps. Inside of a stepper motor there is a central gear-shaped piece of iron sounded by multiple coils organised in groups (phases). The steps are controlled by the current sent to the electromagnets. By energizing each phase in sequence, the motor will rotate, one step at a time. There are different types of stepper motor, but stepper motor I used was each full step 1.8 degrees bipolar stepper motor (current limit 1.0A). Bipolar stepper motor has two sets of coils inside as electromagnets to control steps of motor. When pulse is sent to a set of coils, motor moves one step and hold there until next pulse is sent to another set of coils. To send pulse one by one to each set of coils, H-bridge is used. H-bridge consists of four switches connected as a circuit and logically controls them as two sets of switches. As an easier alternative way, it is possible to use stepper driver (A4988) to control stepper motor. The stepper driver need to be placed between motor and microcontroller. We had A4988 in Fab Lab Oulu so I decided to use it.
Since it was the first time to work with a motor, I decided to make a simple circuit following the example in Pololu instructions. I drew a sketch of my output device and how do I want to control it. I wanted to connect stepper motor and stepper driver to the echo hello-world board (ATTiny44A) I made in week 7. I also wanted to use potentiometer to control speed of stepper motor. Four wires from the stepper motor are connected to A4988 stepper motor drive carrier. Power (8-12V) for stepper motor is supplied by power supply. Step pin and direction pin from A4988 are connected to I/O pins on ATTiny44A. Potentiometer is attached to one of I/O pins on ATTiny44A.
Testing stepper motor
I started testing using breadboard. I connected stepper motor, stepper driver and echo hello-world board with jumper wires. Stepper motor requires 8-35V separate power from microcontroller. I added decoupling capacitor (200μF, it should be more than 47μF) between VMOT and GND for protecting driver from voltage spikes.
First I needed to adjust current limiting of stepper driver to make sure the current is under the current limit of the motor. We can adjust current limit using potentiometer on stepper driver. I set up power supply. I set voltage and current limit as follow: one is 5V, 20mA for microcontroller and another is 8V, 0.7A for stepper motor. The voltage limit of the capacitor I used was 10V so I set 8V following Antti 's advice. Also the current limit of the motor I used was 1.0A so I set 0.7A as current limit.
I used a simple code I found here to adjust current limit. I uploaded the code to echo hello-world board and turn on power supply (first for microcontroller (smaller voltage) and then motor (bigger voltage)). Motor didn’t move but only vibrate. As I turned the potentiometer slowly right using screwdriver, the current increased. The motor started to move when the current was around 0.3A.
Making PCB for stepper motor
I designed the board for stepper motor referring to A4988 datasheet, Neil’s board and Jari Pakarinen's documentation. I wanted to use one power source to supply power for motor and processor so I used regulator ZLDO1117 to regulate 8V for stepper motor to 5V for processor. I referred to the datasheet to draw the circuit. I followed the same sequence that I described in week 9. I added Eagle library which has stepper driver.
* Later I found mistakes in this schematic as I describe below.
On this board, I had through hole components, so I exported three different images. First I made Top and layer 17 Pads visible and exported (trace). Second I changed to white background and made only layer 46 milling visible and exported (outline). Next I made only layer 17 visible and exported (holes). For the third image of holes I needed to modify in GIMP. I opened the image in GIMP, and bucket filled outer part of the holes with black. With this way only the holes are in the image.
Then I went to Fabmodule. I made the tool diameter for trace smaller (0.37mm) since there were some tool paths which were not made with the default setting (0.4mm). Next I imported image for holes in Fabmodule. I had the image with black background and white holes. I inverted the image in Fabmodule so that only the holes (parts coloured with black) are drilled. I select outline and tool diameter 0.79mm to create tool path. I also made tool path for outline in the same way that I described in week5.
Tool path of trace
Tool path of holes
Tool path of outline
I manufactured the board with milling machine. I milled the trace first with 0.2-0.5mm V shape milling bit, then I changed the milling bit to 1mm flat and drilled the holes and finally I cut the outline with the same bit. When I created the tool path in Fab Module, instead of 0.79mm I should have used the tool diameter 1mm which was the actual size of the tool. Since I calculated tool path with 0.79mm tool diameter and used 1mm diameter tool to make holes, the copper layer was removed more than it should have been. As a result very thin copper rings remained around the holes.
After finished milling, I noticed the holes were not drilled completely. I used 0.8mm milling bit and manually made holes.
I started soldering.
I soldered the connector for stepper driver first. I placed two connectors first to the PCB and set stepper driver on it. With this way two connectors were aligned. I managed to solder the connectors from the narrow space between the connectors and PCB surface using thin soldering iron.
After I soldered connectors, I checked conductivity of pins and GND with multimeter. Since I was soldering very narrow spaces where pins were close to each other, I wanted to check pins and GND were not connected with soldering tin.
I found two pins were connected since the copper was not completely removed. I should have checked more carefully before I started soldering. I used a needle to remove the copper between pins.
After I soldered all the components, I checked conductivity with multimeter. There was no problem.
I made some mistakes in design. I found GND and VCC pins of ISP in the new board were drawn other way around in schematic in Eagle (stupid me!). I needed to change the order of the cable to connect USBTiny and the board. Also I messed up the order of the motor pins on stepper driver. There are four wires coming from the stepper motor. They are two sets of two wires connected to the coils work as phases. The stepper motor I used had a connector for the four wires to connect with stepper driver. I thought I have designed the order of the pins on my PCB as same order as the wires from stepper motor so that the sets of wires are connected on the sets of pins on the stepper driver. But apparently I made wrong pairs. So I removed the connector on the stepper motor and changed the order of wires and added a new connector so that the order matches the pins on my PCB.
Programming
I used Arduino sketch to program the board. I checked pin numbers of I/O pins on ATTiny44A in datasheet and changed them in Arduino sketch referring to this page. I started to write simple program referring to example of Arduino and A4988 code. In Arduino sketch for stepper driver, we need to define step pin and direction pin. Set the step pin and direction pin as output. The number of pulse is decided for stepper motors. The stepper motor I used was 200 pulses for making one full cycle rotation, which means 1.8 degrees per step (360 degrees/ 200 pulses). In the loop, use for statement, initialization; x=0, condition; x < 200 and increment x++. It means increment continues until condition becomes false. (see more information about for statement). We can control the rotation speed of the motor by changing the delay time. The sum of the delay times after digitalWrite (step, HIGH) and digitalWrite (step, LOW) is the time between one step to the next step.
I uploaded Arduino sketch I used with breadboard. I connected the board to power supply and set the voltage 8V and current limitation 0.7A as I did before. But the stepper motor did not work. However, it didn’t move. I could see it is trying to move but it didn’t move. I increased voltage up to 9.5V but it still did not work. The voltage limit of 220μF capacitor I used was 10V so I couldn’t increase anymore.
Problem and debugging
I tried debugging. I listed up possible reasons caused the problem of my new board.
Since I messed up the pins of ISP header, so it might be an issue. - I programmed simple code to blink LED and checked LED blinks. Also I used py serial to check communication with computer and it worked.
Voltage is not provided correctly. - I checked voltage of pins with multimeter. I checked 8V and 5V are coming.
Arduino sketch is not correct. - I checked Ari’s and Jari’s documentation and made sure my sketch is okay.
Signal is not provided correctly to step pin on stepper deriver. - I checked signal on oscilloscope. I could not see clear digital signal. But I could not find understandable reason nor fix the signal.
Finally I borrowed stepper motor and driver and tried to test with them. There might be problem in stepper driver or stepper motor. Here are the results of trials with stepper motor I had used (stepper motor A), stepper driver I had used (stepper driver A), stepper motor I borrowed (stepper motor B) and stepper driver I borrowed (stepper driver B).
Stepper motor A did not work with stepper driver A.
Stepper motor B worked with stepper driver A.
Stepper motor B worked with stepper driver B.
Stepper motor A worked with stepper driver B.
I realised that stepper driver A provided only around 0.040A, while stepper driver B provided around 0.300A. The current limit of the stepper driver A was too small. It was barely enough to make stepper motor B work, but not stepper motor A. I increased the current limit of the stepper driver A until it provided around 0.300 A which would be enough for both stepper driver A and B. After that both stepper motors worked with stepper driver A. I found when the speed of rotation is slow (delay 500000000 microseconds), it consumes around 0.25A and when the speed of rotation is fast (delay 500000 microseconds) it consumes around 0.15A.
Before adjusting current limit
After adjusting current limit
Fast speed rotation
Later I got feedback from Antti that I should check the delay time since 500000000 microseconds is too long. It does not match the speed of the rotation of the motor. I checked the delay time again and while I was searching information about delay time in Arduino sketch, I got to know that currently the largest value I can put as delay is 16383 (see more information). So the code delayMicroseconds() in the previous Arduino sketch did not produce the accurate delay. I used delay() which delays milliseconds instead of delayMicrosecond(). I tested three paterns of delay: delay(3000) = 3 seconds, delay(300) = 0.3 seconds and delay(30) = 0.03 seconds. With each patern, the motor stepped one step (1.8 degrees) in each 6 seconds, 0.6 seconds and 0.06 seconds.
For final version of my Arduino sketch, I modified example of Arduino and A4988 code. I changed pin numbers, changed delay time from microseconds to milliseconds for slower rotation and added code for LED blinking to check whether the motor is rotating in correct speed according to the daly time.
Reflection
This week I tried to use stepper motor for the first time. I started to learn and get familiar with stepper motor and tried it with breadboard and jumper wires to see how to operate and how stepper driver functions. After that I made the PCB. But with actual PCB, I had a long time debugging to make it work. Fab Lab staff helped me a lot and I am developing debugging skill. I also learned it is important to minimise unsure matters when I fabricate something. If I have something unsure, debugging is difficult. Anyway, I made my stepper motor work. I was planning to change rotation speed of the stepper motor with potentiometer, but in this week I didn’t have time. I will find time to make it work too.