embedded programming :
 h  o  m  e   >   >   >















making a
dc motor move :
dc motor circuit board :

This week we were asked to :
1. read a data sheet
2. make our board do something.

I think I technically did both of the above in WEEK 05, but I was happy to do it again, though maybe jumping a bit ahead - mostly because I'm anxious to prototype my conveyor belt, anxious to see if my idea will even work.

As mentioned in my final project ongoing log, I bought some material to prototype - in particular I want to know whether my design can with little friction move aluminum plates via steel marbles and a rollerblade type wheel.

I bought some stepper motors for my final project (which sounds like they should have been DC motors, but whatever) and have no idea how to connect them to a circuit board, so I decided to see if Neil had any boards for stepper motors, and of course he did!

neil's stepper motor board

neil's stepper motor board w components

Neil's board included two motor drivers (labelled A4953), and a stepper motor (labelled J3),so I figured I would read data sheets on both and ultimately remake neil's board to make these motors move - and move my wheel, that will move my steel plates!

During the programming recitation, we were told adding LEDs to debug is a good idea, so I will try to figure out how to do that too - I mean I know how to add an LED but I'm not sure I know how to add it in order to debug...

Maybe I should also add a button to turn on and off the motor?...

neil's echo hello-world board :

Looking back at Neil's echo hello-world board, we can recognize some similarities. I kind of know whats going on there, so I dont' feel as overwhelmed as I did two weeks ago.

But let's start looking at these components more closely :

stepper motor :

The Stepper Motor Nema 17 has four wires : red, yellow, gray, and green.

These wires are paired. The stepper motor is used for precise turning, it "steps" and counts its steps - which is why my choosing it for my conveyor belt might not have been appropriate... Apparently, they also create a lot of heat, which doesn't sound great, but I have the motors (4 of them, ha!), so let's just try this out.

stepper motor wires :

In order to precisely turn, the stepper motor uses 2 groups of coils.

So red and yellow are one pair and grey and green another - this will be important when we attach the motor to the board - if you pair the wires incorrectly, the motor will not work.

how motor wires should connect to the board :

motor specs :

Have to admit, I don't know what all of this means, but it sounds like the motor needs 12v to operate?

- - - - -

a4953 (motor driver) pin out :

the other unknown in neil's board is the A4953, or the motor driver. Neil's board has two motor drivers - I assume this might be because the motor has two coils?.... TBD

the motor driver functions to help drive the motor via your microcontroller. a motor driver uses a larger chip which can handle larger amounts of current and higher voltages than the standard 5v/3.3v from a microcontroller pin. They allow you to controll a much larger load from a small signal.

a4953 (motor driver) pin out :

We have some new terms here :

IN1 : logic input 1 : this data sheet doesn't provide as much information as the one I read for the attiny - but if we refer back to neil's board both IN1 and IN2 of both motor driver's are connected to attiny pins pA0 and pA1, and pA3 and pA4.

IN2 : logic input 2 : see above

OUT1 : DMOS full bridge output 1 : dmos stands for double-diffused metal-oxide-semiconductor. i am pretty sure a MOS is part of the MOSFET structure (paloma mentioned I would need to look at mosfets in order to make a board for my motors). Again, the data sheet isn't super informative, but if we again look at neil's board, we can see that the outputs are connected to the header that connects the stepper motor to the board. red and yellow connect to one driver and gray and green connect to another.

OUT2 : DMOS full bridge output 2 : see above

LSS : power return - sense resistor connection : hmmmm... in this case, looks like LSS connects to both the central pad and GND...

VREF : analog input : again, not sure, but seems to connect to power : ">"

VBB : load supply voltage : hmmmm... this also connects to power, but now I'm confused, how does VBB differ from VCC? ok - VCC is the collector supply and VBB is the base supply. maybe this has to do w the fact the stepper motor is bipolar (the paired wires...) vs unipolar? I mean - this is also the first time we are seing power in / out - the echo-hello board only had VCC...

- - - - -

feeling a bit confused again, but let's clarify where everything is going / connected to...

gnd vs vcc+vref vs vbb :

so - it looks like the attiny does not connect directly to the power IN supply - it only does so via the motor driver - because the driver can handle higher voltages?... - - - - -

