ECE 3430 – Intro to Microcomputer Systems

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
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
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.
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.
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.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
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.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
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 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
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.
INSTITUTE: INSTITUTE:PARUL INSTITUTE OF TECHNOLOGY BRANCH : BRANCH :B.E. E.C.5 TH SEM. SUBJECT:MICROCONTROLLER & INTERFACING TOPIC:AVR INTTRUPT TOPIC:AVR.
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
V.V.P. ENGINEERING COLLEGE,RAJKOT
ECE 3430 – Intro to Microcomputer Systems
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.
ECE 3430 – Intro to Microcomputer Systems
Timer and Interrupts.
BITS EDU. CAMPUS , VARNAMA
ECE 3430 – Intro to Microcomputer Systems
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
ECE 3430 – Intro to Microcomputer Systems
Programmable Interval Timer
Programmable Interval Timer 8254 LECTURE 3
AVR Addressing Modes Subject: Microcontoller & Interfacing
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
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.
8-bit Timer/Counter0 with PWM
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Programmable Interval timer 8253 / 8254
8-bit Timer/Counter2 with PWM and Asynchronous Operation
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Programmable Interval timer 8253 / 8254
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
ECE 3430 – Intro to Microcomputer Systems
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.
ECE 3430 – Intro to Microcomputer Systems
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Presentation transcript:

