PHYSICS 358 Advanced Electronics Laboratory Manual Fall 2014 Dr. Adam T. Whitten

Similar documents
Alice EduPad Board. User s Guide Version /11/2017

ECE 372 Microcontroller Design

Laboratory 11. Required Components: Objectives. Introduction. Digital Displays and Logic (modified from lab text by Alciatore)

Data Sheet. Electronic displays

16 Stage Bi-Directional LED Sequencer

MODULAR DIGITAL ELECTRONICS TRAINING SYSTEM

Chapter 9 MSI Logic Circuits

Laboratory 8. Digital Circuits - Counter and LED Display

V6118 EM MICROELECTRONIC - MARIN SA. 2, 4 and 8 Mutiplex LCD Driver

ECB DIGITAL ELECTRONICS PROJECT BASED LEARNING PROJECT REPORT ON 7 SEGMENT DIGITAL STOP WATCH USING DECODER

Laboratory 9 Digital Circuits: Flip Flops, One-Shot, Shift Register, Ripple Counter

TV Character Generator

Alice EduPad for Tiva or MSP432 TI ARM Launchpad. User s Guide Version /23/2017

Although the examples given in this application note are based on the ZX-24, the principles can be equally well applied to the other ZX processors.

University of Illinois at Urbana-Champaign

University of Victoria. Department of Electrical and Computer Engineering. CENG 290 Digital Design I Lab Manual

SDA 3302 Family. GHz PLL with I 2 C Bus and Four Chip Addresses

Embedded System Training Module ABLab Solutions

UNIT V 8051 Microcontroller based Systems Design

Marks and Grades Project

Reaction Game Kit MitchElectronics 2019

DRAFT Microprocessors B Lab 3 Spring PIC24 Inter-Integrated Circuit (I 2 C)

Table of Contents Introduction

Chapter 3: Sequential Logic Systems

WINTER 15 EXAMINATION Model Answer

The Micropython Microcontroller

7 SEGMENT LED DISPLAY KIT

DIGITAL ELECTRONICS: LOGIC AND CLOCKS

Sequential Logic Basics

Vorne Industries. 87/719 Analog Input Module User's Manual Industrial Drive Itasca, IL (630) Telefax (630)

LABORATORY # 1 LAB MANUAL. Digital Signals

EECS 140 Laboratory Exercise 7 PLD Programming

uresearch GRAVITECH.US GRAVITECH GROUP Copyright 2007 MicroResearch GRAVITECH GROUP

Experiment # 4 Counters and Logic Analyzer

SWITCH: Microcontroller Touch-switch Design & Test (Part 2)

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

PB-507. Advanced Analog & Digital Electronic Design Workstation Instruction Manual. Revision: 2/2014

Contents Circuits... 1

PHYS 3322 Modern Laboratory Methods I Digital Devices

ELECTRICAL ENGINEERING DEPARTMENT California Polytechnic State University

DX-10 tm Digital Interface User s Guide

82C55A CHMOS PROGRAMMABLE PERIPHERAL INTERFACE

Design and Implementation of Timer, GPIO, and 7-segment Peripherals

Catch or Die! Julia A. and Andrew C. ECE 150 Cooper Union Spring 2010

SPI Serial Communication and Nokia 5110 LCD Screen

S6B CH SEGMENT DRIVER FOR DOT MATRIX LCD

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

PHYSICS 5620 LAB 9 Basic Digital Circuits and Flip-Flops

PHY 351/651 LABORATORY 9 Digital Electronics The Basics

WINTER 14 EXAMINATION

CPE 200L LABORATORY 3: SEQUENTIAL LOGIC CIRCUITS UNIVERSITY OF NEVADA, LAS VEGAS GOALS: BACKGROUND: SR FLIP-FLOP/LATCH

Bell. Program of Study. Accelerated Digital Electronics. Dave Bell TJHSST

EE292: Fundamentals of ECE

NS8050U MICROWIRE PLUSTM Interface

Point System (for instructor and TA use only)

Report on 4-bit Counter design Report- 1, 2. Report on D- Flipflop. Course project for ECE533

PESIT Bangalore South Campus

Integration of Virtual Instrumentation into a Compressed Electricity and Electronic Curriculum

Chapter 7 Memory and Programmable Logic

DM Segment Decoder/Driver/Latch with Constant Current Source Outputs

Physics 323. Experiment # 10 - Digital Circuits

Digital Delay / Pulse Generator DG535 Digital delay and pulse generator (4-channel)

Chapter 9 Introduction to Sequential Logic

Rensselaer Polytechnic Institute Computer Hardware Design ECSE Report. Lab Three Xilinx Richards Controller and Logic Analyzer Laboratory

64CH SEGMENT DRIVER FOR DOT MATRIX LCD

Due date: Sunday, December 5 (midnight) Reading: HH section (pgs ), mbed tour

Revision: August 11, E Main Suite D Pullman, WA (509) Voice and Fax. 8 LEDs. Doc: page 1 of 9

Lab 17: Building a 4-Digit 7-Segment LED Decoder

4.9 BEAM BLANKING AND PULSING OPTIONS

Solutions to Embedded System Design Challenges Part II