At this point, I felt like I should install arduino on my computer and try to make my board blink from my own computer - i had only been working with the computer in rpl so far and I bought and FTDI cable, so now I could do this kind of stuff from home.

I installed all the necessary things onto my computer and was ready to go, but when I tried to upload the code, I got a number of errors :



Anthony told me I needed to plug in both the USBtiny AND the FTDI cable in order to upload a sketch. I quickly tried this and it worked. Idk how I forgot to do such a simple thing, but I am relieved the board is working.

This was the code I used, changed slightly from Jaclyn Berry - added an internal pull up resistor as suggested by Rafa, on his page from last year.



When I got back home, I wanted to show my partner, but due to my excitement I was a bit heavy handed, and I ended up breaking the board...!!!! The ISP header ripped the traces out with it. AH, I was very much ready to play with different ways to make this light blink - Now I am feeling like I should have really started here vs trying to look a bit ahead.

broken board : noooooooooo

ISP w ripped traces : tragic

sigh...

Anyways, I also spoke w Anthony a bit about my final project. He strongly suggested I drop the stepper motor, it would, anyways, not be strong enough for what I needed. So now the work I've done thus far this week feels really gone to waste... I guess it is fine. We discussed brushless DC motors, so now I am going to look at one of Neil's DC motor boards...

NOW - moving on the the dc motor board.. I suppose my goal will be to make a new board before class - lets see if this happens.

Neil's DC Motor board :

Hm - this actually looks somewhat similar to the stepper motor board. Instead of two motor drivers, there is only one, though. So actually, all of the previous covered material still applies here.

Anthony mentioned I would need a stronger DC motor that the ones included in the fab lab inventory, so I do wonder how that would change the board...

gnd vs vcc+vref vs vbb :

my re-drawn dc motor board :

Drawing a circuit board on eagle was MUCH easier this time around - especially because I named everything :

clean and named schematic :

clean and named board :

traces not being cut as intended :

When I went to mill the board, I made sure to take a look at the tool path - as expected, some traces were not being cut as intended. This happened with my hello-echo board. Instead of adjusting in Eagle, I moved some stuff around in Photoshop, but I had to tweak a couple of times :

wrong :

still wrong :

right, finally :

updated png :

if you refer to my previous png, you'll see there is a bit more space in between RST and VCC paths and on the motor pin to motor driver.

milled pcb for dc motor :

yay, no need to cut traces out by hand.

components soldered on - shoulda added a button... :

Overall, the entire process went a lot smoother / less stressful than a couple of weeks ago. I do really enjoy the workflow from eagle > soldering, but I wish I understood the basics of electronics a bit more...

testing the dc motor with dc power supply :

when i spoke to anthony about my final project, he said I would probably need a dc motor more powerful than whatever was in the fab lab inventory, but he said I should play around w those anyways. so, i approached the dc power supply hoping to power the dc motor.

i didnt know anything about the dc power supply, but it wasn't too difficult to figure out. I connected the motor to the "slave" cables. I didnt know which was positive / negative on my motor, but I quickly figured that out :

it's alive :

at 5v, the motor moved super fast! I think Anthony is right, this probably wont power my conveyor belt, but I think I might scale down and prototype using this motor...

now to figure out how to program my board to do this... but before that...

i remade my blink board bc why not :

