DOC PREVIEW
UNCC ECGR 4101 - Study Notes

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

AbstractIntroductionTimer Mode DescriptionConfiguring Timer ModeReferenceSoftware CodeAPPLICATION NOTE M16C/62 Using the M16C/62 Timers in Timer Mode 1.0 Abstract The following article describes how to use timers A and B as basic timers, referred to as Timer Mode. Timers are useful for updating multiplexed display, scanning inputs, real time clocks, hardware watchdogs, etc. 2.0 Introduction The M16C/62 is a 16-bit MCU, based on the M16C CPU core, with features including 10-bit A/D, D/A, UARTS, timers, DMA, etc., and up to 256KB of user flash. The MCU has 11 timers. The timers are separated into two categories by functionality, 5 Timer A’s and 6 Timer B’s. All 11 timers can operate in Timer Mode. Timer A has the following additional modes of operation: • Event Counter Mode • PWM Mode • One-Shot Mode Timer B has the following additional modes of operation: • Event Counter Mode • Pulse Width Measurement Mode Figure 1Figure 1 Bock Diagram of Timer A illustrates the operation of timer A and Figure 2 illustrates Timer B. Note that there are some differences between the two timers but both operate similarly in Timer Mode. The remainder of this document will focus on setting up timer A0 in Timer Mode. Count start flag(Address 038016)Up count/down countTAi Addresses TAj TAkTimer A0 038716 038616 Timer A4 Timer A1Timer A1 038916 038816 Timer A0 Timer A2Timer A2 038B16 038A16 Timer A1 Timer A3Timer A3 038D16 038C16 Timer A2 Timer A4Timer A4 038F16 038E16 Timer A3 Timer A0Always down count except in event counter modeReload register (16) Counter (16)Low-order 8 bitsHigh-order 8 bitsClock source selection Timer (gate function) Timer One shot PWMf1f8f32TAiIN (i = 0 to 4)TB2 overflow Event counterfC32Clock selectionTAj overflow (j = i 1. Note, however, that j = 4 when i = 0)Pulse outputToggle flip-flopTAiOUT (i = 0 to 4)Data bus low-order bitsData bus high-order bitsUp/down flagDown count(Address 038416)TAk overflow (k = i + 1. Note, however, that k = 0 when i = 4)Polarity selectionClock selectionTo external trigger circuit REU05B0021-0100Z June 2003 Page 1 of 9M16C/62Using the M16C/62 Timers in Timer Mode Clock source selection(address 038016) Event counter Timer Pulse period/pulse width measurementReload register (16)Low-order 8 bitsHigh-order 8 bitsData bus low-order bitsData bus high-order bitsf1f8f32TBj overflow (j = i 1. Note, however, j = 2 when i = 0, j = 5 when i = 3)Can be selected in only event counter modeCount start flag fC32Polarity switching and edge pulseTBiIN (i = 0 to 5)Counter reset circuitCounter (16)TBi Address TBjTimer B0 039116 039016Timer B2Timer B1 039316 039216Timer B0Timer B2 039516 039416 Timer B1Timer B3 035116 035016Timer B5Timer B4 035316 035216Timer B3Timer B5 035516 035416 Timer B4Clock selection Figure 2 Block Diagram of Timer B 3.0 Timer Mode Description In Timer Mode, the counter register counts down using the selected clock source until the counter underflows (0000 to FFFFh). At this point, the timer interrupt request bit is set and the contents of the reload register are loaded back into the counter and countdown continues. An interrupt will be accepted when all of the following conditions are met: • interrupt enable flag (I flag) = "1" • interrupt request bit = "1" • interrupt priority level > IPL (Processor Interrupt Priority Level) If at any time during countdown the count start flag is cleared, counting is suspended until set. Figure 3 illustrates this. FFFF16n000016TimeStart count againCount start flagTimer Ai interruptrequest bit“1”“1”Counter content (hex)n = reload register contentSet to “1” by software“0”“0”Set to “1” by softwareCleared to “0” by softwareCleared to “0” when interrupt request is accepted, or cleared by software(1) Start count (2) Underflow(3) Stop count Figure 3 Operation Timing of Timer Mode REU05B0021-0100Z June 2003 Page 2 of 9M16C/62Using the M16C/62 Timers in Timer Mode 4.0 Configuring Timer Mode To configure a timer for Timer Mode: 1. Load the Timer Ai register, TAi (which also loads the reload register) with the count source. 2. Load the Timer Mode register, TAiMR: • Select timer mode: bits TMOD0, TMOD1 = 0. • Select the clock source (f1, f/8, f/32, or fc/32): bits TCK0,TCK1. 3. Load the Timer Interrupt Control register (TAiIC) with an interrupt priority level (ILVL) value of at least 1 if interrupts are desired. 4. Ensure interrupts are enabled ( I flag set). 5. Set the ‘start count’ flag bit, TAiS in the Count Start Flag register, TABSR. It is not necessary to perform these steps in the order listed, but the count register should be loaded before the ‘start count’ flag is set. Also, the priority level should not be modified when there is a possibility of an interrupt occurring. The required registers are shown in through Figure 7. Figure 4Figure 4 Timer Ai Register FunctionR WSymbolTA0TA1TA2TA3TA4Address038716, 038616038916, 038816038B16, 038A16038D16, 038C16038F16, 038E16When resetIndeterminateIndeterminateIndeterminateIndeterminateIndeterminateTimer Ai register (Note)b7b8)(b15b0O OO OX OX OX OTimer modeCounts an internal count sourceEvent counter modeCounts pulses from an external source ortimer overflowOne-shot timer modeCounts a one-shot widthPulse width modulation mode (16-bit PWM)Functions as a 16-bit pulse width modulatorPulse width modulation mode (8-bit PWM)timer low-order address functions as an 8-bit prescaler and high-order addressfunctions as an 8-bit pulse width modulator000016 to FFFF16Values that can be set000016 to FFFF16000016 to FFFF16000016 to FFFF160016 to FE16 (Bothhigh-order and low-order addresses)Note: Read and write data in 16-bit unitsb7b0 REU05B0021-0100Z June 2003 Page 3 of 9M16C/62Using the M16C/62 Timers in Timer Mode Note 1: The settings of the corresponding port register and port direction register are invalid. Timer Ai mode registerSymbol Address When reset TAiMR(i=0 to 4) 039616 to 039A16 0016Bit name FunctionBit symbol WRb7 b6 b5 b4 b3 b2 b1 b0Operation mode select bit0 0 : Timer modeb1 b0 TMOD1TMOD0 MR0Pulse output function select bit0 : Pulse is not output (TAiOUT pin is a normal port pin)1 : Pulse is output (Note 1) (TAiOUT pin is a pulse output pin)Gate function select bit0 X (Note 2): Gate function not available (TAiIN pin is a normal port pin)1 0 : Timer counts only when TAiIN pin is held


View Full Document

UNCC ECGR 4101 - Study Notes

Documents in this Course
Load more
Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?