1 68hc11 timer hc11 or hc12: chapter 10. 2 68hc11 timer subsystem several timing functions: basic...
TRANSCRIPT
![Page 1: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/1.jpg)
11
68HC11 Timer68HC11 Timer
HC11 or HC12: Chapter 10HC11 or HC12: Chapter 10
![Page 2: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/2.jpg)
22
68HC11 Timer Subsystem68HC11 Timer Subsystem Several 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 HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/3.jpg)
33
Timer Timer System System Block Block
DiagramDiagram
Reference Manualp. 370
![Page 4: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/4.jpg)
44
Basic TimerBasic Timer
![Page 5: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/5.jpg)
55
Basic Timer– TCNTBasic Timer– TCNT$100E$100E
16-bit free running counter (timer)16-bit free running counter (timer) Cannot be set or stopped. Cannot be set or stopped.
E-clk = bus clock = ¼ XTAL Clock (crystal)E-clk = bus clock = ¼ XTAL Clock (crystal)Can be prescaled by 1,4,8, or 16Can be prescaled by 1,4,8, or 16Read only at memory address $100E:100FRead only at memory address $100E:100F
Overflow flag is bit 7 in TFLG2 ($1025)Overflow flag is bit 7 in TFLG2 ($1025)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)Bit 7 in TMSK ($1024)
![Page 6: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/6.jpg)
66
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 7: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/7.jpg)
77
PrescalerPrescaler
7 6 5 4 3 2 1 0
Bits
PR0PR1PAII 00PAOVIRTHTOI
Timer Interrupt Mask Register 2: $1024 -- TMSK2
PR1,PR0 = Timer prescale select Timer Clock = E-Clock / Prescale Factor
PR1 PR0 Prescale Factor 0 0 1 0 1 2 1 0 4 1 1 16
Notes: 1.) Unlike HC12, HC11 Prescaler must be set with 64 clock cycles of RESET
2.) The Buffalo Monitor initializes the prescaler to 1 on our lab boards
![Page 8: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/8.jpg)
88
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 9: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/9.jpg)
99
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 10: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/10.jpg)
1010
Basic Timer ExampleBasic Timer ExampleProblem: Write an ISR to read the input from Problem: Write an ISR to read the input from
PortC and write it to PortB approximately PortC and write it to PortB approximately every 1,000,000 clock cycles. Assume timer every 1,000,000 clock cycles. Assume timer prescale = 1prescale = 1
![Page 11: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/11.jpg)
1111
Basic Timer ExampleBasic Timer ExampleMain ProgramMain Program
Set Timer Overflow Interrupt VectorSet Timer Overflow Interrupt Vector ORG TOI_VECTOR ($FFDE:FFDF)ORG TOI_VECTOR ($FFDE:FFDF) FDB TO_ISRFDB TO_ISR
Configure Timer Overflow InterruptConfigure Timer Overflow Interrupt TMSK2(7) TMSK2(7) ‘1’ ‘1’
Enable Interrupts (CLI)Enable Interrupts (CLI)Wait for interruptsWait for interrupts
![Page 12: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/12.jpg)
1212
Basic Timer ExampleBasic Timer ExampleTO_ISRTO_ISR
Disable Interrupts Disable Interrupts SEISEI
Turn-off Interrupt RequestTurn-off Interrupt Request TOF TOF ‘1’ ‘1’
CNT = CNT + 1CNT = CNT + 1 IF CNT = MAX_CNT thenIF CNT = MAX_CNT then
CNT = 0CNT = 0 A A PORTC PORTC PORTB PORTB A A
END IFEND IF Return from InterruptReturn from Interrupt
![Page 13: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/13.jpg)
1313
Basic Timer ExampleBasic Timer ExampleMAX_CNT Calculation MAX_CNT Calculation
Need to wait 1,000,000 (or $F4240) E-clock Need to wait 1,000,000 (or $F4240) E-clock cycles.cycles.
Interrupt is generated every 65536 or $10000 Interrupt is generated every 65536 or $10000 clock cyclesclock cycles
Max_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 14: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/14.jpg)
1414
In-Class AssignmentIn-Class Assignment
The evaluation board used in lab uses and 8 MHz The evaluation board used in lab uses and 8 MHz crystal to set the XTAL clock frequencycrystal to set the XTAL clock frequency
The Buffalo ROM Monitor sets the prescale to 1 (PR1, The Buffalo ROM Monitor sets the prescale to 1 (PR1, PR0 = 0, 0)PR0 = 0, 0)
1.1. Determine the frequency of the E-ClockDetermine the frequency of the E-Clock2.2. Determine the time period between timer overflow Determine the time period between timer overflow
interrupts (TOI)interrupts (TOI)3.3. If the previous example was implemented on the lab If the previous example was implemented on the lab
board, what would the time interval (in seconds) board, what would the time interval (in seconds) between successive transfers from Port C to Port B?between successive transfers from Port C to Port B?
![Page 15: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/15.jpg)
1515
Real Time InterruptReal Time Interrupt
![Page 16: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/16.jpg)
1616
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 E-Clock is first divided by $2000 System E-Clock is first divided by $2000
(8192(81921010) using a 13-bit clock, and then ) using a 13-bit clock, and 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)
RTR1 and RTR2 can be set RTR1 and RTR2 can be set anytimeanytime in the in the programprogram
![Page 17: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/17.jpg)
1717
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 18: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/18.jpg)
1818
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 19: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/19.jpg)
1919
Real Time InterruptReal Time InterruptPrescalePrescale
7 6 5 4 3 2 1 0
Bits
RTR0RTR1PEDGEPAMODPAEN6DDRA7 00
RTR1, RTR0= Real Time Interrupt Prescale
RTR1 RTR0 Prescale Value Nominal RTI period (2MHz E-Clock) 0 0 1 4.096 ms 0 1 2 8.192 ms 1 0 4 16.384 ms 1 1 8 32.768 ms
Port A Control Register: $1026 (PACTL)
![Page 20: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/20.jpg)
2020
In-Class AssignmentIn-Class Assignment
Get with a partner to complete the following tasks:Get with a partner to complete the following tasks:
1.1. Explain the difference between the RTI and the Explain the difference between the RTI and the basic Timer Overflow.basic Timer Overflow.
2.2. Assume an E-clock of 1 MHz. Determine the Assume an E-clock of 1 MHz. Determine the values needed for RTR1 and RTR0 to provide a values needed for RTR1 and RTR0 to provide a RTI as close as possible to 10 msRTI as close as possible to 10 ms
![Page 21: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/21.jpg)
2121
Computer Operating Computer Operating ProperlyProperly
COPCOP
![Page 22: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/22.jpg)
2222
Computer Operating ProperlyComputer Operating ProperlyCOPCOP
Also known as a “watchdog” timerAlso known as a “watchdog” timer When enabled, your program must set the When enabled, your program must set the
COP timer and reset the COP timer COP timer and reset the COP timer priorprior to to the COP’s “time-out” delay. This time-out the COP’s “time-out” delay. This time-out delay is programmable.delay is programmable.
If the program does not set or reset the COP If the program does not set or reset the COP timer timer beforebefore the “time-out”, a COP failure the “time-out”, a COP failure interrupt is generated and the ISR assigned to interrupt is generated and the ISR assigned to the interrupt is executed. the interrupt is executed.
![Page 23: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/23.jpg)
2323
Computer Operating ProperlyComputer Operating ProperlyCOPCOP
UsageUsage Design your program to set and reset the Design your program to set and reset the
COP before time-out.COP before time-out. If your program enters an infinite loop, the If your program enters an infinite loop, the
COP timer will “time-out” automatically COP timer will “time-out” automatically causing a COP failure interrupt. causing a COP failure interrupt.
Use the COP failure ISR to place your system Use the COP failure ISR to place your system into a “safe” mode or restart mode. into a “safe” mode or restart mode.
![Page 24: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/24.jpg)
2424
Output CompareOutput Compare
![Page 25: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/25.jpg)
2525
Timer Output CompareTimer Output Compare
Using the timer overflow flag or interrupt will Using the timer overflow flag or interrupt will generate a count every 65536 clock cycles.generate a count every 65536 clock cycles.
Given a 2 MHz E-clock, this gives a sample Given a 2 MHz E-clock, this gives a sample resolution of 32.8 ms (prescale = 1)resolution of 32.8 ms (prescale = 1)
The timer output compare feature allows for The timer output compare feature allows for more precise timing.more precise timing.
![Page 26: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/26.jpg)
2626
Timer Output CompareTimer Output Compare
There are five output compare registersThere are five output compare registersEach with a separateEach with a separate
Compare CounterCompare Counter Interrupt MaskInterrupt Mask Overflow FlagOverflow Flag
![Page 27: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/27.jpg)
2727
TOC1 – TOC5 TOC1 – TOC5 Timer Output Compare RegistersTimer Output Compare Registers
7 6 5 4 3 2 1 0
Bits
OCn15
TOC1 - $1016:$1017TOC2 - $1018:$1019TOC3 - $101A:$101B
OCn13 OCn12 OCn11 OCn10 OCn9 OCn8OCn14
7 6 5 4 3 2 1 0
OCn7 OCn5 OCn4 OCn3 OCn2 OCn1 OCn0OCn6
TOC4 - $101C:$101DTOC5 - $101E:$101F
![Page 28: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/28.jpg)
2828
Output Compare FlagsOutput Compare Flags
7 6 5 4 3 2 1 0
Bits
IC3FIC2FOC4F IC1FOC5FOC3FOC2FOC1F
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
![Page 29: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/29.jpg)
2929
Output Compare InterruptsOutput Compare Interrupts
7 6 5 4 3 2 1 0
Bits
IC3IIC2IOC4I IC1IOC5IOC3IOC2IOC1I
Main Timer Interrupt Mask Register 1: $1022 (TMSK1)
OC1I-OC5I = Output Compare interrupt enable 0 = disable interrupt 1 = enable interrupt
![Page 30: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/30.jpg)
3030
Output Compare ExampleOutput Compare Example
Problem: Write an ISR to read the input Problem: Write an ISR to read the input from PortC and write it to PortB from PortC and write it to PortB approximately every 10,000 E-clock approximately every 10,000 E-clock cycles. Assume timer prescale = 1cycles. Assume timer prescale = 1
Note: 10,000 cycles is less than one timer Note: 10,000 cycles is less than one timer overflow!!overflow!!
![Page 31: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/31.jpg)
3131
Output Compare ExampleOutput Compare ExampleMain ProgramMain Program
AA TCNT ; Load current count TCNT ; Load current count TOC1 TOC1 A + 10000 ; Add 10000 to current count A + 10000 ; Add 10000 to current count Configure Output Compare 1 InterruptConfigure Output Compare 1 Interrupt
TMSK1(7) TMSK1(7) ‘1’ ‘1’
Enable Interrupts (CLI)Enable Interrupts (CLI) RepeatRepeat Until ForeverUntil Forever
Set Output Compare 1 Interrupt VectorSet Output Compare 1 Interrupt Vector ORG OC1_VECTOR ($FFE8:FFE9)ORG OC1_VECTOR ($FFE8:FFE9) FDB OC1_ISRFDB OC1_ISR
![Page 32: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/32.jpg)
3232
Output Compare ExampleOutput Compare ExampleOC1_ISROC1_ISR
Disable Interrupts Disable Interrupts SEISEI
Turn-off Interrupt RequestTurn-off Interrupt Request OC1F OC1F ‘1’ ‘1’
A A PORTC PORTC PORTB PORTB A A A A TCNT ; Load current count TCNT ; Load current count TOC1 TOC1 A+10000 ; update TOC1 for next A+10000 ; update TOC1 for next interruptinterrupt Return from InterruptReturn from Interrupt
![Page 33: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/33.jpg)
3333
In-Class AssignmentIn-Class Assignment
Get with a partner and answer the following:Get with a partner and answer the following:
Assume an E-clock of 1 MHz and prescale set to 4. Assume an E-clock of 1 MHz and prescale set to 4.
Determine what number must be added to the Determine what number must be added to the current TCNT (sum store in TOC1) to create an current TCNT (sum store in TOC1) to create an interrupt that occurs in 125 msec.interrupt that occurs in 125 msec.
![Page 34: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/34.jpg)
3434
Input CaptureInput Capture
![Page 35: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/35.jpg)
3535
Timer Input CaptureTimer Input Capture
16-bit TCIx LatchDetCkt
TCNT
clkExt 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
![Page 36: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/36.jpg)
3636
Timer Input CaptureTimer Input Capture
The timer input capture feature can be used The timer input capture feature can be used to time external eventsto time external events
Three input capture registersThree input capture registers TIC1 : $1010:$1011TIC1 : $1010:$1011 TIC2 : $1012:$1013TIC2 : $1012:$1013 TIC3: $1014:$1015TIC3: $1014:$1015
Maximum time between events must be less Maximum time between events must be less than 65536 cyclesthan 65536 cycles
![Page 37: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/37.jpg)
3737
TIC1 – TIC3 TIC1 – TIC3 Timer Input Capture RegistersTimer Input Capture Registers
7 6 5 4 3 2 1 0
Bits
ICn15
TIC1 - $1010:$1011TIC2 - $1012:$1013TIC3 - $1014:$1015
ICn13 ICn12 ICn11 ICn10 ICn9 ICn8ICn14
7 6 5 4 3 2 1 0
ICn7 ICn5 ICn4 ICn3 ICn2 ICn1 ICn0ICn6
![Page 38: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/38.jpg)
3838
Input Compare InterruptsInput Compare Interrupts
7 6 5 4 3 2 1 0
Bits
IC3IIC2IOC4I IC1IOC5IOC3IOC2IOC1I
Main Timer Interrupt Mask Register 1: $1022 (TMSK1)
IC1I-IC3I = Input Compare interrupt enable 0 = disable interrupt 1 = enable interrupt
![Page 39: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/39.jpg)
3939
Interrupt Capture FlagsInterrupt Capture Flags
7 6 5 4 3 2 1 0
Bits
IC3FIC2FOC4F IC1FOC5FOC3FOC2FOC1F
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
![Page 40: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/40.jpg)
4040
Timer Control Register 2Timer Control Register 2TCTL2 - $1021TCTL2 - $1021
7 6 5 4 3 2 1 0
Bits
EDG1B EDG1A EDG2B EDG2A EDG3B EDG3A0 0
EDGnB EDGnA Configuration 0 0 Disabled 0 1 Rising Edge 1 0 Falling Edge 1 1 Either Edge
![Page 41: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/41.jpg)
4141
Pulse AccumulatorPulse Accumulator
![Page 42: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/42.jpg)
4242
Pulse AccumulatorPulse Accumulator
The pulse accumulator can be used as an event The pulse accumulator can be used as an event counter. That is, it can count the number of counter. That is, it can count the number of external events. external events.
Note: difference to Timer Input Capture which Note: difference to Timer Input Capture which counts the counts the timetime between external events. between external events.
Configuration:Configuration: PACTL ($1026) is used to configure PAPACTL ($1026) is used to configure PA PACNT ($1027) is the PA Count RegisterPACNT ($1027) is the PA Count Register
Two Modes:Two Modes: Event Counting: PA7 is External ClockEvent Counting: PA7 is External Clock Gated Time Accumulation: PA7 is enable to system Gated Time Accumulation: PA7 is enable to system
clock divided by 64clock divided by 64
![Page 43: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/43.jpg)
4343
PACTL: $1026PACTL: $1026Port A Control RegisterPort A Control Register
7 6 5 4 3 2 1 0
Bits
RTR0RTR1PEDGEPAMODPAEN6DDRA7 00
PAEN6 = Pulse Accumulator System Enable0 = Disable (Default)
Port A is set for I/O function1 = Enable
Port A is set for Pulse Accumulator function
PAMOD= Pulse accumulator mode0 = Event counter (Default)1 = Gated time accumulation
![Page 44: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/44.jpg)
4444
PACTL: $1026PACTL: $1026Port A Control RegisterPort A Control Register
7 6 5 4 3 2 1 0
Bits
RTR0RTR1PEDGEPAMODPAEN6DDRA7 00
PEDGE= Pulse Accumulator Edge Select0 = Falling Edge (in event mode) – Active High (in gated mode)1 = Rising Edge (in event mode) – Active Low (in gated mode)
![Page 45: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/45.jpg)
4545
Pulse Accumulator FlagPulse Accumulator Flag
7 6 5 4 3 2 1 0
Bits
00PAIF 00PAOVFRTIFTOF
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
![Page 46: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/46.jpg)
4646
Pulse Accumulator Interrupts Pulse Accumulator Interrupts
7 6 5 4 3 2 1 0
Bits
PR2PR1PAII 00PAOVIRTIITOI
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
![Page 47: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/47.jpg)
4747
Pulse Width ModulationPulse Width Modulation
![Page 48: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/48.jpg)
4848
Pulse Width ModulationPulse Width Modulation
Some versions of 68HC11 have a pulse Some versions of 68HC11 have a pulse width modulation (PWM) module which width modulation (PWM) module which can be used to can be used to generategenerate periodic output periodic output waveforms with a specific period and duty waveforms with a specific period and duty cycle (i.e. the percentage of time the cycle (i.e. the percentage of time the signal is high compare to when it is low).signal is high compare to when it is low).
Example application: PWM for controlling Example application: PWM for controlling motor speed in a robotmotor speed in a robot
![Page 49: 1 68HC11 Timer HC11 or HC12: Chapter 10. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfec1a28abf838cb84fc/html5/thumbnails/49.jpg)
4949
Timer SummaryTimer Summary Timer subsystem – most complex in 68HC11Timer subsystem – most complex in 68HC11 Based on free running timerBased on free running timer Timings available:Timings available:
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
Overflow flags and/or Interrupts are availableOverflow flags and/or Interrupts are available