I was super unhappy w the fact that I broke my board last night, so when I milled my motor board, I decided to remake the board I made two weeks ago. After all, that process went smoothly, debugging was the time consuming aspect, and I had by now figured out my silly mistakes (not connected both USBTiny AND FTDI in order to blink my board.

changed red to green LED... :

as soon as I finished soldering, I uploaded the blink sketch, and it worked! finally, i have proof of it too :

blinks on demand :

ok, well, while I should probably just play w this board, I really want to make the other board make the motor move, thus accomplishing the assignment for the week and allowing me to continue playing / prototyping w the motor moving forward...

I looked throughout the past year of students, and it seems none of them programmed a DC motor via Arduino, so I was thinking this wasn't going to happen for me this week. But I kept looking online, and searched for "controlling dc motor circuit board arduino ide hbridge". I mostly didn't understand how to communicate to the motor via the hbridge. It looked like Neil's code was initializing those pins, but I wasn't sure how to do in Arduino..

This page was what I looked at : tutorials point.

pwm pins attiny45 :

it seemed like, if i was going to go w arduino, i needed pwm and only certain pins can do that :

thankfully / luckily, pin 6 (PA7, or Arduino Pin 7) was empty and thus i chose to assign that to PWM.

this was my code - my pins are updated according to arduino / attiny shift:



Like the echo-hello board I needed to power the motor board via the battery. As soon as the USBTiny lit up, I knew I had the battery in the correct orientation. But I also wasn't sure about the orientation of the motor... The motor wasn't working, and I wasn't sure if it was the board, the code, or the wiring. So, I tried a couple of different orientations,and all of a sudden the motor starts moving!!!

!!! :

Again, I'm not sure if I'm setting this up right. I need to look into PWM more in depth. I think something funny is going on though because rather than stop for one second, the motor would pause for a long time before running again. I only really got it to go about three times.

i hope to visit one of the TA's for office hours, and get a better understanding on the code i copied. but here is some more information on the code from arduino's website:

pinMode(pin, mode) : pin (the arduino pin numnber to set the mode of) / mode (input, output, or input_pullup)

decription : configures the specified pin to behave either as an input or an output

- - - -

analogWrite(pin, value) : pin (the arduino pin to write to. Allowed data types : int.) / value (the duty cycle : between 0 (always off) and 255 (always on) Allowed data types : int.)

decription : writes an analog value (PWM wave) to a pin. can be used to light an led at varying brightness or drive a motor at various speeds. after a call to analogWrite(), the pin will generate a steady rectangular wave of the specified duty cycle until the nect call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin.

- - - -

ahh this is helpful

pulse width modulation, or pwm, is a technique for getting analog results with digital means. digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 volts) and off (0 volts) by changing the portion of the time the signal sends on versus the time that the signal spends off. The duration of "on time" is called pulse width. To get varying analog values, you change or modulate, that pulse width. if you repeat this on-off pattern fast enough with and LED for example, the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.

- - - -

digitalWrite(pin, value)pin (the arduino pin number) / value (HIGH or LOW)

description : write a HIGH or LOW value to a digital pin. if the pin has been configured as an output with pinMode(), its voltage will be set to the corresponding value : 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. If you do not set the pinMode() to OUTPUT, and connect an LED to a pin when calling digitalWrite(HIGH), the LED may appear dim. Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor.

- - - -

Regardless, I'm pretty happy with the results. Hopefully I will see someone for office hours sometime this week and start adding things (like a button / switch?) to play w this motor and finally begin to prototype my moving mechanism!

correct delay() :

I put an issue in the issue tracker asking about why my motor would be so off (instead of 3 seconds, it was going for 2 minutes / instead of 1 second, it was going for 1 minute), and Anthony responded that I probably had the internal clock set incorrectly. I was previously programming my blink board with indeed had an external clock of 20 Mhz, and this indeed was the problem.

During office hours, Anthony pointed out other problem with the code. For whatever reason, I thought the PMW had to be assigned to an "empty" pin, but actually, you have to assign it to a pin that is indeed doing something. He said it probably wasn't an issue, though since I was setting the pins to LOW / HIGH...

Although the delay() was now working by adjusting the clock setting, the code was meant to turn the motor one way and then the other, and at the moment it turns one way, skips the other way, and then turns the same way. So there is still some debugging to do.

One other note : After trying the motor a couple of times, the initial code I was using actually stopped working. The motor would work when we put a battery to it, but not via the board. Anthony lent me another dc notor, and I believe this one had a resistor whereas the other did not?.. Anyways, this motor is working whenever I connect it to my board.

Anthony told me this board could power motors up to 40 V, but that the driver would heat up a lot, so I should provide more surface area ground to dispell heat vs v thin traces. I dont need a super super fast motor, but I do think I'll need something more powerful than this current motor.

Here is the code Anthony adjusted w me (removed pwm and both breaks which were written incorrectly):



woohoo :

Turns out, I was assigning the wrong pins, that is why only one direction worked.

Here is the corrected code. I'm not sure if my PWM is doing anything if its not connected to the motor driver.....



Here is code to make the motor e forever - though you could just do this by connecting to a 9V battery.