SEQUENTIAL LOGIC. Satish Chandra Assistant Professor Department of Physics P P N College, Kanpur

INTRODUCTION (EE2499_Introduction.doc revised 1/1/18)

FLIP-FLOPS AND RELATED DEVICES

EECS145M 2000 Midterm #1 Page 1 Derenzo

Lab #10: Building Output Ports with the 6811

Combo Board.

Physics 217A LAB 4 Spring 2016 Shift Registers Tri-State Bus. Part I

DepartmentofElectronicEngineering NEDUniversity ofengineering &Technology LABORATORY WORKBOOK DIGITAL LOGIC DESIGN (TC-201)

DM Segment Decoder/Driver/Latch with Constant Current Source Outputs

Dynamic Animation Cube Group 1 Joseph Clark Michael Alberts Isaiah Walker Arnold Li

Engineering College. Electrical Engineering Department. Digital Electronics Lab

ECE 2274 Pre-Lab for Experiment Timer Chip

Overview of All Pixel Circuits for Active Matrix Organic Light Emitting Diode (AMOLED)

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

Data Acquisition Using LabVIEW

LED Array Board.

Light Emitting Diodes and Digital Circuits I

Decade Counters Mod-5 counter: Decade Counter:

Combinational vs Sequential

Microcontrollers and Interfacing week 7 exercises

Mission. Lab Project B

Part No. ENC-LAB01 Users Manual Introduction EncoderLAB

Spring 2011 Microprocessors B Course Project (30% of your course Grade)

ET-REMOTE DISTANCE. Manual of ET-REMOTE DISTANCE

Chapter 5 Flip-Flops and Related Devices

Digital Circuits I and II Nov. 17, 1999

A 400MHz Direct Digital Synthesizer with the AD9912

MODULE 3. Combinational & Sequential logic

CSE 352 Laboratory Assignment 3

Nuvoton Touch Key Series NT086D Datasheet

Transcription:

PHYSICS 358 Advanced Electronics Laboratory Manual Fall 2014 Dr. Adam T. Whitten

Notes

Physics 358 Advanced Electronics Lab Manual Fall 2014 Preliminaries The Coridium ARMmite microcontroller (CAM) receives its power from the USB connection to your computer. The CAM has a 3.3V regulator to reduce the voltage to the LPC2103 microcontroller on the board. While inputs to the microcontroller are 5V tolerant, you can burn out the protection diodes for the LPC2103 inputs if 5V is applied while the CAM is powered down, rendering it useless. Because of this: 1. Never power up the protoboard unless the CAM is powered up first. 2. Protect inputs to the CAM IOs with 1kΩ resistors. 3. Never exceed 3.3V on an AD input. 4. Outputs from the CAM should be buffered with TTL chips. Connect your CAM board to the lab protoboard using the provided ribbon cable. One side of the ribbon cable plugs into the header on the CAM board while the other end has 2 DIP connectors allowing it to plug into the protoboard. The pinouts are as follows: Note the orientation of the ribbon cable connected to the microcontroller board and the protoboard. 1

Physics 358 Advanced Electronics Lab Manual Fall 2014 Operation Connect the USB cable to your CAM and logon to the PC with your username and password before powering on the Global Specialties protoboard. Connect the ribbon cable to the CAM and protoboard. Connect the protoboard s ground to the two ground wires on the ribbon cable. You need only power on the protoboard when you test your programs. Launch the BASICtools program on the desktop. When you are done with a lab session, always power off the protoboard and disconnect the ribbon cable from the CAM (a power outage may result in the protoboard having power on while the computer and CAM have power off). Dual Usage Pins Eight IO pins can be used by the hardware pulse width modulation (HWPWM) function and two pins can be used for external interrupts. Plan accordingly if you use either of these features. Hardware Pulse Width Modulation External Interrupts IO Pin 0 1 2 3 4 9 10 11 IO Pin 14 15 Channel 1 2 3 4 5 6 7 8 EINT 0 2 Only HWPWM channels 1-4 use the LPC2103 s Timer2 and Timer3 modules, while channels 5-8 use the Timer2 and Timer1 modules. The Timer0 module is used in conjunction with the BASIC keyword TIMER. Therefore, if you want to use timed interrupts and HWPWM in the same program, you should use Timer1 for the timed interrupts which will limit you to HWPWM channels 1-4. IO15 is also connected through a 330Ω resistor to a LED which is tied to 3.3V. Anything connected to IO15 will be in parallel with this circuit, so design accordingly. The 10-bit analog to digital inputs (AD0-AD7) can also be configured as digital input/outputs (IO16-IO23). On reset or power up the AD pins are configured as AD inputs. To change those to digital IOs you must individually specify a control direction using INPUT(x), OUTPUT(x), DIR(x), or IO(x) commands. After that they will remain digital IOs until the next reset or power up. Lab Reports Record your lab report in an Ampad #26-251 (or equivalent). You should turn in your lab notebook at the beginning of class on Tuesday so that I may grade them. I will put your graded notebooks in your mailbox by Wednesday afternoon so you can prepare for the next lab. The labs build upon each other and are structured to prepare you to be able to complete a project during at the end of the course. Therefore timely completion and submission of your lab notebook is important. Include an introduction and conclusion for each lab. Sketch all oscilloscope waveforms and record all numerical data in your lab book. Output to the computer can be cut and pasted into a text document for printing and then taped in your lab book if necessary. Include flowcharts used for program design and diagrams for electronic circuits. Programs should be written using Notepad (using a.bas extension), fully documented, and printed out for inclusion in your lab book. 2

