1 68hc11 timer. 2 68hc11 timer subsystem several timing functions: basic timing basic timing real...

16
1 68HC11 Timer 68HC11 Timer

Upload: franklin-wheeler

Post on 19-Jan-2018

220 views

Category:

Documents


1 download

DESCRIPTION

3 Basic Timer

TRANSCRIPT

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

11

68HC11 Timer68HC11 Timer

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

22

68HC11 Timer Subsystem68HC11 Timer SubsystemSeveral timing functions:Several timing functions: Basic timingBasic timing Real time interruptsReal time interrupts Output compareOutput compare Input captureInput capture Computer Operating ProperlyComputer Operating Properly Pulse AccumulatorPulse Accumulator Pulse Width Modulation Pulse Width Modulation

Common FeaturesCommon Features Based on a central timerBased on a central timer Overflow FlagsOverflow Flags Interrupt EnablesInterrupt Enables

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

33

Basic TimerBasic Timer

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

44

Basic Timer– TCNTBasic Timer– TCNT$100E/0E$100E/0E

16-bit free running counter (timer)16-bit free running counter (timer) Cannot be set or stopped. Cannot be set or stopped.

Fclk = system clockFclk = system clockCan be prescaled by 1,4,8, or 16Can be prescaled by 1,4,8, or 16Read only at memory address ($100E/$0E)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 rangeCan use overflow to extend counter’s range Timer Overflow Interrupt Enable Timer Overflow Interrupt Enable

Bit 7 in TMSK ($1024/$24)Bit 7 in TMSK ($1024/$24)

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

55

TCNT - $100E:$100FTCNT - $100E:$100FTimer Counter RegisterTimer Counter Register

7 6 5 4 3 2 1 0

Bits

CNT15

READ ONLY Register

CNT13 CNT12 CNT11 CNT10 CNT9 CNT8CNT14

7 6 5 4 3 2 1 0

CNT7 CNT5 CNT4 CNT3 CNT2 CNT1 CNT0CNT6

$100E

$100F

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

66

PrescalerPrescaler

7 6 5 4 3 2 1 0

Bits

PR2PR1PAII 00PAOVIRTHTOI

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)

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

77

Timer Overflow FlagTimer Overflow Flag

7 6 5 4 3 2 1 0

Bits

00PAIF 00PAOVFRTIFTOF

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

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

88

Timer Overflow InterruptsTimer Overflow Interrupts

7 6 5 4 3 2 1 0

Bits

PR2PR1PAII 00PAOVIRTHTOI

Timer Interrupt Mask Register 2: $1024 (TMSK2)

TOI = Timer overflow interrupt enable 0 = disable interrupt 1 = enable interrupt

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

99

Basic Timer ExampleBasic Timer Example

*************************************************************************************************** Time delay = 1000 X 524.3 ms= 524 s* Time delay = 1000 X 524.3 ms= 524 s**************************************************************************************************

ORG $0200ORG $0200SUBSUB LDX #1000LDX #1000

BSET $24 $03 ; BSET $24 $03 ; PRESCALE = 524.3 msPRESCALE = 524.3 ms

BCLR $24 $80 ; BCLR $24 $80 ; Disable the main timer interruptDisable the main timer interrupt

CONCON BSET $25 $80 : BSET $25 $80 : CLEAR OVERFLOW FLAG START THE TIMERCLEAR OVERFLOW FLAG START THE TIMER

MONMON BRCLR $25 $80 MON ; BRCLR $25 $80 MON ; END OF INTERVAL?END OF INTERVAL?

DEXDEX ; ; NEXT INTERVALNEXT INTERVAL

BNE CONBNE CON ; ; END OF COUNT?END OF COUNT?

RTSRTS ; ; YES, GO BACK TO MAIN PROGRAMYES, GO BACK TO MAIN PROGRAM

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

1010

Basic Timer ExampleBasic Timer ExampleMAX_CNT Calculation MAX_CNT Calculation

Need to wait 1,000,000 or $F4240 clock Need to wait 1,000,000 or $F4240 clock cycles.cycles.Interrupt is generated every 65536 or $10000 Interrupt is generated every 65536 or $10000 clock cyclesclock cyclesMax_CNT = INT(1,000,000 / 65556) = 15.258 ~ 15 = $FMax_CNT = INT(1,000,000 / 65556) = 15.258 ~ 15 = $F Note: INT($F4240/$10000) = $FNote: INT($F4240/$10000) = $F

Set MAX_CNT EQU $FSet MAX_CNT EQU $F

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

1111

Real Time InterruptReal Time Interrupt

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

1212

Real Time InterruptReal Time Interrupt

Similar to Timer Overflow Interrupt exceptSimilar to Timer Overflow Interrupt exceptWe have: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 System Clock is first divided by $1000 then

divided again by the prescale bits given by divided again by the prescale bits given by RTR1 and RTR0 in PACTL ($1026)RTR1 and RTR0 in PACTL ($1026)

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

1313

Real Time Interrupt Real Time Interrupt EnableEnable

7 6 5 4 3 2 1 0

Bits

PR2PR1PAII 00PAOVIRTIITOI

Timer Interrupt Mask Register 2: $1024 (TMSK2)

RTII = Real Time Interrupt Enable 0 = disable interrupt 1 = enable interrupt

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

1414

Real Time Interrupt FlagReal Time Interrupt Flag

7 6 5 4 3 2 1 0

Bits

00PAIF 00PAOVFRTIFTOF

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

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

1515

Real Time InterruptReal Time InterruptPrescalePrescale

7 6 5 4 3 2 1 0

Bits

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

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

1616

Basic Timer ExampleBasic Timer Example

*************************************************************************************************** Time delay = 2000 X 32.77 ms= 65 s* Time delay = 2000 X 32.77 ms= 65 s**************************************************************************************************

ORG $0200ORG $0200SUBSUB LDX #2000LDX #2000

BSET $26 $03 ; BSET $26 $03 ; PRESCALE = 32.77 msPRESCALE = 32.77 ms

BCLR $24 $40; BCLR $24 $40; Disable the RTI TIMER interruptDisable the RTI TIMER interrupt

CONCON BSET $25 $40 : BSET $25 $40 : CLEAR OVERFLOW FLAG START THE TIMERCLEAR OVERFLOW FLAG START THE TIMER

MONMON BRCLR $25 $40 MON ; BRCLR $25 $40 MON ; END OF INTERVAL?END OF INTERVAL?

DEXDEX ; ; NEXT INTERVALNEXT INTERVAL

BNE CONBNE CON ; ; END OF COUNT?END OF COUNT?

RTSRTS ; ; YES, GO BACK TO MAIN PROGRAMYES, GO BACK TO MAIN PROGRAM