EMCH 367Fundamentals of MicrocontrollersLab 3 S01.doc

Lab 3 – Timer Functions: Bolt Drop and square wave

Objective

This lab will use MC6811 to perform time measurements. Part I will perform time measurements on a dropping bolt using input capture (IC) timer functions. Part II will generate a square wave using output compare (OC) timer functions.

PREREQUISITES

Floppy disk with the asm codes for the programs:

  • LASTNAME_Firstname_Drop.asm
  • LASTNAME_Firstname_OC_sqwav.asm

Hard copy (printout) of Hmwk5 – Timer functions. When printing, use the 'pages per sheet' option in the lower right corner of the print dialog-box with settings of 4 or 2 (depending on your eyesight) to save paper. (We may want to experiment a little with this before printing the full document.)

PROCEDURE

The students will utilize the asm code developed with the THRSim11 simulator for Hmwk5. The students will go through the printout of Hmwk5 step by step and will verify that the MCU responds to instructions as expected.

The lab is divided into sections. After completing each section, the student will ask the TA to check the student’s work and make a check mark on that section.

The asm code is activated into the MCU following the standard procedure learned in Lab 1.

Part I – Bolt Drop Experiment (50%)

Figure 1Bolt drop experimental setup

Note: This part uses the timer program LASTNAME_Firstname_Drop.asm developed in the section “Input capture – bolt drop experiment” of Hmwk5.

MC6811 will be used in an experiment to measure travel times. A 1.5-in bolt will be held by an electromagnet at the top of a drop shaft. The electromagnet is connected to the MCU. . This magnet is controlled by any of the 8 pins on PORTB. It is turned on by sending 5V through parallel PORTB. When a keystroke occurs, the MCU commands the electromagnet to release the bolt. Simultaneously, the time origin, T0, is recorded. The bolt travels down the shaft. After falling a specified distance (L = 48.75-in), the bolt crosses an infrared emitter-detector sensor and interrupts its beam causing its output voltage to fall from high (+5V) to low (~0V). When the bolt exits the emitter detector sensor, its output voltage comes back up to high (+5V). The output from the emitter-detector sensor is wired into the input capture pins IC1 and IC2 of the MCU. You will program the microcontroller to perform the following functions: (a) control the electromagnet, (b) take the initial time when the process starts, (c) measure the time required for the free-falling bolt to reach the emitter-detector; (d) measure the time required for the bolt to pass through the emitter-detector.

Wiring Diagram

Wire / Connection
Green wire: / +15V
Red wire / +5V
Black wire / Ground
White wire: / To parallel port B pin controlling the magnet
Yellow wire with 2 prongs: / Signal wire to the input capture pins IC1 and IC2

Bolt Drop Circuit Diagram

Pre-test Procedure

Before starting your test, perform the following pre-test procedure to verify that your experimental set-up is performing correctly:

i)Check the correct wiring of the bolt drop set up:

Wire / Connection / Check mark
Green wire: / +15V
Red wire / +5V
Black wire / Ground
White wire: / To parallel port B pin controlling the magnet
Yellow wire with 2 prongs: / Signal wire to the input capture pins IC1 and IC2

TA checkmark ______

ii)Take the white wire out of the Port B connection (if connected). Check the electromagnet holding action upon the bolt by applying 5V to the white wire. The bolt should hold. Then, check the release action by applying 0 V. [Note that 0 V is different from “no-voltage” (floating wire). A floating wire may not release the bolt] The bolt should drop.

iii)Connect O-scope Ch.1 to the signal wire (yellow). Set Trigger Mode to Auto and Horizontal to 0.2 sec/div. You will see a spot traveling across the screen at 5V level. (If the spot is too bright, adjust Brightness Intensity). By hand, introduce the bolt in the emitter-detector zone at the lower end of the tube and watch the signal go to 0V on the O-scope screen. Extract the bolt and watch the signal go back to 5V. Now, let the bolt drop through the tube and watch the fast 5V/0V/5V transition (spot flicker) on the screen.

iv)Connect the white wire to port B. Manually, send a 5V voltage through port B (i.e., store $ff into Port B at memory location $1004) and verify that the electromagnet holds the bolt. Now, send a 0V through port B (store $00 into Port B at memory location $1004) and observe the electromagnet releasing the bolt. Watch the 5V/0V/5V transition on the screen as the dropping bolt passes the emitter-detector sensor.