Lab 1 Basic Input and Output Introduction In this lab you will take keyboard and digital inputs and display them on 7-segment common anode LEDs. In part 1 you will read a hexadecimal digit from the keyboard and display it. In part 2 you will display a counting loop of hexadecimal numbers 0-F. In part 3 you will decode a 4-bit binary number and display it as a hexadecimal digit. In part 4 you will decode an 8-bit binary number and display it as two hexadecimal digits. While there are several ways to drive 7-segment displays, in this lab you will use 8 digital outputs from the CAM to turn on and off the seven segments plus decimal point. Make sure to buffer your outputs to the 7-segment display with a TTL device (e.g., 7404 Hex Inverter). Also limit the current into the display with a 330Ω resistor between the common anode and the 5V supply. By the end of the lab you will end up using 8 digital inputs and 10 digital outputs, so plan accordingly. Since you will use this LED display in subsequent labs, avoid using pins 0-3 (HWPWM), 14 (EINT0), and 15 (EINT2). Additional Components Needed (quantity): 7-segment common anode LED displays (2) 330Ω resistors (2) appropriate TTL devices for output buffers (enough for 10 outputs) limiting resistors for CAM inputs (number depends on design) 2N3904 NPN switching transistors (2) side-board SPDT switches (1 bank of 8 switches) Common Anode 7-Segment Display Pin Assignment Pin Assignment 1 Cathode a 14 Common Anode 2 Cathode f 13 Cathode b 3 Common Anode 12 N. C. 4 N. C. 11 Cathode g 5 N. C. 10 Cathode c 6 N. C. 9 Cathode dp 7 Cathode e 8 Cathode d 2N3904 Transistor Pin Description 1 collector 2 base 3 emitter The convention for displaying hexadecimal digits beyond 9 is: A, b, C, d, E, F. To distinguish 6 from b, segment a is lit for 6 and dark for b. Part 1 Terminal input and 7-segment displays Using the DEBUGIN command, read a hexadecimal digit (0-F) and display it on a 7-segment display. Perform a check on the input to make sure it is in the proper range. You should first decide which eight pins you will use to control the display. Using consecutively numbered pins will make your code easier to write and faster to execute. DIM and initialize a 16 element integer array with 8-bit values corresponding to the 8 outputs that turn on and off the segments necessary to display a digit. These values will depend on which pin is controlling each segment, so document your connections at the beginning of your program. Remember to buffer your outputs with TTL gates. Use a FUNCTION or SUB to set the levels of the outputs to the display so that it can be reused later. After your program works make sure to save it and print it out for inclusion in your 3

Lab 1 Basic Input and Output lab report. Show your working system to the instructor. Part 2 Simple counting Instead of displaying a hexadecimal digit typed in on the keyboard, create a counter that counts from 0 to F and displays each digit for 1 second. After the count reaches F it should roll over back to 0 and repeat. Use the same displaying function as in Part 1. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Part 3 Digital inputs Now for your input use 4 SPDT switches to input a high or low signal to the CAM and display the corresponding 4-bit number in hexadecimal. Use the same displaying function as in Part 1. The output should remain on the display until a switch is changed. Since the protoboard operates at 5V and the CAM operates at 3.3V, you must protect the CAM inputs with at least 1kΩ limiting resistors. This can be done by using two 1.0 kω resistors to make a voltage divider to supply the high side of the SPDT switches with 2.5 V. Explain why this works in your lab notebook! Decide which inputs you will use and document them within your program. Keep in mind that in part 4 you will expand the number of inputs to 8 and that if the inputs are numbered consecutively it will make you code more compact and efficient. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Part 4 Strobing two 7-segment displays An 8-bit binary number requires two hexadecimal digits to display. Instead of using 16 outputs to control 2 displays, you can use 8 outputs to tell a display which segments to turn on and 2 additional outputs to control power to the displays. This way you can load the data for the low nibble, turn on its display for 1 ms, then load the data for the high nibble, turn on its display for 1 ms, and repeat this process indefinitely. A human eye will not notice the continual switching because of the persistence of vision effect. Use the two additional control lines to turn on and off 2N3904 transistors which control power to the Common Anode (CA) of the displays. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Do not dismantle your 7-segment LED display circuit when you are finished you will use it again in Labs 2 & 4. 4

