Microcontroller6

Microcontroller6 - 4/17/2011 1 Timer Functions (Chapter 8)...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: 4/17/2011 1 Timer Functions (Chapter 8) A.H. Mohsenian-Rad (U of T) 1 Networking and Distributed Systems Timer Applications Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-2 • Timers can be used for several applications : s Time delay creation and measurement s Period and pulse width measurement s Frequency measurement s Event counting s Periodic interrupt generation s Waveform generation HCS12 Timer Unit Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-3 • Here is the block diagram: • It uses ports PT7~PT0 . • There are 8 channels . Timer Counter Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-4 • The heart of the timer unit is a 16 bit timer counter register . • It is denoted by TCNT ($0044) . • At any time, we can read the content of the timer counter using: • Q: Why not using the following codes? ldd TCNT ; load timer counter to D. movw TCNT, $2000 ; load timer counter to $2000~2001 ldd TCNT ; load timer counter to D. movw TCNT, $2000 ; load timer counter to $2000~2001 ldaa $0044 ldab $0045 ldaa $0044 ldab $0045 movb $0044, $2000 movb $0045, $2001 movb $0044, $2000 movb $0045, $2001 4/17/2011 2 Timer Counter Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-5 • TCNT must be enabled before it can be used. • The following instruction can enable TCNT: • Note that TSCR1 ( $0046 ) is Timer System Control Register 1. • TCNT starts counting right after it is enabled. bset TSCR1, %10000000 bset TSCR1, %10000000 Timer Counter Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-6 • Q: What are the values of X, Y, and D after running this code? #include "MC9S12DP256BEQU.inc" #include "DEBUG12V4EQU.inc" org $1000 bset TSCR1, %10000000 ; enable TCNT ldx TCNT nop ldy TCNT nop nop ldd TCNT #include "MC9S12DP256BEQU.inc" #include "DEBUG12V4EQU.inc" org $1000 bset TSCR1, %10000000 ; enable TCNT ldx TCNT nop ldy TCNT nop nop ldd TCNT Timer Counter Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-7 • Note that NOP takes 1 cycle and LDX, LDY, and LDD take 3 cycles. • Q: What is the rate at which TCNT counts? • This is the default rate . We will change it later on. Timer Counter Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-8 • By looking at TCNT and knowing SYSCLK, we can keep track of time. • Example : Consider the following timing for an event: • TCNT = $0012 when the event starts . • TCNT = $BB92 when the event ends . • Q: How long did the event take? 4/17/2011 3 Timer Counter Overflow Dr. Hamed Mohsenian-Rad Texas Tech University ECE 3362: Microcontrol ers – Spring 2011 6-9 • Q: What happens when TCNT reaches $FFFF ?...
View Full Document

This document was uploaded on 10/27/2011 for the course EE 3362 at Texas Tech.

Page1 / 33

Microcontroller6 - 4/17/2011 1 Timer Functions (Chapter 8)...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online