1 68HC11 Timer Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.

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.
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 Chapter 10 9S12DP256. Timers The 9S12DP256 Programmable Timer Output Compares Pulse Train Using Interrupts Input Capture Measuring the Period of.
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.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Timers ME4447 INTRODUCTION TO MECHATRONICS Anthony Wingo Carlos Alzate Jim Kitchen.
NS Training Hardware. System Controller Module.
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.
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
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.
8254 Counter/Timer Counter Each of the three counter has 3 pins associated CLK: input clock frequency- 8 MHz OUT GATE: Enable (high) or disable.
Timer/counter Chapter 12
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
Chapter 4 TIMER OPERATION
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.
Timers.
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.
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.
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.
8254 Timer.
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.
#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)
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
EET 2261 Unit 13 Enhanced Capture Timer
16F877A.
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
Timer and Interrupts.
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
Programmable Interval Timer
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.
8254 Timer and Counter (8254 IC).
ECE 3430 – Intro to Microcomputer Systems
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
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.
MCO556 Timer System Exercise.
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Presentation transcript:

1 68HC11 Timer Chapter 10

2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare Output compare Input capture Input capture Computer Operating Properly Computer Operating Properly Pulse Accumulator Pulse Accumulator Pulse Width Modulation Pulse Width Modulation Common Features Based on a central timer Based on a central timer Overflow Flags Overflow Flags Interrupt Enables Interrupt Enables

3 Timer System Block Diagram

4 Basic Timer

5 Basic Timer– TCNT $100E 16-bit free running counter (timer) Cannot be set or stopped. Cannot be set or stopped. Fclk = system clock Can be prescaled by 1,4,8, or 16 Read only at memory address ($100E) Overflow flag is bit 7 in TFLG2 ($1025) Overflow flag is bit 7 in TFLG2 ($1025) Can use overflow to extend counter’s range Timer Overflow Interrupt Enable Timer Overflow Interrupt Enable Bit 7 in TMSK ($1024)

6 TCNT - $100E:$100F Timer Counter Register Bits CNT15 READ ONLY Register CNT13CNT12CNT11CNT10CNT9CNT8 CNT CNT7 CNT5CNT4CNT3CNT2CNT1CNT0 CNT6 $100E $100F

7 Prescaler Bits PR2 PR1PAII00PAOVIRTHTOI Timer Interrupt Mask Register 2: $ TFLG2 PR1,PR0 = Timer prescale select - Timer Clock = System Clock / Prescale Factor Pr1 Pr0 Prescale Factor

8 Timer Overflow Flag Bits 0 0PAIF00PAOVFRTIFTOF Miscellaneous Timer Interrupt Flag Register 2: $1025 (TFLG2) TOF = Timer overflow flag - 0 = No overflow 1 = Overflow TOF is reset to 0 by writing ‘1’ to TOF

9 Timer Overflow Interrupts Bits PR2 PR1PAII00PAOVIRTHTOI Timer Interrupt Mask Register 2: $1024 (TMSK2) TOI = Timer overflow interrupt enable 0 = disable interrupt 1 = enable interrupt

10 Basic Timer Example Problem: Write an ISR to read the input from PortC and write it to PortB approximately every 1,000,000 clock cycles. Assume timer prescale = 1

11 Basic Timer Example Main Program Configure Timer Overflow Interrupt TMSK2(7)  ‘1’ TMSK2(7)  ‘1’ Enable Interrupts (CLI) Repeat Until Forever Set Timer Overflow Interrupt Vector ORG TOI_VECTOR ($FFDE:FFDF) ORG TOI_VECTOR ($FFDE:FFDF) FDB TO_ISR FDB TO_ISR

12 Basic Timer Example TO_ISR Disable Interrupts SEI SEI Turn-off Interrupt Request TOF  ‘1’ TOF  ‘1’ CNT = CNT + 1 IF CNT = MAX_CNT then CNT = 0 CNT = 0 A  PORTC A  PORTC PORTB  A PORTB  A END IF Return from Interrupt

13 Basic Timer Example MAX_CNT Calculation Need to wait 1,000,000 or $F4240 clock cycles. Interrupt is generated every or $10000 clock cycles Max_CNT = INT(1,000,000 / 65556) = ~ 15 = $F Note: INT($F4240/$10000) = $F Note: INT($F4240/$10000) = $F Set MAX_CNT EQU $F

14 Real Time Interrupt

15 Real Time Interrupt Similar to Timer Overflow Interrupt except We have: RTI Flag (RTIF) – Bit 6 in TFLG2 ($1025) RTI Flag (RTIF) – Bit 6 in TFLG2 ($1025) RTI Enable (RTII) – Bit 6 in TMSK2 ($1024) RTI Enable (RTII) – Bit 6 in TMSK2 ($1024) System Clock is first divided by $1000 then divided again by the prescale bits given by RTR1 and RTR0 in PACTL ($1026) System Clock is first divided by $1000 then divided again by the prescale bits given by RTR1 and RTR0 in PACTL ($1026)

