Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare."— Presentation transcript:

1 1 68HC11 Timer

2 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 3 Basic Timer

4 4 Basic Timer– TCNT $100E/0E 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/$0E) Overflow flag is bit 7 in TFLG2 ($1025/$25) Overflow flag is bit 7 in TFLG2 ($1025/$25) Can use overflow to extend counter’s range Timer Overflow Interrupt Enable Timer Overflow Interrupt Enable Bit 7 in TMSK ($1024/$24)

5 5 TCNT - $100E:$100F Timer Counter Register 76543210 Bits CNT15 READ ONLY Register CNT13CNT12CNT11CNT10CNT9CNT8 CNT14 76543210 CNT7 CNT5CNT4CNT3CNT2CNT1CNT0 CNT6 $100E $100F

6 6 Prescaler 76543210 Bits PR2 PR1PAII00PAOVIRTHTOI Timer Interrupt Mask Register 2: $1024/24 -- TFLG2 PR1,PR0 = Timer prescale select - Timer Clock = System Clock / Prescale Factor Pr1 Pr0 Prescaler Timer count (overflow period) 0 0 1 E/1 (32.77 ms) 0 1 2 E/4 (131.1 ms) 1 0 8 E/8 (262.1 ms) 1 1 16 E/16 (524.3 ms)

7 7 Timer Overflow Flag 76543210 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

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

9 9 Basic Timer Example ************************************************* * Time delay = 1000 X 524.3 ms= 524 s ************************************************* ORG $0200 SUBLDX #1000 BSET $24 $03 ; PRESCALE = 524.3 ms BCLR $24 $80 ; Disable the main timer interrupt CONBSET $25 $80 : CLEAR OVERFLOW FLAG START THE TIMER MONBRCLR $25 $80 MON ; END OF INTERVAL? DEX ; NEXT INTERVAL BNE CON ; END OF COUNT? RTS ; YES, GO BACK TO MAIN PROGRAM

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

11 11 Real Time Interrupt

12 12 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)

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

14 14 Real Time Interrupt Flag 76543210 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

15 15 Real Time Interrupt Prescale 76543210 Bits RTR0RTR1 PEDGEPAMODPAEN6DDRA7 00 RTR1, RTR0= Real Time Interrupt Prescale RTR1 RTR0 Nominal RTI rate (2MHz E-Clock) 0 0 4.096ms 0 1 8.192ms 1 0 16.384ms 1 1 32.768ms Port A Control Register: $1026 (PACTL)

16 16 Basic Timer Example ************************************************* * Time delay = 2000 X 32.77 ms= 65 s ************************************************* ORG $0200 SUBLDX #2000 BSET $26 $03 ; PRESCALE = 32.77 ms BCLR $24 $40; Disable the RTI TIMER interrupt CONBSET $25 $40 : CLEAR OVERFLOW FLAG START THE TIMER MONBRCLR $25 $40 MON ; END OF INTERVAL? DEX ; NEXT INTERVAL BNE CON ; END OF COUNT? RTS ; YES, GO BACK TO MAIN PROGRAM


Download ppt "1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare."

Similar presentations


Ads by Google