Lab 2 Timing External Events and PWM Introduction In this lab you will investigate the various ways the CAM can generate frequencies and measure frequencies and pulse widths. In part 1 you will generate frequencies and examine them on an oscilloscope. In part 2 you will measure an externally applied frequency from a function generator and display the frequency to 2 significant digits. In part 3 you will generate a pulse width modulated (PWM) signal that could be used to control a stepper motor and view it on an oscilloscope. In part 4 you will use external interrupts to measure your reaction time. There are various methods for generating frequencies on the CAM. Usually an interrupt driven routine is used that runs continously in the background. Non-interrupt driven routines will monopolize the microprocessor until they are finished. The typical method for measuring a frequency is to count the number of pulses at an input for a set time period. You can then calculate the frequency of the signal. Another common task is to create and measure pulse widths. You generate a pulse as part of a method to measure a person s reaction time. Additional Components Needed: the 2 digit 7-segment LED display circuit from Lab 1 Part 4 capacitors and resistors for push button switch debouncing and voltage dividing appropriate TTL devices for output buffers limiting resistors for CAM inputs LED oscilloscope function generator digital multimeter Part 1 Frequency generation Write a short program that will use HWPWM to create a 1kHz signal on pin 0. Examine the signal on an oscilloscope, sketch it in your lab notebook, and measure its frequency. Now add code to generate a second 1kHz signal on pin 1 using PWM (you may have to continuously loop to generate the signal repeatedly). Examine both the HWPWM and PWM signals on an oscilloscope. Sketch the PWM signal in you lab book and measure its frequency. Are there any other differences between the two signals? Now add code (after the PWM code) to create a signal on pin 2 that is similar to the HWPWM signal on pin 0 using the PULSOUT routine (this may require some thought). Examine both the HWPWM and PULSOUT signals on an oscilloscope and describe/sketch them in you lab book. What are the differences between the two signals? What is the effect you observe on the oscilloscope that is a consequence of some signals being interrupt driven and others being non-interrupt driven? Save your program and print it out for inclusion in your lab report. Part 2 Frequency measurement Use the COUNT subroutine to measure a frequency from the function generator. Use the TTL (pulse out) on the function generator and make sure to limit the input to the CAM with a resistor. Display the frequency in khz on your 2 digit 7-segment LED display. Your program should accomodate signals from 0.1 to 99. khz and display the decimal point in the appropriate location, 5

Lab 2 Timing External Events and PWM updating the display every 0.5 seconds. For frequencies less than 0.1 khz display 0.0. and for frequencies greater than 99. khz display -.-.. Note that there is a tradeoff between the accuracy of the measurement and the quality of the display. More time spent COUNTing gives more accuracy, but increases flicker on the display; less time spent COUNTing decreases both flicker and accuracy. Justify your choice of count time. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Part 3 Pulse width modulation with external interrupts Write a program that will create a 2kHz pulse width modulated signal. The duty cycle should be displayed on your 2 digit 7-segment LED display and use external interrupt routines with appropriately debounced push buttons (see figure below). Use one push button to increase the duty cycle by 10% (to a maximum of 100%) each time it is pressed and a second push button to decrease the duty cycle from it s current value to 0% over 2 seconds. View the waveform on an oscilloscope and measure the output voltage on a voltmeter. What happens to the output voltage as the duty cycle increases, remains constant, and decreases? Collect data for output voltage versus duty cycle and plot it using WAPP+. Is the graph linear? Explain. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Part 4 Measure reaction time Create a system to measure a person s reaction time using external interrupt routines with an appropriately debounced push button. When a push button is first pressed, turn on an LED for a random length of time between 3 and 6 seconds. When the LED goes off, time how long it takes for the person to press the button again. Display this time in seconds on your 2 digit 7-segment display putting the decimal point in the appropriate location, with times less than a second having no decimal point. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. 6

Lab 3 Analog to Digital Conversion Introduction In this lab you will check on the accuracy and precision of the CAM analog to digital converter. You will also use measurements of the decaying voltage on a capacitor to determine the capacitance of a RC circuit. The CAM can perform a 10-bit analog to digital conversion in approximately 6 µs and the result is stored as a 16-bit left justified number. To convert the 16-bit number to the appropriate 10-bit number shift it to the right 6 bits. To convert the count to a voltage you multiply by V max (in this case 3.3 V) and divide by the maximum count (2 10 ). Notes: You can copy output from the BASICtools terminal window and paste it into a spreadsheet or document. WAPP+ is limited to 99 data points. Additional Components Needed: the 2 digit 7-segment LED display circuit from Lab 1 Part 4 capacitors and resistors for push button switch debouncing and voltage dividing appropriate TTL devices for output buffers limiting resistors for CAM inputs digital multimeter 1.0 µf capacitor and 330 kω resistor for RC circuit Part 1 Analog to digital conversion Using the 10 kω potentiometer on the protoboard and suitable resistors create a circuit to provide a variable 0.0-3.3 V input to the CAM. Use EINT0 to initiate a series of 10 analog to digital conversions and print out the resulting counts to the terminal. Also measure the voltage with a digital multimeter (V DMM ) during the conversion process and record the uncertainty δv DMM in this measurement. Collect data over the full range of voltage inputs (do not worry if your input does not go all the way up to 3.3 V or down to 0.0 V). Use a spreadsheet to find the average and standard deviation of the mean of the ten conversions of each voltage. Use WAPP+ to fit Counts vs. V DMM to a straight line and graph it. Put the fit report and graph in your lab notebook. Comment on the fit parameters. To how many bits is the conversion process accurate? What is the conversion factor for counts to voltage and how does it compare to the theoretical value? After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Part 2 Measure RC time constant Wire up the simple RC circuit pictured at the right. Measure and record the resistance in your lab notebook. Use the CAM to digitize the voltage on the capacitor and measure elapsed time during a discharge and send these values to the computer. Use EINT0 to trigger a discharge and start the measurement cycle. Note: the capacitor will charge when IO(0)=1 and discharge when IO(0)=0. You may use the CAM to convert the digitized counts to voltages and print the voltage and elapsed time to the terminal. Copy your data to a spreadsheet and use WAPP+ to fit Voltage vs. Time and graph it. Describe in your lab notebook how you found the uncertainties in the voltages. Put the fit report and graph in your lab notebook. Comment on the fit parameters. What is the RC time constant? Calculate the value of your capacitor. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. 7

