Sander van Vliet

Fabacademy2016
@Fablab Amsterdam


Output Devices

Week 13 (27 april - 4 may)


Lecture

This weeks lecture introduced us to various output devices like LED's, LCD's, video, speakers, solenoids, brush DC motors, brushless DC motors (BLDC), servo motors and stepper motors. We also went through the function of mosfets and H-Bridges and the ways to control the different types of motors and other output devices. See this weeks' class lecture file to get an overview of the lecture.

Assignment


A motor / actuator to open a window

For this weeks assignment I would like to test motors which can be useful for my final project. A stepper motor can be controlled in steps of rotation, but needs more control logic and although I find it interesting to try this type of motors out, I don't need that type of control to open and close my window. I probably could use a servo for it and might try that too, but I will start with a brushed DC motor to test things out.
Click on the images for more information on the working priciple of the motor types below.
stepper motor
servo motor
dc brush motor

I will recreate the hello.H-bridge example board so I can test some brushed DC motors we have in the Fablab and I also have a 12V linear actuator (brushed DC motor inside) from a friend I want to test. This board contains an H-Bridge which is a component with which you can control the direction of the current in the motor. By doing this, you can control the direction in which the motor is rotating. The board also uses an input power terminal to supply the motor with the voltage it needs, while the voltage regulator on the board generates a lower constant voltage for the microcontroller. In this case 5V, because that is the operating voltage for the ATtiny44 microcontroller.

The parts list/bom of the hello.H-bridge board consists of:
  • 1x ATtiny44 microcontroller
  • 1x A4953 H-Bridge motor driver
    (correction after checking Fablab inventory: I used a A4950 instead)
  • 2x 1uF capacitor
  • 1x 10uF capacitor
  • 1x 10k Ω resistor
  • 2x 4 pin (2x2) header (input and output power terminals)
  • 1x 6 pin (2x3) ISP header
  • 1x LM3480 5V 100mA voltage regulator
  • and I added two buttons:
  • 2x Tactile switch (push button)

  • So I based my board (I named it Hello Motor) on Neil's hello.H-bridge board and I added two push buttons to it. Decided to not add pull up resistors for them because I would use the internal pull ups of the ATtiny44 and activate them in the program code.
    For the motor driver component I had used the A4953 in my design, but once I came to the Fablab to make the board I discovered that we only have the A4950 in our Fablab inventory so I had to compare data sheets to ensure that the pin layout was the same. The pinout is indeed the same so luckily I didn't have to change my design and can use the A4950.
    I also checked if the H-Bridge could handle a 12V power source and the datasheet mentions this:"Designed for pulse width modulated (PWM) control of DC motors, the A4950 is capable of peak output currents to ±3.5 A and operating voltages to 40 V." so that would be fine.
    The LM3480 5V voltage regulator has an input Voltage Range up to 30V so that will also be enough.

    Making the board

    Below are a few images of the design and production processes using Eagle and the Roland Modela. When I wanted to start milling, I had an issue because the Modela started milling in an incorrect position so I halted it. I had added the letters to the design using Inkscape right before I started milling and apparently Inkscape had changed the scale/dimensions of the file. Now I had to remove this job which was still partly in the memory of the Modela and partly active on the PC first, before I could start a new job using a corrected .png file. I used this tutorial to do so.
    hello motor source files - eagle

    After I finished soldering the components on the board I checked all connections with a multimeter and it checked out OK.

    Programming and testing it

    I burned the bootloader on it using Arduino IDE and programmed it with Neil's example C code. The first time I did this I received errors, see the command line response here. The second time I succeeded, but I'm not sure why this happened. I noticed that the board and especially the voltage regulator heated up a lot. As always I was glad that my board was functioning so far and was programmable!
    I connected a 12V transformer to the power input headers (left bottom on the board layout image) and connected a little dc brush motor to the power out header (right top) and the motor operated! It ran its sequence of rotations as written in the hello.H-bridge.44.DC.c file.



    I used this transformer as a power source:


    Programming to use the buttons

    I searched for Arduino code which was used with similar boards and used parts of that to assemble this code.

    The motor responded to the buttons like I expected, but when not pressing any buttons, the motor was running frantically in either direction and changing direction at will. It seemed like a floating state and I realized that I did not define the situation where neither of the buttons are pressed.



    I changed the two if statements into a a branch of if - else if - else statements where next to either one of the pins is being pressed I define a third situation. If neither of the buttons are pressed, both motor1Pin and motor2Pin will get the LOW state resulting in the motor not running. You can see in the H-Bridge motor driver datasheet how this exactly works.


    Now when I powered the board the motor was not running 'by itself' and only when I pressed a button it started running. In one direction with one button and in the other direction with the other button.



    hello motor buttons sketch source file - arduino ide


    Not able to control the RPM of the motor (no PWM)

    I thought of the idea to control the speed of the motor (RPM) in the code and for that I would need to use a PWM signal, but I did not think of this when designing the board. In the design I connected the IN1 and IN2 pins of the H-Bridge motor driver component to the PA2 and PA3 pins of the ATtiny44, but these do not support the PWM function so they can only supply 0V or 5V so can only let the motor stand still or run at max RPM. I should have connected the IN1 and IN2 to the PB2 and PA7 because they do support PWM and I could have because they are not used on my board.
    See below the ATtiny44 and ATtiny45 pinout including the pin numbers Arduino IDE uses for these pins:
    So I decided to cut the traces which connect the IN1 and IN2 pins of the H-Bridge motor driver component to the PA2 and PA3 pins of the ATtiny44. Then I soldered two jumper wires connecting the IN1 and IN2 pins of the H-Bridge motor driver component to the PB2 and PA7 pins of the ATtiny44, see below. Now I can try to control the RPM of the motor using PWM.

    I changed the code accordingly by replacing the two pins 2 and 3 by pins 7 and 8.
    I also replaced the digitalWrite by analogWrite including values between 0 and 255 for the PWM signal.

    And here you can see I can now operate the motor in two directions and control the amount of RPM in the code.


    hello motor buttons pwm sketch source file - arduino ide