ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?

Slides:



Advertisements
Similar presentations
More fun with Timer/Counters
Advertisements

4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
10-1 EE 319K Introduction to Microcontrollers Lecture 10: Interrupts, Output Compare Periodic Interrupts Read Book Sections 9.1, 9.2, 9.4, 9.6.1, 9.6.2,
ELEC 330 Digital Systems Engineering Dr. Ron Hayne
EET 2261 Unit 10 Enhanced Capture Timer  Read Almy, Chapter 20.  Homework #10 and Lab #10 due next week.  Quiz next week.
68HC11 Polling and Interrupts
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
INTERRUPTS PROGRAMMING
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
ENG3640 Microcomputer Interfacing Week #6 Timing Generation and Measurement.
ELE22MIC Lecture 19, 20, 21 Edge Detector Latch vs Flip Flop
ELN5622 Embedded Systems Class 5 Spring, 2003 Aaron Itskovich
8254 Programmable Interval Timer
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Timer Operations.
ARM Timers.
System Clocks.
M Semiconductor Products Sector Computer Operating Properly Module Detail Slide #1 of 7 Tutorial Introduction PURPOSE -To explain how to configure and.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Interrupts, Counter and Timers. Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow.
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Interrupts and reset operations. Overview  Introduction to interrupts – What are they – How are they used  68HC11 interrupt mechanisms – Types of interrupts.
ECE 447: Lecture 8 Timer System (1). ECE 447: 68HC11 Timer System 1.Generating delays - imposing a specific delay between two points in the program by.
Chapter 11: Timer Subsystem Esteban Rodriguez-Marek Eastern Washington University Department of Engineering & Design.
ELE22MIC Lecture 15 Applications of Parallel Input Output (I/O)
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
CS-280 Dr. Mark L. Hornick 1 Atmel Timer/Counter System Most microcontrollers include some type of timer system Facilitates real-time monitoring and control.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
ECE 265 – LECTURE 5 The M68HC11 Basic Instruction Set 12/8/ ECE265.
1 Stacks, Subroutines, I/O Routines Today: First Hour: Stacks, Subroutines –Section 3.9,3.10 of Huang’s Textbook –In-class Activity #1 Second Hour: I/O.
ECE Lecture 21 Typical Assembly Language Program Bugs.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
System Integration Module MTT Motoola SYSTEM INTEGRATION MODULE (SIM)
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare.
Timers Presented by: Griffin Reid Rohit Vardhan Freddie Wilson Date: October 25, 2005.
Computer Operating Properly Module MTT COMPUTER OPERATING PROPERLY MODULE (COP)
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
ECE 3430 – Intro to Microcomputer Systems
68HC11 Interrupts & Resets.
ECE 3430 – Intro to Microcomputer Systems
Mon. Oct 2 Announcements Quiz Postponed to Wednesday – still only on 2.a + 2.b Video lecture for 2.a posted Lab 6 experiment extension You must come to.
Timer and Interrupts.
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
AVR Addressing Modes Subject: Microcontoller & Interfacing
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
MCO556 Timer System Exercise.
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Presentation transcript:

ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?

Writing 68HC11 software Use Functional Decomposition i.e. Break down complex functions into several simpler functions or subroutines. For example a long time delay cannot be created using just one 16 bit counter, so break the time delay into two parts. 1. A short time delay subroutine 2. A long time delay subroutine that calls the short time delay routine many times.

Software Time Delays Wait_a_sec: LDX #1000; 3 cycles Delay_lots: JSR Wait_a_bit ; 6 for jsr ; * wait 10 ms * Subroutine Wait_a_bit is on next page DEX; 3 BNE Delay_lots; 3 RTS ; 5 * ReTurn from Subroutine

Software Time Delays * 1 us = 2 cycles, so 1ms = 2000 cycles. * 10 cycles per delay_more loop. * 29 cycles in wait_a_sec/jsr/pshx/setup/rts overhead... Wait_a_bit: PSHX ; save x on stack 4 LDX #1971 ; X = Delay_More: NOP ; waste some time 2 NOP ; 2 DEX ; X - - ; 3 BNE Delay_More ; Is (X = 0)? 3 PULX ; recover x 5 RTS ; ReTurn from Subroutine 5