ECE 3430 – Intro to Microcomputer Systems ECE 3430 – Introduction to Microcomputer Systems University of Colorado at Colorado Springs Lecture #17 Agenda Today Output Compare Forced Output Compare HC11 Timer Review Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function - Sometimes it is desirable for a microcontroller to generate a precisely-timed digital waveform. Programmatically driving a waveform by repeatedly forcing a bit high and low will not yield a digital waveform with good integrity! - Some microcontrollers provide a feature called output compare which can be used to more accurately produce digital waveforms. - The HC11 (D3) provides 5 output compare channels. - Each channel has a dedicated 16-bit output compare register. - A 16-bit value is loaded into the output compare registers. When TCNT is equal to this value, an internal event is triggered. - When this internal event is triggered the output compare circuitry will alter the value on an output pin. These output pins are shared with port A (each channel has a dedicated output pin): OC1 = PA7 (bi-directional, need to set to OUTPUT if using, shared with PAI) OC2 = PA6 OC3 = PA5 OC4 = PA4 OC5 = PA3 (bi-directional, need to set to OUTPUT if using, shared with IC4) - In the HC11 (D3), OC1 operates a little differently than the others (OC2-5). OC1 can control any or all of PA7-PA3. But only OC1 has access to PA7. Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Output Compare Details - When the output compare generates an internal event (when OC register and TCNT match), the OCx pins in the TCTL1 register ($0020) specify what to do to the respective output pin: 1) Drive the output pin to logic 1 2) Drive the output pin to logic 0 3) Toggle state of output pin (0  1 or 1  0) OMx OLx 0 0 Timer disconnected from output pin logic 0 1 Toggle OCx output drive level 1 0 OCx output drive level to zero 1 1 OCx output drive level to one NOTE: OC1 uses OC1D and OC1M control registers instead. OM2 OL2 OM3 OL3 OM4 OL4 OM5 OL5 7 6 5 4 3 2 1 0 Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Output Compare Details - The 16-bit output compare registers for each of the 5 output compare channels are located at: TOC1 = {$0016 : $0017} TOC2 = {$0018 : $0019} TOC3 = {$001A : $001B} TOC4 = {$001C : $001D} TI4O5 = {$001E : $001F} - The last register is used for either input capture or output compare—hence the weird register name. Theory of how we use output compare Ex) Generate a ‘1’ on PA6 256 cycles from NOW!!! Assume PA6 is currently ‘0’. - Set up OC channel 2 to set output pin on successful compare and enable. - Load TCNT into ACCD (LDD TCNT) - Add 256 to it (ADDD #256) - Store that value to TOC2 (STD TOC2) - When TCNT reaches that value, it will trigger an output compare internal event. Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Output Compare Details FLAGS - When the output compare internal event occurs, a flag is set in the TFLG1 register ($0023): OC1F, OC2F, OC3F, OC4F, I4O5F OCxF = 0 = waiting for successful compare (RESET state) OCxF = 1 = TCNT and TOCx registers successfully compared - When a successful compare occurs, the respective flag is set. To use that flag again, you must clear it by writing a ‘1’ to the proper bit. - Remember: The hardware sets the flag bit when TCNT and TOCx are equal. Software has the responsibility of clearing that flag. Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Output Compare Details (Optional Interrupts) - Just like virtually all of the other on-chip peripheral devices, the output compare system can generate an interrupt when TCNT and the TOCx registers are equal. - Each output compare channel has a relative priority. Output compare channel 1 has a higher priority than any of the other output compare channels. It has a global and local interrupt enable: Global mask = I-bit in CCR (another maskable interrupt) Local mask = OCxI bits in the TMSK1 register ($0022) OCxI = 0 = Disabled (RESET State) OCxI = 1 = Enabled - When a particular output compare channel is turned on, it is disconnected from the normal output pin control logic. Hence, once you turn on the output compare for a channel, the respective pin can only be changed by the hardware (writing a value to the pin by storing to a port register will have no effect)! Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Output Compare Applications Generate Square Waves - A square wave with a pre-defined duty cycle and frequency (period) can be generated. Useful in PWM control (motors). Generate Fixed Delay after Event - When an event occurs, we can trigger a specific # of TCNT’s after the event. Could also be an accurate delay subroutine. Generate a Pulse with a Certain Width - Trigger two ‘toggle’ output compares a certain  TCNT between edges. Event Output Compare  TCNT  Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Output Compare Example Generate a square wave with a pulse width equal to TCNT rollover on PA6 (OC2) TMSK1 EQU $22 OC2I EQU %01000000 ; OC2 local interrupt enable (bit 6) TFLG1 EQU $23 OC2F EQU %10111111 ; OC2 flag (bit 6) TCTL1 EQU $20 TOC2 EQU $18 ; OC2 compare register ORG $FFE6 ; initialize TOC2 Vector Table FDB OC2_ISR ORG $FFFE ; initialize RESET Vector Table FDB $E000 Roll Over Roll Over Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Output Compare Example Cont… ORG $E000 SEI ; disable maskable interrupts during setup LDS #$00FF ; initialize stack pointer BSET TMSK1 OC2I ; enable local IRQ mask for OC2 BCLR TFLG1 OC2F ; clear the OC2 Flag LDAA TCTL1 ; set the OC2 function to toggle ORAA #%01000000 ANDA #%01111111 STAA TCTL1 LDX #$5555 ; initialize TOC2 to $5555 STX TOC2 ; every time TCNT = $5555, OC2 generates event CLI ; enable maskable interrupts, we are now ready MAIN: BRA MAIN ; the main loop doesn’t do anything with OC2 * On each interrupt, PA6 will toggle state OC2_ISR: BCLR TFLG1 OC2F ; all we need to do is clear the OC2 flag RTI ; so the next interrupt will fire Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Timer Output Compare Function Forced Output Compare - We can “force” an output compare function at anytime—even if TCNT and the TOCx register don’t match. - By writing to the CFORC register ($000B), we can specify which output compare to trigger. - Writing a 1 forces a compare. Register is set to zero on reset. - We would use this if we wanted to insert aperiodic edges in addition to our periodic edges. - Also since we cannot re-initialize the state of the outputs once the output compare system is engaged, we might use a forced compare to re-initialize the output pin state without disengaging the output compare logic (which could induce glitches). FOC1 FOC2 FOC3 FOC4 FOC5 7 6 5 4 3 Forced Periodic Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Timer Review HC11 Timers Main Timer - A 16-bit free-running, read-only counter that runs off of the E-clock. It can trigger an interrupt upon overflow ($FFFF-$0000). The speed of the counter can be clocked down by a factor of 4, 8, or 16. Input Capture – Used to capture external events via dedicated input pins. When the event occurs, the value of TCNT is loaded into a pre-defined register. This is then used to calculate relative timing information between events. This can also cause an interrupt. Output Compare - Compare registers are loaded with a 16-bit values. When TCNT reaches the value in the register, an output compare trigger will occur. Upon the compare event, output pins on the HC11 can be altered. This can also cause an interrupt. Forced Output Compare - At any time, software can force any of the output compare functions to trigger by writing to the CFORC register. Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Timer Review HC11 Timers Real Time Interrupts – A sub-system independent from the 16-bit free-running counter (TCNT) but derived from the E-clock. It can be programmed to generate periodic internal interrupts. Used to provide a semi-accurate time base for software and hardware. This is similar to the “Main Timer Overflow Interrupts” but generates quicker interrupts. Pulse Accumulator - A counter that can be incremented upon an event on a dedicated input pin or a counter that is incremented by E-clock/64 where the counter is gated by an input pin. Lecture #17 ECE 3430 – Intro to Microcomputer Systems Fall 2009