Lab 3 Analog to Digital Conversion This page intentionally left blank. 8

Lab 4 I2C Interfacing Introduction In this lab you will interface an I/O expander and EEPROM memory with the CAM using the I2C protocol. Communication with I2C devices is via I2CIN and I2COUT: I2CIN(DATApin, CLKpin, addr, OUTcnt, OUTlist, INcnt, INlist) I2COUT(DATApin, CLKpin, addr, OUTcnt, OUTlist) The PCF8574A I/O expander is a simple slave device that runs at 100 khz, can drive LEDs directly, and has a device address 0111zyxR, where zyx are the logic levels on pins A2, A1, and A0 respectively. R is either 1 for a read operation or 0 for a write operation. It can also generate an interrupt signal with any rising or falling edge of the port inputs when in input mode. Data is sent to the I/O expander one byte at a time so OUTcnt is always 1 in the I2COUT command. Since it has only one internal memory location, data is received by setting OUTcnt to 1, OUTlist to null (i.e., ), and INcnt to 1. The 24LC512 is a 512 Kbit serial EEPROM, meaning that it has 64K bytes of storage. To randomly access this much storage a 16 bit (or 2 byte) address is needed. When using I2CIN with the 24LC512 you pass the desired read memory address in OUTlist. The 24LC512 has a device address of 1010zyxR, where zyx are the logic levels on pins A2, A1, and A0 respectively. R is either 1 for a read operation or 0 for a write operation. Operations on 24LC512 memory chips with the CAM that can be performed are: Operation OUTcnt value OUTlist Byte Write 3 {hiaddr,loaddr,data} Page Write 4 up to 130 {hiaddr,loaddr,data0,...,data127} Current Address Read 1 {} (blank) use Random Read 2 hiaddr,loaddr For read operations, setting INcnt to 1 will perform a byte read and any number greater than 1 will perform a sequential read. Refer to 24LC512 datasheet for restrictions on page writes and sequential reads. Additional Components Needed: the 2 digit 7-segment LED display circuit from Lab 1 Part 4 capacitors and resistors for push button switch debouncing and voltage dividing 2 PCF8574A remote 8-bit I/O expanders for I2C bus 24LC512 I2C bus serial EEPROM pullup resistors for clock, data, and interrupt lines Part 1 Using two 8574As for input and output Revisit Lab 1 Part 4 Strobing two 7-segment displays, but instead of using CAM I/O lines for input and output use 2 8574A I/O expanders. Instead of using 8 I/O lines from the CAM to drive the segments of the displays, use a 8574A I/O expander with A2, A1, and A0 hardwired to ground so that its address is 0111000R (note: R will always be 0 for writes). Since the 8574A runs at 100 khz, you should include #define I2Cspeed100. You will still need 2 CAM I/O lines to control power to each 7-segment display. 9

Lab 4 I2C Interfacing Give the second 8574A and address of 0111001R (note: R will always be 1 for reads) and connect it to the side-board data switch. When the input changes, the 8574A should send an interrupt to the CAM so that it can read the new data and update the display. Use a delay at the beginning of the interrupt service routine and before reading the data in order to accommodate for switch bounce. The INT requires a pullup resistor (1.0 kω is fine) and goes low when any input pin changes. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Part 2 I2C memory interfacing Revisit Lab 3 Part 2 Measure RC time constant, but instead of sending data to the computer write it to a 24LC512 I2C bus serial EEPROM. Leave the 8574A used for the 7-segment display. Since the analog to digital converter is good to ten bits, it will take two bytes in the 24LC512 to store the digitized number. If the digitized number is converted to a single precision floating point value, that value will required 32 bits or 4 bytes of storage. Similarly, since TIMER is a 32-bit value it will take four bytes in the 24LC512 to store a single value. Reserve the first two memory locations to store the address high byte and address low byte of the last memory location used. Flash this memory location on the 7-segment display: high byte for 1 second, low byte for 1 second, then blank for 1 second. If you use page writes, be careful to not write across page boundaries (i.e., don t use page writes). For byte writes you may need to insert a delay after each write to allow the EEPROM to complete the writing process. Use EINT2 to tell the CAM to read the 24LC512 and send the data to you computer. Copy your data to a spreadsheet and use WAPP+ to fit Voltage vs. Time and graph it. Put the fit report in your lab notebook. Is the value for your RC time constant the same as what you found in Lab 3 Part 2? After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. 10