16 Real Time Interrupt Enable Bits PR2 PR1PAII00PAOVIRTIITOI Timer Interrupt Mask Register 2: $1024 (TMSK2) RTII = Real Time Interrupt Enable 0 = disable interrupt 1 = enable interrupt

17 Real Time Interrupt Flag Bits 0 0PAIF00PAOVFRTIFTOF Miscellaneous Timer Interrupt Flag Register 2: $1025 (TFLG2) RTIF = Real Time Interrupt flag - 1 = RTI has occurred RTIF is reset to 0 by writing ‘1’ to RTIF

18 Real Time Interrupt Prescale Bits RTR0RTR1 PEDGEPAMODPAEN6DDRA7 00 RTR1, RTR0= Real Time Interrupt Prescale RTR1 RTR0 Nominal RTI rate (2MHz E-Clock) ms ms ms ms Port A Control Register: $1026 (PACTL)

19 TPS Quiz

20 Computer Operating Properly COP

21 Computer Operating Properly COP Also known as a “watchdog” timer When enabled, your program must set the COP timer and reset the COP timer prior to the COP’s “time-out” delay. This time-out delay is programmable. When enabled, your program must set the COP timer and reset the COP timer prior to the COP’s “time-out” delay. This time-out delay is programmable. If the program does not set or reset the COP timer before the “time-out”, a COP failure interrupt is generated and the ISR assigned to the interrupt is executed. If the program does not set or reset the COP timer before the “time-out”, a COP failure interrupt is generated and the ISR assigned to the interrupt is executed.

22 Computer Operating Properly COP Usage Design your program to set and reset the COP before time-out. Design your program to set and reset the COP before time-out. If your program enters an infinite loop, the COP timer will “time-out” automatically causing a COP failure interrupt. If your program enters an infinite loop, the COP timer will “time-out” automatically causing a COP failure interrupt. Use the COP failure ISR to place your system into a “safe” mode or restart mode. Use the COP failure ISR to place your system into a “safe” mode or restart mode.

23 Output Compare

24 Timer Output Compare Using the timer overflow flag or interrupt will generate a count every clock cycles. Given a 2MHz clock, this gives a sample resolution of 32.8ms The timer output compare feature allows for more precise timing.

25 Timer Output Compare There are five output compare registers Each with a separate Compare Counter Compare Counter Interrupt Mask Interrupt Mask Overflow Flag Overflow Flag

26 TOC1 – TOC5 Timer Output Compare Registers Bits OCn15 TOC1 - $1016:$1017 TOC2 - $1018:$1019 TOC3 - $101A:$101B OCn13OCn12OCn11OCn10OCn9OCn8 OCn OCn7 OCn5OCn4OCn3OCn2OCn1OCn0 OCn6 TOC4 - $101C:$101D TOC5 - $101E:$101F

27 Output Compare Flags Bits IC3F IC2FOC4FIC1FOC5FOC3FOC2FOC1F Main Timer Interrupt Flag Register 1: $1023 (TFGL1 ) OC1F-OC5F = Output Compare Flags 1 = when output compare register equals TCNT 0 = reset by writing ‘1’ to bit position

28 Output Compare Interrupts Bits IC3I IC2IOC4IIC1IOC5IOC3IOC2IOC1I Main Timer Interrupt Mask Register 1: $1022 (TMSK1) OC1I-OC5I = Output Compare interrupt enable 0 = disable interrupt 1 = enable interrupt

29 Output Compare Example Problem: Write an ISR to read the input from PortC and write it to PortB approximately every 10,000 clock cycles. Assume timer prescale = 1 Note: 10,000 cycles is less than one timer overflow!!

30 Output Compare Example Main Program A  TCNT ; Load current count TOC1  A ; Add to current count Configure Output Compare 1 Interrupt Configure Output Compare 1 Interrupt TMSK1(7)  ‘1’ TMSK1(7)  ‘1’ Enable Interrupts (CLI) Repeat Until Forever Set Output Compare 1 Interrupt Vector ORG OC1_VECTOR ($FFE8:FFE9) ORG OC1_VECTOR ($FFE8:FFE9) FDB OC1_ISR FDB OC1_ISR

31 Output Compare Example OC1_ISR Disable Interrupts SEI SEI Turn-off Interrupt Request OC1F  ‘1’ OC1F  ‘1’ A  PORTC PORTB  A A  TCNT ; Load current count TOC1  A ; update TOC1 for next interrupt interrupt Return from Interrupt