68HC11 Timer - PreScaler An E-Clock PreScaler divides by 1, 4, 8 or 16 This value is selected by writing to Bits PR0, PR1 of the TMSK2 register (at $1024). In normal modes the pre-scale rate may only be changed once within the first 64 bus cycles after reset.

68HC11 Timer - PreScaler Crystal Frequency vs clock Pre-Scaler

Free Running Counter - TCNT (1) The pre-scaled clock clocks a free-running counter, TCNT (= $100E..$100F) The TCNT Count Value can be read using the instructions: LDD$100E Reads all 16 Bits in one instruction. The Timer value is frozen during this instruction sequence. DONT read the timer with the following instruction sequence: LDAA $100E LDAB $100F as the counter will be incremented between the instructions

68HC11 Timer System (1) The HC11 Timer System is based on a free- running 16 bit counter with a four stage programmable pre-scaler. Assuming PR0=0 and PR1 = 0 => TCNT counts at frequency of divide E by 1 (8MHz crystal -> 2MHZ E clock -> 0.5us per count). Five Output Compare functions are included for generating software timing delays or output signals on pins OC1, OC2, OC3, OC4 and OC5 OC2..OC5 work in exactly the same manner.

68HC11 Timer System (2) Timer Register Summary: –TCNT - 2-byte Free Running Timer Counter Value –TOCx/TICx - 8 x 2-byte TIC/TOC count registers 5 for Timer Ouput Compare & 4 Timer Input Capture (One shared TIC/TOC) –TMSK1 - 1 byte - Timer Interrupt Enables –TMSK2 - $ PR0/PR1/RTI –OPTION - $ CR0/CR1 - Clock Pre-scaler –CFORC - 1 x byte port for Force output compare –TCTL2 - 1 x byte register for output port control OMx/OLx –TFLG1 - 1 x byte flag register indicating state of comparisons

Timer Output Compare - TOC (1) The five Output Compare pins can be used independently to create precise timing for time delays or external logic pulses. Each Output Compare Register is compared to the value in the 16 bit counter, and if equal, triggers its Timer Output Compare (TOCn) function.

Timer Output Compare (2) The output compare hardware can ensure that intervals and waveforms are not subject to jitter due to interrupt servicing routines

Timer Output Compare (3) TCTL2 $1020, OM2 & OL2 - select the relationship of Output Compare to Output Port Pin OMx OLx where x = No Change 0 1Toggle Pin state 1 0Force Pin to 0 1 1Force Pin to 1

TOC2 code (4) REGBAS EQU $1000* Starting address for register block PORTBEQU $04 * Output port B TCNTEQU $0E * Free running counter (16 bit) TOC2EQU $18 * OC2 register (16 bit) TCTL1EQU $20 * OM2,OL2,OM3,OL3;OM4,OL4,OM5,OL5 TCTL2EQU $21 * -,-,EDGlB,EDGlA,EDG2B,EDG2A,EDG3B, * EDG3A TMSK1EQU $22* OC1I,OC2I,OC3I,OC4I;OC51,IC1I,IC2I,IC3I TFLG1 EQU $23 *OC1F,OC2F,OC3F,OC4F;OC5F,IC1F,IC2F,IC3F TMSK2EQU $24 * TOI,RTII,PAOVI,PAII;-,-,PR1,PR0 TFLG2EQU $25 * TOF,RTIF,PAOVF,PAIF;-,-,-,- *** EVB Routine Addresses & Pseudo Vector Equates PVOC2 EQU $00DC EVB Pseudo Vector for OC2 ORG $2000 Start variables in RAM (upper half) HDLY RMB 2 Half-cycle delay (in 0.5mS increments)