Lab 5 Matrix Keypads and Multidigit Displays Introduction In this lab you will interface more complex input output devices. A matrix keypad allows for greater flexibility in user input compared to simple pushbuttons or switches. Multidigit displays eliminate the need for software multiplexing, but require more I/O lines for interfacing. The matrix keypad requires 8 connections. All buttons in a common row are connected by a common wire available at pins 1-4 for rows 0-3. All buttons in a common column are connected by a common wire available at pins 5-8 for columns 0-3. In your textbook, the columns have an external 1 kω pull-up resistor, although the keypad will also work if the pull-up resistors are put on the rows instead. The keypad is read by sequentially setting the row lines to LOW and then reading the column lines. When a button in row, col = i, j is pressed, col j only reads LOW when row i is low, otherwise col j is high. The period for changing rows should be in the ms range. 1 GHI 4 PRS 7 1 2 3 4 5 6 7 8 ABC 2 JKL 5 DEF 3 MNO 6 TUV WXY 8 9 OPER 0 * # A B C D 16 Button Keypad Top View Pinout Button Location 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Terminal Location 1 2 3 4 5 6 7 8 1 2 3 A 4 5 6 B 7 8 9 C * 0 # D Faceplate Character 16 Button Code and Truth Table Pin 1 Pin 2 Pin 3 Pin 4 Pin 5 Pin 6 Pin 7 Pin 8 (could connect to I/O expander) (could connect to I/O expander) Pull-up Resistors (could be on rows instead) Both polling and interrupt techniques can be used to interface the matrix keypad. Polling techniques require the microcontroller to spend time checking if a key is pressed (executing a loop every hundred milliseconds or so) and then decoding the matrix. Interrupt techniques wait until a key has been pressed before decoding the matrix, thereby freeing up the microcontroller to handle other tasks. Neither approach is superior to the other the best approach depends on the particular application (see pages 57-58 of your text). If polling is used, 4 digital outputs from the microcontroller are connected to the row pins and are periodically driven low sequentially in order to test whether a button has been pressed. The column lines are connected to 4 digital inputs to the microcontroller and read to see if one of the inputs is LOW. Alternatively, the column lines could be connected to an I/O expander which can then be read after each row line goes low to check if a key has been pressed. These are pure polling techniques. There are several ways to make an interrupt driven keypad system, but I/O expanders with interrupt capabilities facilitate their design. Half the lines of an I/O port are connected to the rows and half are connected to the columns. In some application notes (e.g., AN1081 Interfacing a 4x4 Matrix Keypad with an 8-Bit GPIO Expander, by Mike Curran of Microchip Technology Inc., 2007) the functions of the rows and columns are reversed: columns are output pins and rows are input pins with external pull-up resistors to V DD. When a button is pressed a row input is changed from high to low generating an interrupt. The expander is read to determine the row number, the I/O directions are flipped, and the expander is re-read to determine the column number. 11

Lab 5 Matrix Keypads and Multidigit Displays Multidigit displays are nice because they can convey more information than one or two 7-segment displays. However, they have significantly more inputs, so I/O expanders may be necessary. The 4-1/2 digit LCD displays that are available are 40-pin devices with 38 segments that can be activated. Typically not every segment is required for every application (e.g., multimeters would not need the colons and clocks would not need all the decimal points or the ±). In this lab we will use 4 digits, so you will need 2 16-bit I/O expanders. 40 21 la a y x f g b x e d c dp1 dp2 dp3 dp4 DIG. 1 DIG. 2 DIG. 3 DIG. 4 DIG. 5 col2 col3 Pin 1 2 3 4 5 6 7 8 9 10 Seg. COM y 1bc dp1 2e 2d 2c dp2 3e 3d Pin 11 12 13 14 15 16 17 18 19 20 Seg. 3c dp3 4e 4d 4c dp4 5e 5d 5c 5b Pin 21 22 23 24 25 26 27 28 29 30 Seg. 5a 5f 5g 4b 4a 4f 4g col3 3b 3a Pin 31 32 33 34 35 36 37 38 39 40 Seg. 3f 3g col2 2b 2a 2f 2g la x COM 1 20 The MCP23017 is a 16-bit I/O expander with 22 individual registers. Its device address (i.e., control byte) is of the form 0100zyxR, where zyx are the logic levels on pins A2, A1, and A0 respectively. R is either 1 for a read operation or 0 for a write operation. Ten registers are associated with port A and ten are associated with port B. There is one shared register (IOCON). The port A registers are identical to the port B registers. They can be separated by bank (all port A registers at addresses 0x00-0x0A, all port B registers at addresses 0x10-0x1A) or can be paired (addressed sequentially by function first for port A and then for port B). To use these expanders you should first configure them with I2COUT commands before entering your MAIN: loop. I2CIN(DATApin, CLKpin, addr, OUTcnt, OUTlist, INcnt, INlist) I2COUT(DATApin, CLKpin, addr, OUTcnt, OUTlist) GPB0 GPB1 GPB2 GPB3 GPB4 GPB5 GPB6 GPB7 V DD V SS NC SCL SDA NC 1 2 3 4 5 6 7 8 9 10 11 12 13 14 MCP23017 28 27 26 25 24 23 22 21 20 19 18 17 GPA7 GPA6 GPA5 GPA4 GPA3 GPA2 GPA1 GPA0 INTA INTB RESET A2 16 A1 15 A0 For example, to separate the registers into two banks and disable sequential operation the address of the IOCON register (0x05) is sent followed by the desired data value (0xA0): OUTcnt= 2 and OUTlist=(0x05, 0xA0). Then to read the data present on port A, use I2CIN with OUTcnt=1, OUTlist=(0x09), and INcnt=1. At power on or after a reset the ports are configured as inputs by default. Additional Components Needed: 1 4x4 keypad 1 4-1/2 digit LCD display 1 PCF8574A remote 8-bit I/O expanders for I2C bus 2 MCP23017 remote 16-bit I/O expanders for I2C bus pullup resistors for keypad, clock, data, and interrupt lines capacitors and resistors for push button switch debouncing and voltage dividing Part 1 Polled matrix keypad Connect your matrix keypad directly to the microcontroller. Use the configuration outlined in your 12

