Lab 5 - Inside Mines

advertisement

EENG 383 Microcomputer Architecture and Interfacing Fall 2016

Lab 5 – DC Motor and H-bridge

September 29, 2016

In this lab you will use the HCS12 microcontroller on the SSMI board to drive a DC motor using an Hbridge circuit.

1 Prelab Questions (complete prior to coming to lab)

Read this handout before coming to lab and answer the following questions:

1.

We will use the TLE5602 H-bridge driver on the SSMI board to drive the DC motor. According to the datasheet for this device (posted on the class web page), what is the maximum current that it can deliver? What is the maximum supply voltage?

2.

The maximum current flow through the motor occurs when it is just starting up, or when it is stalled. Look up the stall current on the webpage containing the description of the motor: https://www.sparkfun.com/products/8910 .

3.

There are two H-bridges on the SSMI board, marked U3 and U4. What two pins coming from the microcontroller control the H-bridge designated U4? What are the pin numbers of the screw terminal J7 that are connected to the output of H-bridge? Note, pin 1 of the screw terminal J7 is designated with a square solder pad in the mechanical drawing posted at the SSMI Board link on the class web page. Identify the location (left or right) of the pins of the screw terminal J7 that are connected to H-bridge U4.

2 Speed Control

Use the 9V power supply from your kit to power the SSMI board. Before applying power to the SSMI board, hook up the following connections and show the instructor:

Connect the 25K

potentiometer to pin AN02 such that it can supply a variable voltage between

0..5V to that pin.

Unscrew pins 1 and 2 of connector J7 just enough so that the pins of the DC motor stay in place when inserted, but can easily be removed.

Connect channel 1 of the oscilloscope to PTT0 and channel 2 to PTT1. Adjust the vertical scale to 2v/division. Put channel 1 on the second lowest reticle and channel 2 to the second lowest reticle on the upper half of the display. Adjust the horizontal scale to 1mS/div.

Write a C language program to do the following

Initialize the A/D converter, put in INIT_HCS12 subroutine.

Initialize the PWM channel 0, put in INIT_HCS12 subroutine. o Period of 1.36mS o Polarity = 1 o MODRR0 = 1

Configure PTT0 and 1 as outputs. Assert a logic 0 on PPT1.

Do the following forever: o Read the digitize input voltage on pin AN02. o Write this digitized value to the duty cycle of PWM channel 0 on PTT0

1

EENG 383 Microcomputer Architecture and Interfacing Fall 2016

Insert the pins of DC motor into J7 only when you have the program running, turn the pot and observe the speed of the motor change and the duty cycle of the PWM waveform change on the oscilloscope.

Sign-Off 1: Demonstrate your program to the instructor.

3 Speed and Direction Control

Change the program to sense the potentiometer and use this to control the speed and direction of the motor. If the potentiometer is exactly in the middle, the motor speed should be zero. If the potentiometer is turned to the right, drive the motor in the forward direction; with motor speed increasing as the potentiometer is turned more in that direction. If the potentiometer is turned to the left, drive the motor in the reverse direction; with motor speed increasing as the potentiometer is turned more in that direction.

To accomplish this, you should drive one motor pin with the PWM signal (MODRR_MODRRx = 1) and the other pin should be a GPIO (MODRR_MODRRx = 0) driven to logic 0.

Use the same oscilloscope setup and capture two waveforms, one in the forward direction and one in the reverse.

Sign-Off 2: Demonstrate your program to the instructor.

4 Optical Encoder

The DC motor / wheel assembly has an optical encoder sensor. The sensor outputs pulses as the wheel turns. The pulse rate can be used to determine the actual rotational velocity of the wheel. For a description of the encoder and the number of pulses per rotation see the webpage https://www.sparkfun.com/products/9209 or http://www.pololu.com/catalog/product/1217 .

Connect +5V power and ground to the optical encoder circuit (red wire is 5v and black wire is ground), and observe the two encoder output signals from the optical encoder on the oscilloscope (yellow and white wires). Try changing the direction of rotation and observe what happens to the output waveforms.

From the observed output pulse rate, calculate the direction and the motor shaft speed in RPMs. Include the scope trace in your report.

Include in your report:

1.

Title page.

2.

The C language program for the speed and direction control program in section 3.

3.

A block diagram of the circuit.

4.

An explanation of the circuit and program. Include the oscilloscope captures of the waveforms from section 3.

5.

Include a waveform of the pulse encoders and with numbers on this trace, derive the rotational velocity of the wheel and describe how you can determine the direction.

2

EENG 383 Microcomputer Architecture and Interfacing Fall 2016

Lab 5: DC Motor and H-Bridge

Name: ________________________________Name: ________________________________

Task

Sign-Off 1 Speed Control

Description Initials

Sign-Off 2 Speed and Direction Control

5 Rubric

Deliverables

C code with flowchart/pseudocode

Schematic

Circuit and program Explanation

Scope traces

20 pts Pre-Lab

/ 7 Questions

/ 5 Demonstrations

/ 3 Sign-Off 1: A/D and Motor Control

/ 5 Sign-Off 2: Motor direction control

5 pts

/ 5

20 pts

/ 10

/10

Composition 5 pts

Total

/ 50 pts

Bonus +5: Poll the ADC about 50 times a second in a timer overflow ISR and have the ISR perform speed and direction control.

3

Download