TOC2 code (5) TOP5 LDS #$0047 * Top of User’s Stack area on EVB LDAA #$7E * Jump (extended) Opcode STAA PVOC2 * Pseudo Vector see manual text LDX #SV5OC2 * Address of OC2 service routine STX PVOC2+1 * Finish jump instruc to TOF svc LDX #REGBAS * Point to register block LDAA #% * OM2:OL2 = 0:1 STAA TCTL1,X * Set OC2 for toggle, on compare STAA TFLG1,X * Clear any pending,OC2F STAA TMSK1,X * Enable OC2 interrupts CLI * Enable Interrupts BRA * * Interrupt driven; sit here * Try varying hdly

TOC2 code (6) *** * SV5OC2 - Output Compare 2 Interrupt Service Routine (ISR) * * Called at each OC2 interrupt. *** SV5OC2 LDD HDLY * Get delay time for 1/2 cycle ADDD TOC2,X * Add HDLY to last compare value STD TOC2,X * Update OC2 (schedule next edge) BCLR TFLG1,X $BF * Clear OC2F RTI ** Return from OC2 service **

TOC1 Differences TOC1 is the same as TOC2..5 in the way we program the Timer register, interrupts and Flags. TOC1 is different in that it does not use OMx, OLx to control the output pins. i.e. TCNTL2 is used for TOC2..TOC5 only.

TOC1 Output Controls TOC1 has much greater flexibility in that it can control all 5 output pins at once, forcing any combination of outputs high or low - TOC1 OC1M - Output Compare 1 Mask Setting a bit in this mask enables the Data in OC1D to be forced onto the output pin. OC1D - Output Compare 1 Data Data to be forced onto pin

TOC1 Output Control Registers

Time Delay using TOC1 (1) If you base your subroutine, delayms, on the TOC1 timer, then the time delay should be independent of other CPU activity as the TOC timers tick at a uniform rate unaffected by other CPU activity The first time you call delayms, you need to read the value of TCNT, the free running timer counter, then add the delay for the number of milliseconds to delay, write that back to the TOC1 count register, and wait until the TCNT count and TOC1 count matches. At this time TOC1 flag is set

Time Delay using TOC1 (2) * We want a subroutine to provide accurate * time delays: * * usage example: wait 10ms startHere ldd#10 ; # of milliseconds jsrdelayms; delay # of ms swi; return to BUFFALO

Time Delay using TOC1 (3) When the TOC1 count matches TCNT, a flag is set OC1F. If your loop waits for the TOC1 flag to be set then you can stop waiting at this point. The BRCLR instruction can be used here. Eg:brclr TFLG1,#% * Branch if bits in mask are clear to * (branch back to current instruction)

Time Delay using TOC1 (4) msDelayCountequ2000 * Toc1 is at $1016 REGBAS equ $1000 TOC1 equ $16 TMSK1 equ$22 * Timer Interrupt Mask 1 Register * TMSK1 BITS * INTSOC1I OC2I OC3I OC4I OC5I IC1I IC2I IC3I TFLG1equ$23 * * TGFLG1 BITS: * Flags:OC1F OC2F OC3F OC4F OC5F IC1F IC2F IC3F *

Time Delay using TOC1 (5) TCNTequ$0E delayms * Save number of ms delay in D - on stack psha pshb * disable TIC & TOC interrupts, * else this code will not work well at all! ldx#REGBAS ldaa#0 staaTMSK1,x

Time Delay using TOC1 (6) lddTCNT,x addd#(msDelayCount-67) stdTOC1,x * clear the OC1F flag * BIT 7 in TFLG1 register bclrTFLG1,x#% morems * Branch if (bit TFLG1 = 0) to * brclr TFLG1,#% * * wait here whilst the TOC1 flag is not set * when flag is set, drop through to test * for more ms delays...

Time Delay using TOC1 (7) * Get D again pulb pula * Decrement ms delay count subd#1 * is (D == 0) ? beqdoneDelay * Yes, then done delaying * else save D back on stack again, and delay another ms psha pshb

Time Delay using TOC1 (8) lddTOC1,x * add clocks adddmsDelayCount stdTOC1,x * delay another ms bramorems doneDelay rts

Acknowledgments Images of the configuration registers, and some source code examples, are derived from the Motorola M68HC11 Reference Manual 11rm.pdf or 11a8td.pdf