Lecture30 - 0306-250 Assembly Language Programming Lecture...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Lecture Thirty: Timer Driver Stopwatch (Text Chapter 14) •HSC12 Enhanced Capture Timer (ECT) Module •ECT Registers •Driver Algorithm HCS12 ECT Module Enhanced capture timer (ECT) module • 16-bit counter • Four functions/features – Timer overflow Flag set on timer overflow: $FFFF à $0000 – Output compare Compare counter with register value – Input compare Capture counter value on selected input edge – 16-bit pulse accumulator Count external events or internal clock pulses • Data sheet link on course resources web page 2 HCS12 Block Diagram ECT MC9S12DT256 Device User Guide, V03.07, p. 23 3 ECT Block Diagram ECT_16B8C Block User Guide V01.06 (S12ECT16BV1), p. 14. 4 PWM Registers (Part 1) ECT_16B8C Block User Guide V01.06 (S12ECT16BV1), p. 17. 5 PWM Registers (Part 2) ECT_16B8C Block User Guide V01.06 (S12ECT16BV1), p. 18. 6 PWM Registers (Part 3) ECT_16B8C Block User Guide V01.06 (S12ECT16BV1), p. 19. 7 ECT Timer System Control Register 2 7 6 5 4 3 2 1 0 TOI 0 0 0 TCRE PR2 PR1 PR0 ClockScaleExponent = PR2 : PR1: PR0 BusClockRate 1 f ExternalOscillator ClockRate = ClockScaleExponent = 2 ClockScaleExponent 2 2 • Set clock rate for counter Want 250 kHz for counter? PR2:PR1:PR0: ClockPrescaler: 3 = %011 • Timer overflow interrupt enable Want disabled? TOI: 0 • Timer counter reset enable Want enabled? TCRE: 1 movb #(mTSCR2_TCRE|mTSCR2_PR1|mTSCR2_PR0),TSCR2 8 ECT Timer Input Capture/ Output Compare Select Register (TIOS) 7 6 5 4 3 2 1 0 IOS7 IOS6 IOS5 IOS4 IOS3 IOS2 IOS1 IOS0 Select input capture¢/output compare for each channel — Want output compare for channel 7? IOS7 : Input¢/Output: 1 — Want to let other channels (not used) default? Other bits: 0 movb #mTIOS_IOS7,TIOS 9 ECT Timer Input Capture/ Output Compare Register 7 (TC7) 16-bit value of counter to generate output compare interrupt Want interrupt every 0.01s? (0.01 s = 2500 * 4 ms) CR7 : Count value of output compare: 2500 ECT_10ms: EQU 2500 movw #ECT_10ms,TC7 10 ECT Timer Interrupt Enable Register (TIE) 7 6 5 4 3 2 1 0 C7I C6I C5I C4I C3I C2I C1I C0I Interrupt enable for each input capture/ output compare channel Want interrupt on channel 7 output compare? C7I : Channel 7 interrupt enable: 1 movb #mTIE_C7I,TIE 11 ECT Timer System Control Register 1 (TSCR1) 7 6 5 4 3 2 1 0 TEN TSWAI TSFRZ TFFCA 0 0 0 0 Timer enable Want to enable? TEN : timer enable: 1 movb #mTSCR1_TEN,TSCR1 12 ECT Timer Driver • Interrupt vector table address for ECT channel 7 $FFE0 • Count: Time counter Word variable Number of ECT OC7 interrupts • RunStopWatch: Behavior on interrupt Boolean byte variable 0: Do not increment time counter nonzero: Increment time counter 13 ECT OC7 ISR Pseudocode if (RunStopWatch) { Increment Count } Clear interrupt return 14 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online