Lab 5 Matrix Keypads and Multidigit Displays textbook put 10 kω pull-up resistors on columns and periodically drive the rows sequentially low to test for a button being pressed. If you use consecutively numbered I/O lines, your programming code will be more compact. Print out to the terminal the location (0-15) of the button when it is pressed. You ll need to decide on an appropriate polling time so that you capture the button pressing event once and only once. Remember that the interval for changing the row should be in the millisecond range. Show your working system to the instructor. Clearly explain in your lab notebook why you chose the polling time and row interval you ended up using (i.e., what did you see happening that caused you to increase or decrease these times). Part 2 Interrupt-driven matrix keypad Use the INT feature of the 8574A I/O expander to make an interrupt driven keypad interface. Connect the keypad as shown in the diagram. Note that the pull-up resistors are now connected to the keypad rows. Not shown in the diagram are the pull-up resistors for SDA and SCL (2.2 kω) and INT (1.0 kω). The quasi-bidirectional port lines of the 8574A allow the pins to function as either inputs or outputs. An interrupt is generated (INT pulled low) if the data on the port changes. The 8574 is initialized by writing 0xF0 (binary 11110000) to the port so that the rows are high and the columns are low. Matrix Keypad VDD 1 row 0 2 row 1 3 row 2 4 row 3 5 col 0 6 col 1 7 col 2 8 col 3 10kΩ P4 P5 P6 P7 P0 P1 P2 P3 8574A SDA SCL INT When a key is pressed it s corresponding row will go low, changing the data on the port and generating an interrupt. For example, if the 6 key is pressed the data on the port becomes 0xD0 (binary 11010000). If you read the port (which clears the interrupt) and divide the value by 16, the resulting number has a 0 in the bit position corresponding to the row of the key that was pressed. Note that mechanical buttons suffer from switch bounce and that keypads are no exception. Pressing a button may cause multiple interrupts, so your interrupt service routine should wait for a millisecond before doing anything else. Next the direction of the I/O lines of the 8574A is flipped by writing 0x0F to the port making all rows low and all columns high. However, because a key is still pressed one of the columns will stay low (in this example with 6 pressed column 2 will be low). Reading the port gives a number that has a 0 in the bit position corresponding to the column of the key that was pressed. In this example, you would read 0x0B (binary 00001011) from the port. The last step is to flip the I/O directions back to their original state by writing 0xF0 to the port. If this is done immediately then another interrupt will be generated when the button is released. You can test for button release by reading the port until its value goes back to 0x0F. After the port returns to this state, then flip the I/O directions back by writing 0xF0 to the port. To convert the bit positions to a number, you can use the compact code shown to the right. Once this is done for the row and column values, then the button location is obtained from key=4*row+col. Print this button location out to the terminal only if a button is pressed. j=16 FOR i=3 DOWNTO 0 j >>= 1 IF (row AND j)=0 THEN row=i EXIT ENDIF NEXT i Show your working system to the instructor. Do you ever see a button location outside the range 0-15? If so, when does it occur? Give an explanation of why it occurs. Do not dismantle this circuit you will use it in part 3. 13