v)Where are IC1 and IC2 located (port and pin)? Enter your answer here: ______Draw a sketch of the pin assignments in the space below

vi)Connect the signal wire (yellow) to IC1 and IC2 pins.

TA checkmark ______

Test Procedure

  1. Put the bolt into the electromagnet hold position
  2. Activate the program LASTNAME_Firstname_Drop.asm.
  3. Press any key. The bolt should drop and the program should stop when the bolt exits the tube.
  4. Read the memory locations for T0, T1, T2, NOF1, NOF2. Record the readings in the table.
  5. Perform all the 6 trials and enter the appropriate values in the table.

TA checkmark ______

  1. Start manual calculations by completing the formulae below:

Time of entry: t1 = [T1+NOF1*($______)-T0] cycles * (______s/cycle)

Time of exit: t2 = [T2+NOF2*($______)-T0] cycles * (______s/cycle)

Time for bolt to pass: t = t2 – t1

Velocity: v = L/t = _____/t (in/s)

Error:  = (theoretical – measured)/theoretical *100%

TA checkmark ______

Then, calculate t1, t2, t, v in the table.

  1. Use the formulae to calculate the measured time of entry in each trial
  2. Calculate the average measured time of entry, t1, and its deviation.
  3. Use the formulae to calculate the measured time of exit in each trial
  4. Calculate the average measured time of exit, t2, and its deviation.
  5. Use the measured time of entry and time of exit in each trial to calculate the measured time taken by the bolt to pass through.
  6. Calculate the average measured time of passing, t, and its deviation.
  7. Use the appropriate formula to calculate the bolt velocity using the measured time of passing and its deviation.
  8. Use the formulae to calculate the measured time required for the bolt to pass in each trial

Trial
1 / 2 / 3 / 4 / 5 / 6
MEASURE / T0
T1
T2
Number of overflows between T0 &T1, NOF1
Number of overflows between T0 &T2, NOF2
T1+NOF1*($______)-T0
Measured time of entry (ms)
E / Average measured time of entry, t1 (ms),
and deviation (ms and %) / t1 _____ ms, ______ms, ____ %
T / Theoretical time of entry (ms) and error (%) / t1,theory = ______ms, t = ____%
U / T2+NOF2*($______)-T0
P / Measured time of exit (ms)
M / Average measured time of exit, t2 (ms),
and deviation (ms and %) / t2 _____ ms, ______ms, ____ %
O / Measured time for bolt to pass through emitter-detector (ms)
C / Average t (ms) and deviation (ms and %) / t _____ ms, ______ms, ____ %
Average measured velocity v (in/s)
and deviation (in/s and %) / v ____ in/s _____in/s ____ %
Theoretical velocity (in/s) and error (%) / vtheory = ______in/s, v = ____%
  1. Compare the experimental results with the theoretical results calculated in Ex_Timer and discuss any discrepancies. Comment upon the error of your measurements, and discuss possible sources of errors. Enter your answers in the space below.

TA checkmark ______

Part III – Square Wave Generation with Timer Functions (30%)

In this part of the lab, you will generate a square wave with the microcontroller. In Lab 2, you generated a square wave through a parallel port pin using a wait loop. Here, you will generate a square using the output compare timer function of the microcontroller. The square wave will be generated at the port A pin OC5.

Wiring Diagram

Fill in the space at the end of the next sentence. The port A location of pin OC5 is at pin PA___.

Connect the oscilloscope Channel 1 probe to this pin.

TA checkmark ______

Test Procedure

  1. Using the results derived in Hmwk5, fill in the missing information in the first two rows of the table below.
  2. Connect the OC5 pin of port A to the oscilloscope Channel 1.
  3. Activate the program LASTNAME_Firstname_OC_sqwav.asm
  4. Put the value DT=$0100 and run your program
  5. Watch the signal on screen and measure the half wavelength duration of the square wave, in s. Enter the value in the table below
  6. Compute the corresponding ‘measured frequency’

TA checkmark ______

  1. Calculate the absolute and relative errors
  2. Repeat for the other values in the table

Desired frequency (Hz) / 250 / 1500
Calculated DT / $0100 / $1000 / $8000 / $a000 / $ffff / $ / $
Measured half wavelength duration (s)
Measured Frequency (Hz)
Absolute error (Hz)
Relative error (%)

TA checkmark ______

Dr. Victor GiurgiutiuPage 111/14/2018