Assignment
-
Individual assignment:
- Add an output device to a microcontroller board you’ve designed,
- Program it to do something
-
Group assignment:
- Measure the power consumption of an output device
Individual assignment
This week with Kris’s suggestion I chose DC motor driver and Full-Bridge to control the motor. In my final, project I need the pump to provide air into the model, it’s a good point to start it.
Schematic
In this week, the PCB included some new components: Full-Bridge PWM Motor Drivers, Voltage Regulator, and DC Power Jack.
- A4952 Full-Bridge DMOS PWM Motor Drivers (Datasheet)
A4952 is designed to operate DC motors. The current from the output full bridge is regulated with pulse width modulated(PWM). Through the function in Full-Bridge, the logic current could transform into PWM which is able to simulate the analog signal by switching digital signal on and off at a fast rate.
↑The red square in the picture is mainly used in my later code.
↓The Decoupling Capacitors I have explained in Week 12: Input Devices. To stabilize the voltage, we need the decoupling capacitors, but I used 0.1uF and 10uF instead, to minimize the space a 100uF capacitor occupies on PCB.
- Tips for soldering Full Bridge
First, melt thin layers of soldering iron both on the pad of A4952 and the PCB. Second, stabilizing it with a clipper on the board. Third, heating the position of A4952 with a hot air gun.
- Voltage Regulator (Datasheet)
The explanation for Voltage Regulator from Week 12: Input Devices by Kris could be found on 13:56. As I need 5V for operating my PCB and 12V for driving the motor, a regulator can help me to achieve that. In my case, I skipped the capacitors on both sides to simplify the schematic design.
- DC Power Jack (Datasheet)
PCB Layout
Additional holes for Power Jack and Connector..
The Wire to Board Terminal needs Rivets to connect and the power jack needs mounting holes for steady. I drew them additionally with the help of Inkscape. Not by margin layer, because the position would change in different import and export on Inkscape.
Create toolpath and mill
Rivets and Soldering
Cables for the Motor
The soldering iron-coated cables enable them to connect to the wire to board terminal easier.
Coding
What I am doing in the code is created two functions Forward and Reverse to rotate the motor gradually up to full speed and decrease to 0 speed by changing the analogWrite of IN1 and IN2 pins. The Forward and Reverse could refer to PWM Control Truth Table from the Full-Bridge datasheet.
#define motorIN1 0 // IN1
#define motorIN2 1 // IN2
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(motorIN1, OUTPUT); //In hole
pinMode(motorIN2, OUTPUT); //Out hole
}
// the loop function runs over and over again forever
void loop() {
Forward();
Reverse();
}
void Forward(){
digitalWrite(motorIN2, 0);
// digitalWrite(motorIN1, 1); testing
// delay(5000);
for (int i=0; i<256 ; i++)
{
analogWrite(motorIN1,i);
delay(30);
}
for (int i=255; i>=0 ; i--)
{
analogWrite(motorIN1,i);
delay(30);
}
digitalWrite(motorIN1, 1); //break
digitalWrite(motorIN2, 1); //break
delay(100);
digitalWrite(motorIN1, 0); //standby
digitalWrite(motorIN2, 0); //standby
delay(100);
}
void Reverse(){
digitalWrite(motorIN1, 0);
for (int i=0; i<256 ; i++)
{
analogWrite(motorIN2,i);
delay(30);
}
for (int i=255; i>=0 ; i--)
{
analogWrite(motorIN2,i);
delay(30);
}
digitalWrite(motorIN1, 1); //break
digitalWrite(motorIN2, 1); //break
delay(100);
digitalWrite(motorIN1, 0); //standby
digitalWrite(motorIN2, 0); //standby
delay(100);
}
The functioning motors demonstration
Challenges
-
The holes were too huge for the vias to hold.
!! Solution: Draw the holes on Inkscape from the F.Cu layer. It could not only fix the position of the holes but also faster to modify.
-
The first USB UPDI was broken; therefore, I couldn’t program my DC Motor Driver.
!! Solution: Build a new one, it might need to be cast with a layer of epoxy.
-
The Forward function couldn’t speed up and down gradually.
?? Reason: The IN1 was connected to Pin2 (PA6 / Arduino 0), however, Pin2 couldn’t receive ~PWM signal. Thus the forward function could only perform a turn on/off at full speed.
Group Assignment
To calculate the power consumption of a pump I used a power supplier to know the current first and calculate it with an online calculator. For both DP0125 and DP0140 pumps, it suggests using 12 volts as a power supply.
Download
The Week 14 zip file includes:
-
DCMotor-Driver
-
Schematic