DOC PREVIEW
UNCC ECGR 4101 - Using the M16C/62 Timer in PWM 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:

AbstractIntroductionPWM Mode DescriptionConfiguring PWM ModeReferenceSoftware CodeAPPLICATION NOTE M16C/62 Using the M16C/62 Timer in PWM Mode 1.0 Abstract PWMs, or Pulse Width Modulators, are useful in DC motor control, actuator control, synthesized analog output, piezo transducers, etc. PWMs produce a signal of (typically) fixed frequency and vary the width of the pulse to control a peripheral. The following article describes how to use the M16C/62 A Timers as Pulse Width Modulators, referred to as Pulse Width Modulation 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 of which can operate as PWMs. Timer A has the following additional modes of operation: • Event Counter Mode • Timer Mode • One-Shot Mode Figure 1Figure 1 Block Diagram of Timer A illustrates the operation of timer A. The remainder of this document will focus on setting up timers A0 and A1 in PWM 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 REU05B0025-0100Z June 2003 Page 1 of 8M16C/62Using the M16C/62 Timer in PWM Mode 3.0 PWM Mode Description PWM Mode has two “sub” modes: 16 bit and 8 bit. In 16-bit mode, the value of the 16-bit Ai Timer register determines the pulse width and the frequency is fixed to fin / 65535. Therefore the maximum frequency of the 16-bit PWM (assuming 16 MHz at Xin) is approximately 244 Hz. In 8-bit mode, the high order 8 bits are used to determine the pulse width and the lower 8 bits the frequency, where the frequency is fin / 255 or a maximum frequency of approximately 62,745 Hz. Note that the PWM output is free running and interrupts need not be enabled or serviced. Also the user has the option of triggering the start of the PWM output via the timer’s TaiIN pin. The pulse width (high level) of the 16-bit PWM is: pulse width (high) = n/ fin , or % duty = n / 65535 * 100, where n is the value loaded into the Ai counter register. The pulse width (high level) of the 8-bit PWM is: pulse width (high) = n * (m+1) / fin , or n/ (255 * fPWM ), % duty = n / 255 * 100, where n is the value loaded into the Ai counter register’s high order address and m is loaded into the Ai counter register’s low order address. The pulse width can be changed at any time by writing to the Ai counter register, but during counting, the write affects only the reload register, and the counter register is updated on the next cycle. Figure 2Figure 2 Example of How a 16-bit Pulse Width Modulator Operates and illustrate the timing for the PWMs. Figure 3 1 / fi X (2 1) 16Count sourceTAiIN pin input signalPWM pulse output from TAiOUT pinCondition : Reload register = 000316, when external trigger (rising edge of TAiIN pin input signal) is selectedTrigger is not generated by this signalHHLLTimer Ai interrupt request bit10Cleared to 0 when interrupt request is accepted, or cleared by softwarefi : Frequency of count source(f1, f8, f32, fC32)Note: n = 000016 to FFFE16.1 / fi X n REU05B0025-0100Z June 2003 Page 2 of 8M16C/62Using the M16C/62 Timer in PWM Mode Count source (Note1)TAiIN pin input signalUnderflow signal of 8-bit prescaler (Note2)PWM pulse output from TAiOUT pinHHHLLL10Timer Ai interrupt request bitCleared to 0 when interrupt request is accepted, or cleaerd by softwarefi : Frequency of count source (f1, f8, f32, fC32)Note 1: The 8-bit prescaler counts the count source.Note 2: The 8-bit pulse width modulator counts the 8-bit prescaler's underflow signal.Note 3: m = 0016 to FF16; n = 0016 to FE16.Condition : Reload register high-order 8 bits = 0216Reload register low-order 8 bits = 0216External trigger (falling edge of TAiIN pin input signal) is selected1 / fi X (m + 1) X (2 1) 81 / fi X (m + 1) X n 1 / fi X (m + 1) Figure 3 Example of How an 8-bit Pulse Width Modulator Operates 4.0 Configuring PWM Mode To configure a timer for PWM mode: 1. Load the Timer Ai register with the pulse width value (16-bit) or frequency and pulse width value (8-bit). Note: For 16-bit 65535 is not valid. For 8-bit 255 is not valid. 2. Load the Timer Ai Mode register, TaiMR: • Select PWM mode: bits TMOD0 and TMOD1 = 1. • Set the MR0 bit = 1 for PWM Mode. • Clear the MR1 bit for a falling edge external trigger, 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 for 16-bit PWM, and set it for 8-bit PWM. • 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 zero if interrupts are not required).. 4. Enable interrupts if required ( I flag set). 5. Set the ‘start count’ flag bit, TaiS in the ‘count start flag’ register, TABSR. REU05B0025-0100Z June 2003 Page 3 of 8M16C/62Using the M16C/62 Timer in PWM Mode 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 Mode Register in Pulse Width Modulation Mode Bit nameTimer Ai mode register Symbol Address When reset TAiMR(i=0 to 4) 039616 to 039A16 0016FunctionBit symbolb7 b6 b5 b4 b3 b2 b1 b0Operation mode select bit1 1 : PWM modeb1 b0 TMOD1TMOD0MR0MR1MR30 0 : f10 1 : f81 0 : f321 1 : fC32b7 b6 TCK1TCK0Count source select bitWR1111 (Must always be “1” in PWM mode)16/8-bit PWM mode


View Full Document

UNCC ECGR 4101 - Using the M16C/62 Timer in PWM Mode

Documents in this Course
Load more
Download Using the M16C/62 Timer in PWM 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/62 Timer in PWM 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/62 Timer in PWM 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?