Вы находитесь на странице: 1из 4

ECE 206 Lab 8: H Bridge and Motor 

Direction Control
Andrew Cichon (acichon2)
Chang Hun Park (chp2)
Lab Date: 03/27/2019
Report Date: 04/03/2019

Statement of Purpose:
The goal of this lab is to construct a circuit that controls the motor’s rotational direction with the
H-bridge circuit. Using, four transistors, the rotational direction varies depending on the voltage
differences. We will also going to use the knob encoder and Arduino to change the direction of
the motor.

Materials

● Breadboard
● Wiring Kit
● 2 - 1k​Ω​ resistor
● Voltage source (5V)
● DC motor
● Arduino
● Knob encoder
● 2 - P-Channel MOSFET (J652)
● 2 - N-Channel MOSFET (K3703)

Procedure / Results

We begin by constructing the circuit shown in ​figure 1​. It shows an h-bridge circuit
comprised of N and P-channel MOSFETs, with a motor being the bridge. The goal is to
implement code using the Arduino that allows us to change the direction of the motor by rotating
the encoder in that direction. Also seen in ​figure 1 ​is an “A” and “B” connection. This is where
the Arduino will apply the analogWrite function in order to change the power given to the motor
and will subsequently change the motor’s direction. P1 and P2 refer to P-Channel MOSFETs
(J652) while N1 and N2 refer to N-channel MOSFETs (K3703).
Figure 1: Provided circuit diagram used to construct lab 8’s h-bridge circuit.

Since an encoder circuit is also required, an annotated photograph of our actual setup is
provided in ​figure 2​.

Figure 2: Numbered photograph of circuit setup (annotations described below).


1. 5V Input Rail
2. Ground Rail
3. Quadrature Encoder Circuit
4. “Left” Portion of H-Bridge Circuit (P1 & N1)
5. “Right” Portion of H-Bridge Circuit (P2 & N2)
6. “Left” Drain to Motor
7. “Right” Drain to Motor
8. Input Pins Receiving Quadrature Information
9. Output Pins “A” and “B”

The motor is visible on the right edge of the photo.

The following code was used to produce a change in direction following a change in the
direction of knob rotation:

int last_a = 0; // to keep track of last state of the encoder digitalWrite(3, LOW);

int parker = 0; //dummy variable (although Parker is not a }


dummy) to keep track of current speed
if(b == LOW){ // Clockwise
void setup() {
parker = parker + 1;
// initialize digital pins 12/13 to be inputs
digitalWrite(5, LOW);
pinMode(12, INPUT);
analogWrite(3, abs(parker));
pinMode(13, INPUT);
}
pinMode(3, OUTPUT); //A (in diagram)
}
pinMode(5, OUTPUT); //B (in diagram)
if(parker > 255){ //set limits since analogWrite only takes
Serial.begin(9600); values between 0-255

} parker = 255;

void loop() { }

int a = digitalRead(12);//read pin 12 if(parker < -255){ //set limits since analogWrite only takes
values between 0-255
int b = digitalRead(13);//read pin 13
parker = -255;
if ((last_a == LOW) && (a == HIGH))
}
{
last_a = a; //update state
////if A has gone from low to high
Serial.println(parker);
if(b == HIGH){ //Counterclockwise
}
parker = parker - 1;

analogWrite(5, abs(parker));

This code shows our ​ATTEMPT​ at the bonus challenge. Our goal was to reduce the value of
our variable (parker) by one if rotated in the opposite direction of motor rotation. For example, if
the motor was being driven at 100% duty cycle (parker = 255) then a counterclockwise rotation
should result in the power being decreased very slightly (parker = 254). Unfortunately, we were
unable to implement this correctly. We had many issues involving the code. One moment it
would be working fine, and the next the motor would arbitrarily change direction without any
input to the quadrature knob. We would have liked to attribute this to faulty equipment however
with the time allotted for each lab it was difficult to debug it to that level. However, we find out
quite easy to complete the challenge which was stated as “[b]uild a circuit which can control the
motor direction. The motor should be able to spin and change directions depending on which
way the encoder knob is turned”. We found that with the code we implemented for this
challenge increased the value of parker by 1 no matter what direction the knob was rotated.
However, the code was able to change direction depending on the rotation of the knob as
required. Being relatively unfamiliar with C/C++ made the debugging for the bonus challenge
quite difficult.

Conclusion:

With the written programming code, we were able to succeed in changing both the motor’s
rotational direction and speed. There were some slight issues in setting up the circuit such as
the knob did not fit tightly to the breadboard. However, we were able to understand how the
code works and how the motor’s behavior change.

Вам также может понравиться