DOC PREVIEW
UNCC ECGR 4101 - Using the M16C or 62 Timers in One-Shot Mode

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 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 9 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 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

AbstractIntroductionOne-Shot Mode DescriptionConfiguring One-Shot ModeReferencesSoftware CodeAPPLICATION NOTE M16C/62 Using the M16C/62 Timers in One-Shot Mode 1.0 Abstract One-shots are commonly found in designs because they are useful for debouncing switches, “cleaning” up sensor inputs, and so on. The A timers on the M16C/62 can be configured as one-shots, reducing the need for external components. These one-shots have advantages over their hardware counterparts because they are not susceptible to RC drift, and the pulse widths can be varied under program control allowing for new applications such as fuel injection control and ignition control. The following article describes how to configure the M16C/62 A timers as one-shots, referred to as One-Shot Mode. 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 5 Timer A’s. All 5 timers can operate in One-Shot Mode. Timer A has the following additional modes of operation: • Event Counter Mode • PWM Mode • Timer Mode Figure 1Figure 1 Bock Diagram of Timer A illustrates the operation of timer A. The remainder of this document will focus on setting up timer A0 in One-Shot Mode using an external trigger. Count start flag(Address 038016)Up count/down countTAi Addresses TAj TAkTimer A0 038716038616 Timer A4 Timer A1Timer A1 038916038816 Timer A0 Timer A2Timer A2 038B16038A16Timer A1 Timer A3Timer A3 038D16038C16Timer A2 Timer A4Timer A4 038F16038E16Timer 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 REU05B0022-0100Z June 2003 Page 1 of 8M16C/62Using the M16C/62 Timers in One-Shot Mode 3.0 One-Shot Mode Description In One-Shot Mode, an event (internal or external trigger) causes the TAiout output pin to go high. The TAi register counts down using the selected clock source until the counter underflows (0000 to FFFFh). At this point, the TAiout pin goes low and the contents of the reload register are loaded back into the TAi register and the interrupt request bit is set. 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 stopped and the contents of the reload register are loaded back into the count register. The one-shot can be triggered (externally) by a signal on the TAiin pin or (internally) by the one-shot start flag or another timer output. If a trigger occurs while a count is in progress, the counter reloads the value in the reload counter and continues counting. and illustrate this. Figure 2Figure 2 Oeration Timing of One-Shot Mode Figure 3 FFFF16n000116Timer Ai interruptrequest bitCounter content (hex)n = reload register contentReloadOne-shot pulse output from TAiOUT pin“H”1 / fi X (n)“L”TimeReload1 / fi X (n+1) Write signal to one-shot start flag“1”“0”Count start flag“1”“0”(1) Start countCleared to “0” when interrupt request is accepted, or cleared by software(2) Stop count(3) Start count(4) Stop countStart countReloadSet to “1” by softwareCleared to “0” by software REU05B0022-0100Z June 2003 Page 2 of 8M16C/62Using the M16C/62 Timers in One-Shot Mode FFFF16n000116Timer Ai interruptrequest bitCounter content (hex)n = reload register contentReloadReload(4) Stop countOne-shot pulse output from TAiOUT pin“H”1 / fi X (n)“L”1 / fi X (n+1) TAiIN pininput signal“H”“L”“1”Cleared to “0” when interrupt request is accepted, or cleared by software“0”Count start flag“1”“0”(2) Stop count(1) Start count(3) Start countTimeReloadStart countSet to “1” by softwareTrigger during countCleared to “0” by software Figure 3 Operation Timing of One-Shot Mode, External Trigger Selected 4.0 Configuring One-Shot Mode To configure a timer for One-Shot 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 One-Shot Mode: bits TMOD0 = 0, TMOD1 = 1. • Set the MR0 bit = 1 for output on the TAiOUT pin, clear for no output. • Clear the MR1 bit for a falling edge external trigger on the TAiIN pin, or set it for rising edge. • Clear the MR2 bit to use the ‘count start flag’ as a trigger, or set it for external trigger. • Clear the MR3 bit One-Shot Mode. • Select the clock source (f1, f/8, f/32, or fc/32): bits TCK0,TCK1 register. 3. Load the Timer Interrupt Control register (TAiIC) with an interrupt priority level, (ILVL) (load with zero if interrupts are not required). 4. Enable interrupts if required ( set the I flag ). 5. Set the ‘start count’ flag bit, TAiS in the ‘Count Start Flag’ register, TABSR. 6. Set the one-shot start flag bit, TAiOS in the ‘one-shot start flag register’, ONSF. Note that if the one-shot start flag is selected as the trigger, the TAiOUT pin will immediately go high. It is not necessary to perform these steps in the order listed, but an initial value should be loaded into the TAi register 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 8. Figure 4 REU05B0022-0100Z June 2003 Page 3 of 8M16C/62Using the M16C/62 Timers in One-Shot Mode Bit nameTimer Ai mode registerSymbol Address When resetTAiMR(i = 0 to 4) 039616 to 039A16 0016Function Bit symbolb7 b6 b5 b4 b3 b2 b1 b0Operation mode select bit1 0 : One-shot timer modeb1 b0 TMOD1TMOD0MR0Pulse 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)MR2MR1MR30 (Must always be “0” in one-shot


View Full Document

UNCC ECGR 4101 - Using the M16C or 62 Timers in One-Shot Mode

Documents in this Course
Load more
Download Using the M16C or 62 Timers in One-Shot Mode
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 Using the M16C or 62 Timers in One-Shot Mode 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 Using the M16C or 62 Timers in One-Shot Mode 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?