DOC PREVIEW
NMT EE 308 - EE 308 – LAB 7

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Lab 7 Spring 2003EE 308 – LAB 7HCS12 Timer Input Capture and Output CompareLast week you wrote programs using the HCS12 Timer Overflow Interrupt and Real Time Interrupt.This week you will work with the Timer Input Capture and Timer Output Compare functions.1. In this lab, it will be convenient for our program to have the HCS12 print out some informationto the computer screen. You can use the standard C function printf() to do this. Here is aprogram hello.c which uses printf():#include <iodp256.h>#include <stdio.h>#define TRUE 1main(){printf("Hello, world!\r\n");}int putchar(char c){while ((SCI0SR1 & 0x80) == 0) ; // Wait until okay to xmitSCI0DRL = c; // Send byte}To use this program, you will need to modify you lkf file to include the C libraries whichinclude printf():# link command file#+seg .text -b 0x1000 -n .text # program start address+seg .const -a .text # constants follow code+seg .data -b 0x2C00 # data start addresscrts.o # startup routinehello.o # application programc:\cx32\lib\libi.h12 # include integer libraryc:\cx32\lib\libm.h12 # include machine library+def [email protected] # symbol used by library+def __stack=0x3C00 # stack pointer initial valueRun the program hello.c on your HCS12 board. Verify that you can print to the computerscreen.1EE 308 Lab 7 Spring 20032. Start with the following program, which is just a do-nothing infinite loop:#include <iodp256.h>#define TRUE 1main(){DDRA = 0xff; /* Make all bits of PORTA output */PORTA = 0x00;while (TRUE){_asm("wai");}}Connect your debounced s witch to Input C apture 2 (PORTT, Bit 2), as s hown below:0V+5VVCCIC2TRFigure 1: Circuit to measure speed of button pushing.The right part of Figure 1 is what the signal to IC2 will look like if you push the pushbuttontwice.3. Add to your program code to meas ure the time TRbetween the two falling edges of the signalin Figure 1. Set the prescaler so you can unambiguously measure time differences of at least250 ms.Use the printf() function to print out the result – the number of timer ticks between pushesof the button. (Do not try to calculate the actual time as a floating point number. Whenyou use floating p oint numbers the programs will become very large, and the floating pointlibrary for our compiler appears to be buggy.) You should write your program as an infiniteloop so that after pressing the button twice your program will print o ut the result, the gowait for the next two presses.4. Test your program on your EVBU. See how fast you can push the switch twice. Recordseveral values in you lab notebook, and convert the times to seconds.5. Add an Output Compare function on Bit 3 of PORTT to generate a 1 kHz square wave. Use alogic probe to verify that B it 3 of PORTT is toggling.2EE 308 Lab 7 Spring 20031000 s100 sRepeatµ µFigure 2: Friend signal for Part 6.6. Add an Output Compare function on Bit 4 of PORTT to generate the following signal: Thesignal consists of five pulses which are high for 100 µs and low for 100 µs, followed by a1000 µs low signal. This signal then repeats.3EE 308 Lab 7 Spring 20037. Connect your output compare signals to a logic analyzer. Verify that the square wave hasa 1 kHz frequency and a 50% duty cycle, and that the other signal looks like the signal ofFigure


View Full Document

NMT EE 308 - EE 308 – LAB 7

Documents in this Course
Load more
Download EE 308 – LAB 7
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EE 308 – LAB 7 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EE 308 – LAB 7 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?