Lab 5 Matrix Keypads and Multidigit Displays Part 3 Multidigit displays The multidigit displays have 4-1/2 LCD digits. To activate the segment of a digit its corresponding pin must be made high. Each digit has 7 segments and a leading decimal point, so it is convenient to use a single 8-bit port to drive them (e.g., one port can drive segments 5a-5g and dp4). Use 2 MCP23017s to drive digits 2-5 and dp1-dp4 in this manner. A single PCF8574A could then be used to drive digit 1, col2, col3, x, y, and la (only 6 bits are required), but we will not use them in this lab. Your goal is to start with a blank display and then scroll characters across the display as keypad buttons are pressed. You will need to map the button location to a byte that will be sent to the correct MCP23017 port to display a proper hexadecimal digit corresponding to the value on the keypad button (0-9, A-D). When the asterisk key (*) is pressed E should be displayed and when the pound key (#) is pressed F should be displayed. Make sure to check for button location values that are out of bounds and do not update the display if this event occurs. Only update the display when a valid key is pressed. For example, after starting the program if you press buttons 2-C-#-9-4-B-* the display should show: blank 2 2C 2CF 2CF 9 CF 94 F 94B 94BE Make sure the MCP23017s have different hardware addresses and that you connect their reset lines to V DD. Note that the default power-on state of the MCP23017s is to be in paired mode (IOCON.BANK=0) with port pins set as inputs (IODIRA=IODIRB=0xFF). Therefore, the only configuration you have to do is to set the port pins as outputs. Thereafter you send data to registers GPIOA (hex address 12) and GPIOB (hex address 13). Since the keypad is interrupt driven, have your main program continuously send data to the I/O expanders. View SCL and SDA on an oscilloscope. Sketch their waveforms in your lab notebook and identify each bit in the data sequence as well as the start and stop conditions. Show your working system to the instructor. 14

Lab 6 Device Interfacing Introduction In this lab you will interface various devices that are typically used in standalone microcontroller applications. In part 1 you will control a DC motor using interrupts to spin up and spin down the motor. These interrupts could be generated by other devices such light detectors and range finders, but we will use pushbuttons in this lab. In part 2 you will measure the output of a phototransistor circuit which is properly interfaced to the analog to digital converter. In part 3 you will modify your phototransistor circuit to provide a digital input to the microcontroller. Additional Components Needed: the 2 digit 7-segment LED display circuit from Lab 1 Part 4 +3.3 and 3.3 voltage regulators Lambda power supply, function generator, and oscilloscope various discrete components (see descriptions for each part below) Part 1 DC motor control You will use hardware pulse width modulation to bring a motor up to its maximum speed and then back down by activating push buttons as in Lab 2 Part 3 Pulse width modulation with external interrupts. You may use the same control program that you used in Lab 2 Part 3 with the exception that you will have to determine the best driving frequency. DC motors have intrinsic resistance, capacitance, and inductance that may change with the frequency of the applied driving current which is being switched on and off. You can quantitatively determine the best frequency by first driving the motor with a TTL pulse train (equivalent to a 50% duty cycle) and measuring the speed of the motor. In this lab you will not do a quatitative assessment, only a qualitative assessment of a good frequency by observing the speed of the motor. You should end up with a frequency between 100 Hz and 1 khz depending on which motor you use. The motors run at either 5 V, 12 V, or 27 V (check the label on the motor) so set up a Lambda power supply to provide this V s. You will also need to determine appropriate values for R 1 and R 2 based on maximum ratings for input and output current listed in the MCT272 datasheet. The diode is used to block current produced by back emf when the power switches off. Be sure to describe how you chose your driving frequency, R 1, and R 2 in you lab notebook. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. 15

Lab 6 Device Interfacing Part 2 Phototransistor analog interfacing Use a FPT5902 phototransistor and a LF356 opamp to generate an analog signal to be measured by the microprocessor. Choose feedback resistors that do not saturate the output when the phototransistor is illuminated with a flashlight. Use +3.3 and 3.3 voltage regulators to provide V CC and V EE to the opamp and bias to the phototransistor. You could end up with lots of data, so start and end the measurements with push buttons. Start a measurement, quickly pass the flashlight over the phototransistor, and end the measurement. Collect time and voltage data during the measurement cycle and print it to the screen so you can graph it and include it in your lab notebook. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. Part 3 Phototransistor digital interfacing Use the FPT5902 in a common-collector amplifier configuration to provide a digital input to the microcontroller. Be sure to use a high enough resistance so that the photodiode operates in switch mode. The microprocessor should continually read the output and display its status on a single LED (on if illuminated, off if not). Your circuit should also have an enable feature provided by the microprocessor so that when the circuit is disabled by the microprocessor the output is always low. Use a single push button to activate and deactivate the enable feature. After your program works make sure to save it and print it out for inclusion in your lab report. Show your working system to the instructor. 16

Lab 7 Project Using what you have learned in class design your own microcontroller circuit that meets the following requirements: 1. uses at least one interrupt 2. uses at least one analog or digital input 3. uses at least one output (digital, PWM, pulse) for control 4. incorporates at least one I2C device in some useful way 5. provides feedback to the user in the form of LEDs or 7-segment displays If a particular input or output device is not on hand you may simulate its presence with other electronics after first researching the device s specifications. For example, frequency inputs can be simulated with a function generator, digital inputs with switches, and analog inputs with potentiometers; outputs can be displayed on an oscilloscope or voltmeter. Your project must be pre-approved by the instructor before lecture on Tuesday, November 11. At the beginning of lab on November 13 you will turn in a copy of your Product Requirements Specification and top level design. Your second level and detailed designs are due at the beginning of class on Tuesday, November 18. All that will be left to do in lab is code the microcontroller and build the interface. Document your work in your lab notebook. Put a copy of your program in your lab notebook. Show your working system to the instructor. Write up your project in a short (3-10 pages) report that includes a copy of your control program at the end. 17