Week 7: Embedded Programming
Designing the board
Since I am trying to build a record player for final project, I wanted to see if I could design and program a board to control a motor. I looked around in the lab and found the A4953 motor driver and a motor. After reading the datasheet for the motor driver, I used Eagle to design the board. I decided to use as 12V power supply since the motor is rated at 12VDC and included a voltage regulator to get the voltage down to 5V to power the attiny.
Milling the board
I milled the first version of the board:
and ran into a lot of trouble getting a motor to run. I read skimmed through the data sheet again and went back to my design. Although the datasheet referred to the LSS pin on the motor driver as optional, I decided to ground it just in case that was causing my problem. I also realized that I had connected the motor driver to non-PWM pins on the attiny even though the motor driver I was using was capable of PWM. I rerouted those traces in Eagle to connect to PWM pins and milled a new board:
Programming the board
Because I have Arduino experience, I felt comfortable starting by using the Arduino IDE to program my motor board. I used analogWrite(255) to send a square wave to one pin to make the motor move in one direction. I also used digitalWrite(HIGH) to send a constant high signal which accomplished the same behavior.
After I got my Arduino program working, I wanted to see if I could do PWM control through C. I took Neil's hello.H-bridge.44.c C program and modified to communicate with the pins that I was using.
Even after I changed the pins to match my board, I was still having issues programming so I used an oscilloscope to see if I was actually sending a PWM signal to the motor in pins in the motor driver.
I confirmed that I was actually getting a PWM signal and deduced signal was not on long enough to get over the static fraction of my motor. Neil's code defines a macro for on_delay() which defines the PWM on time. I increased this value from 3 to 5 to increase the amount of time that the signal is high which was just enough to get the motor to start spinning.
Since I want very fine control over my motor for my final project (33 1/3 RPM or 45 RPM), I am planning to experiment more with programming the board to see if my current board is good enough to accomplish a steady speed.