ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System

Slides:



Advertisements
Similar presentations
More fun with Timer/Counters
Advertisements

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,
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
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.
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.
Interrupts and reset operations. Overview  Introduction to interrupts – What are they – How are they used  68HC11 interrupt mechanisms – Types of interrupts.
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.
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.
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 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.
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.
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
Timers and Scheduled Interrupts
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
HCS12 Exceptions Maskable Interrupts
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.
UNIT – Microcontroller.
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
Interrupts, Counter and Timers
AVR Addressing Modes Subject: Microcontoller & Interfacing
8085 Microprocessor Architecture
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.
Timer/Counter Modified from Dr. Lam Phung’s Slides.
Timer.
Programmable Interval timer 8253 / 8254
8-bit Timer/Counter2 with PWM and Asynchronous Operation
8085 Microprocessor Architecture
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
Programmable Interval timer 8253 / 8254
8051 Micro Controller.
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
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 18 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 = 2000-29 3 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 - $1024 - PR0/PR1/RTI OPTION - $1039 - 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 = 2..5 0 0 No Change 0 1 Toggle Pin state 1 0 Force Pin to 0 1 1 Force Pin to 1

TOC2 code (4) REGBAS EQU $1000 * Starting address for register block PORTB EQU $04 * Output port B TCNT EQU $0E * Free running counter (16 bit) TOC2 EQU $18 * OC2 register (16 bit) TCTL1 EQU $20 * OM2,OL2,OM3,OL3;OM4,OL4,OM5,OL5 TCTL2 EQU $21 * -,-,EDGlB,EDGlA,EDG2B,EDG2A,EDG3B, * EDG3A TMSK1 EQU $22 * OC1I,OC2I,OC3I,OC4I;OC51,IC1I,IC2I,IC3I TFLG1 EQU $23 *OC1F,OC2F,OC3F,OC4F;OC5F,IC1F,IC2F,IC3F TMSK2 EQU $24 * TOI,RTII,PAOVI,PAII;-,-,PR1,PR0 TFLG2 EQU $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 #%01000000 * 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 jsr delayms ; 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,X #%10000000 * Branch if bits in mask are clear to * (branch back to current instruction)

Time Delay using TOC1 (4) msDelayCount equ 2000 * Toc1 is at $1016 REGBAS equ $1000 TOC1 equ $16 TMSK1 equ $22 * Timer Interrupt Mask 1 Register * TMSK1 BITS 7 6 5 4 3 2 1 0 * INTS OC1I OC2I OC3I OC4I OC5I IC1I IC2I IC3I TFLG1 equ $23 * * TGFLG1 BITS: 7 6 5 4 3 2 1 0 * Flags: OC1F OC2F OC3F OC4F OC5F IC1F IC2F IC3F

Time Delay using TOC1 (5) TCNT equ $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 staa TMSK1,x

Time Delay using TOC1 (6) ldd TCNT,x addd #(msDelayCount-67) std TOC1,x * clear the OC1F flag * BIT 7 in TFLG1 register bclr TFLG1,x #%01111111 morems * Branch if (bit TFLG1 = 0) to * brclr TFLG1,x #%10000000 * * 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) ? beq doneDelay * Yes, then done delaying * else save D back on stack again, and delay another ms psha pshb

Time Delay using TOC1 (8) ldd TOC1,x * add 20000 clocks addd msDelayCount std TOC1,x * delay another ms bra morems 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