32 Input Capture

33 Timer Input Capture 16-bit TCIx Latch Det Ckt TCNT clk Ext Signal When the Ext Signal is detected on pin PAx, the current value of the free running counte TCNT is latched into the timer input capture latch. This value can be read and saved to determine the time between events. PAx

34 Timer Input Capture The timer input capture feature can be used to time external events Three input capture registers TIC1 : $1010:$1011 TIC1 : $1010:$1011 TIC2 : $1012:$1013 TIC2 : $1012:$1013 TIC3: $1014:$1015 TIC3: $1014:$1015 Maximum time between events must be less than cycles

35 TIC1 – TIC3 Timer Input Capture Registers Bits ICn15 TIC1 - $1010:$1011 TIC2 - $1012:$1013 TIC3 - $1014:$1015 ICn13ICn12ICn11ICn10ICn9ICn8 ICn ICn7 ICn5ICn4ICn3ICn2ICn1ICn0 ICn6

36 Input Compare Interrupts Bits IC3I IC2IOC4IIC1IOC5IOC3IOC2IOC1I Main Timer Interrupt Mask Register 1: $1022 (TMSK1) IC1I-IC3I = Input Compare interrupt enable 0 = disable interrupt 1 = enable interrupt

37 Interrupt Capture Flags Bits IC3F IC2FOC4FIC1FOC5FOC3FOC2FOC1F Main Timer Interrupt Flag Register 1: $1023 (TFGL1 ) IC1F-IC3F = Interrupt Capture Flags 1 = when selcted edge is detected 0 = reset by writing ‘1’ to bit position

38 Timer Control Register 2 TCTL2 - $ Bits EDG1BEDG1AEDG2BEDG2AEDG3BEDG3A00 EDGnB EDGnA Configuration 0 0 Disabled 0 1 Rising Edge 1 0 Falling Edge 1 1 Either Edge

39 Pulse Accumulator

40 Pulse Accumulator The pulse accumulator can be used as an event counter. That is, it can count the number of external events. Note: difference to Timer Input Capture which counts the time between external events. Configuration: PACTL ($1026) is used to configure PA PACTL ($1026) is used to configure PA PACNT ($1027) is the PA Count Register PACNT ($1027) is the PA Count Register Two Modes: Event Counting: PA7 is External Clock Event Counting: PA7 is External Clock Gated Time Accumulation: PA7 is enable to system clock divided by 64 Gated Time Accumulation: PA7 is enable to system clock divided by 64

41 PACTL: $1026 Port A Control Register Bits RTR0RTR1 PEDGEPAMODPAEN6DDRA7 00 PAEN6 = Pulse Accumulator System Enable 0 = Disable (Default) Port A is set for I/O function 1 = Enable Port A is set for Pulse Accumulator function PAMOD= Pulse accumulator mode 0 = Event counter (Default) 1 = Gated time accumulation

42 PACTL: $1026 Port A Control Register Bits RTR0RTR1 PEDGEPAMODPAEN6DDRA7 00 PEDGE= Pulse Accumulator Edge Select 0 = Falling Edge (in event mode) – Active High (in gated mode) 1 = Rising Edge (in event mode) – Active Low (in gated mode)

43 Pulse Accumulator Flag Bits 0 0PAIF00PAOVFRTIFTOF Miscellaneous Timer Interrupt Flag Register 2: $1025 (TFLG2) PAOVF = Pulse Accumulator Overflow Flag 1 = Overflow has occurred PAOVF is reset to 0 by writing ‘1’ to PAOVF PAIF = Pulse Accumulator Input Edge Flag 1 = Input edge has been detected PAIF is reset to 0 by writing ‘1’ to PAIF

44 Pulse Accumulator Interrupts Bits PR2 PR1PAII00PAOVIRTIITOI Timer Interrupt Mask Register 2: $1024 (TMSK2) PAOVI = Pulse Accumulator overflow interrupt enable 0 = disable interrupt 1 = enable interrupt PAII = Pulse Accumulator input edge interrupt enable 0 = disable interrupt 1 = enable interrupt

45 Pulse Width Modulation

46 Pulse Width Modulation Some versions of 68HC11 have a pulse width modulation (PWM) module which can be used to generate periodic output waveforms with a specific period and duty cycle (i.e. the percentage of time the signal is high compare to when it is low).

47 Timer Summary Timer subsystem – most complex in 68HC11 Based on free running timer Timings available: Basic timing Basic timing Real time interrupts Real time interrupts Output compare Output compare Input capture Input capture Computer Operating Properly Computer Operating Properly Pulse Accumulator Pulse Accumulator Pulse Width Modulation Pulse Width Modulation Overflow flags and/or Interrupts are available