DOC PREVIEW
NMT EE 308 - EE 308 Exam 1

This preview shows page 1-2-3-24-25-26 out of 26 pages.

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

Unformatted text preview:

EE 308 Spring 2009Exam 1Feb. 27• You w ill be able to use all of the Motorola data manuals on the exam.• No calculators will be allowed for the exam.• Numbers– Decimal to Hex (signed and unsigned)– Hex to Decimal (signed and unsigned)– Binary to Hex– Hex to Binary– Addition and subtraction of fixed-length hex numbers– Overflow, Carry, Zero, Negative bits of CCR• Programming Model– Internal registers – A, B, (D = AB), X, Y, SP, PC, CCR• Addressing M odes and Effective Addresses– INH, IMM, DIR, EXT, REL, IDX (Not Indexed Indirect)– How to determine effective address• Instructions– What they do - Core Users Guide– What machine code is generated– How many cycles to execute– Effe ct on CCR– Branch instructions – which to use with signed and which with unsigned• Machine Code– Reverse Assembly• Stack and Stack Pointer– What happens to stack and SP for instructions (e.g., PSHX, JSR)– How the SP is used in getting to and leaving subroutines• Asse mbly Language– Be able to read and write simple assembly language program– Know basic assembler directives – e.g., equ, dc.b, ds.w– Flow charts1EE 308 Spring 2009Delay subroutine from textbookvoid delayby10us(int k){int i;TSCR1 |= TFFCA; /* enable fast timer flag clear */for (i = 0; i < k; i++) {MCCTL = 0x04; /* enable modulus down counter with 1:1 as prescaler */MCCNT = 240; /* let modulus down counter count down from 1200 */while(!(MCFLG & MCZF));MCCTL &= ~0x04; /* disable modulus down counter */}}• Func tion sets MCCNT (modulus down counter) to a value which will take 10 µs tocount down to zero• Func tion waits until MCCNT reaches zero and the MCZF (modulus counter zero flag)is set• Problems:– Cannot do anything while waiting– Changes value of TSCR1, so may affect how timer subsystem works if you areusing it for other purposes• Be tter to use another method – Timer Overflow Interrupt, Real Time Interrupt, OutputCompare Interrupt, or Modulus Downcounter with interrupts enbaled2EE 308 Spring 2009Capturing the Time of an External Event• One way to determine the time of an external event is to wait for the event to occur,the read the TCNT register:• For example, to determine the time a signal on Bit 0 of PORTB changes from a high toa low:while ((PORTB & BIT0) != 0) ; /* Wait while Bit 0 high */time = TCNT; /* Read time after goes low */• Two problems with this:1. Cannot do anything else while waiting2. Do not get exact time because of delays in software• To solve problems use hardware which latches TCNT when event occurs, and generatesan interrupt.• Such hardware is built into the MC9S12 — called the Input Capture System3EE 308 Spring 2009Measure the time between two events+5V∆ tPB0PB1+5VPB0 PB1How to measure ∆t?Wait until signal goes low, then measure TCNTwhile ((PORTB & BIT0) == BIT0) ;start = TCNT;while ((PORTB & BIT0) == BIT1) ;end = TCNT;dt = end - start;4EE 308 Spring 2009Measure the time between two events+5V∆ tPB0PB1+5VPB0 PB1How to measure∆t?Wait until signal goes low, then measure TCNTwhile ((PORTB & BIT0) == BIT0) ;start = TCNT;while ((PORTB & BIT1) == BIT1) ;end = TCNT;dt = end - start;Problems: 1) May not get very accurate time2) Can’t do anything while waiting for signallevel to change.5EE 308 Spring 2009Measure the time between two events+5V∆ tPB0PB1+5VTCNTINTERRUPTSolution: Latch TCNT on falling edge of signalRead latched values anytime later and get exact valueCan have MC9S12 generate interrupt when event occurs, so can doother things while waiting6EE 308 Spring 2009The MC9S12 Input Capture Function• The MC9S12 allows you to capture the time an external e vent occurs on any of theeight Port T PTT pins• An e xternal event is either a rising edge or a falling edge• To use the Input Capture Function:– Enable the timer subsystem (set TEN bit of TSCR1)– Set the prescaler– Tell the MC9S12 that you want to use a particular pin of PTT for input capture– Tell the MC9S12 which edge (rising, falling, or either) you want to capture– Tell the MC9S12 if you want an interrupt to be generated when the cature occurs7EE 308 Spring 2009A Simplified Block Diagram of the MC9S12 Input Capture SubsystemWriteReadTFLG1TFLG1D QVCC00: DisableTCNT16 Bit CounterCapture01: Rising10: Falling11: Either EdgeRegisterEDGx B:A(TCTL 3:4)INPUT CAPTURETCxCxICxFCxFInterruptI BitCCRPrescalerPort T Pin x set up as Input Capture (IOSx = 0 in TOIS)Bus ClockTIEPTT Pin x8EE 308 Spring 2009Registers used to enable Input Capture FunctionTo turn on the timer subsystem: TSCR1 = BIT7;TSWAI TSBCK TFFCA you want to measureTOI TCRE PR2 PR1 PR0PR2 PR1 PR000 11 01 1000 11 01 1000001111Period Overflow( s) (ms)µMake sure the overflow time is greater than the time differenceTEN0Write a 1 to Bit 7 of TSCR1 to turn on timer0x0046 TSCR1Set the prescaler in TSCR20x004D TSCR2 0 00.04160.08330.16670.33330.66671.33332.66675.33332.73 5.4610.9221.84 43.69 86.38174.76349.53To have overflow rate of 21.84 ms:TSCR2 = 0x03;9EE 308 Spring 2009TCTL4 = (TCTL4 | BIT6) & ~BIT7;Write a 0 to the bits of TIOS to make those pins input captureWrite to TCTL3 and TCTL4 to choose edge(s) to captureEDGnB EDGnA Configuration0 0 Disabled0 1 Rising1 0 Falling1 1 AnyTo have Pin 3 capture a rising edge:IOS7 IOS6 IOS5 IOS4 IOS3 IOS2 IOS1 IOS0EDG7B EDG7A EDG6B EDG6A EDG5B EDG5A EDG4B EDG4AEDG3B EDG3A EDG2B EDG2A EDG1B EDG1A EDG0B EDG0A0x0040 TIOS0x004A TCTL30x004B TCTL4To make Pin 3 an input capture pin: TIOS = TIOS & ~BIT3;To enable interrupt on Pin 3: TIE = TIE | BIT3;CF7 CF6 CF4 CF3 CF2 CF0CF5 CF1 0x008E TFLG1When specified edge occurs, the corresponding bit in TFLG1 will be set.To clear the flag, write a 1 to the bit you want to clear (0 to all others)C4I C2IC5Ibit in TIE registerTo enable interrupt when specified edge occurs, set correspondingC7I C6I C3I C1I C0ITo determine time of specified edge, read 16−bit result registers TC0 thru TC7To read time of edge on Pin 3: unsigned int time;time = TC3;40x004C TIETo wait until rising edge on Pin 3: while ((TFLG1 & BIT3) == 0) ;To clear flag bit for Pin 3: TFLG1 = BIT3;10EE 308 Spring 2009USING INPUT CAPTURE ON THE MC9S12Input Capture: Connect a digital signal to a pin of Port T. Can capture the time of anedge (rising, falling or either) – the edge will latch the value of TCNT into TCx register.This is used to measure the difference between two times.To use Port T Pin x as an input capture pin:1. Turn on timer subsystem (1


View Full Document

NMT EE 308 - EE 308 Exam 1

Documents in this Course
Load more
Download EE 308 Exam 1
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 Exam 1 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 Exam 1 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?