Text preview for : Timer asynchrone.pdf part of MAAS KNT-5000 Stabilized DC Power Supply MAAS KNT-5000



Back to : Maas KNT-5000.pdf | Home

M
Author:

AN580
In asynchronous operation, if the clock source is an external clock, it is input on the T1CKI pin. If the clock source is a crystal oscillator, the crystal is connected across the T1OSO and T1OSI pins. When using Timer1 in Asynchronous mode, the use of an external clock minimizes the operating and sleep currents. This is because the timer's internal oscillator circuitry is disabled. Though the external clock may give the lower device currents, the use of a crystal oscillator may lead to lower system current consumption and system cost. System current consumption can also be reduced by having the TMR1 Overflow Interrupt wake the processor from SLEEP at the desired interval, With a 32.768 kHz crystal, Timer1's overflow rate ranges from 2 to 16 seconds, depending on the prescaler chosen. Table 1 shows Timer1 overflow times for various crystal frequencies and prescaler values.

Using Timer1 in Asynchronous Clock Mode

Mark Palmer Microchip Technology Inc.

INTRODUCTION
This application note discusses the use of the PIC16CXXX Timer1 module as an asynchronous clock. The Timer1 module has it own oscillator circuitry, which allows the timer to keep real-time, even when the device is in SLEEP mode. When the device is in sleep, the oscillator will continue to increment TMR1. An overflow of the TMR1 register causes a TMR1 Overflow Interrupt (if enabled) and will wake the processor from sleep. The interrupt service routine can then perform the desired task.

OVERVIEW
Timer1 is a 16-bit counter with a 2-bit prescaler. Timer1 can be incremented from an internal clock, an external clock, or an external oscillator. Timer1 can be configured to synchronize or not synchronize the external clock sources. Asynchronous operation allows Timer1 to increment when the device is in sleep. Figure 1 is a block diagram of Timer1. To set up Timer1 for asynchronous operation the Timer1 control register, T1CON, must have the following bits configured: · TMR1CS set (external clock source) · T1CKS1:T1CKS0 configured for the desired prescaler · T1SYNC set (asynchronous operation) · TMR1ON set (enables Timer1) · T1OSCEN set, if using an external oscillator

TABLE 1:

TIMER1 OVERFLOW TIMES
Frequency (kHz)

Prescale 1 2 4 8

32.768 2 4 8 16

100 0.655 1.31 2.62 5.24

200 0.327 0.655 1.31 2.62

Overflow times in seconds.

FIGURE 1:

TIMER1 BLOCK DIAGRAM
Set flag bit TMR1IF on Overflow TMR1 TMR1H TMR1L 1 TMR1ON on/off T1OSC T1SYNC Synchronize det SLEEP input 0 Synchronized clock input

RC0/T1OSO/T1CKI T1OSCEN FOSC/4 Enable Internal Oscillator Clock

1 Prescaler 1, 2, 4, 8 0 2 T1CKPS1:T1CKPS0 TMR1CS

RC1/T1OSI/CCP2

When the T1OSCEN bit is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.

© 1997 Microchip Technology Inc.

DS00580C-page 1

AN580
As can be seen the 32 kHz crystal, gives very nice overflow rates. These crystals, referred to as watch crystals, also can be relatively inexpensive. In many applications the 2 second overflow time, of a 32 kHz crystal, is too long. An easy way to reduce the overflow time is to load the TMR1H register with a value, during the interrupt service routine. Table 2 shows the overflow times, depending on the value loaded into the TMR1H register and a prescale of 1. The code segment shown in Example 1 configures the Timer1 module for asynchronous operation, enables the Timer1 interrupt, and the interrupt service routine loads the TMR1H register with a value.

CONCLUSION
Timer1 gives designers a powerful time-base function. The asynchronous operation and internal oscillator circuitry gives designers the ability to easily keep realtime, while minimizing power consumption and external logic.

TABLE 2:

TMR1H LOAD VALUES / TIMER1 OVERFLOW TIMES
Overflow Time (@ 32.768 kHz) 1 Second 0.5 Second 0.25 Second 0.125 Second

TMR1H Load Value 80h C0h E0h F0h

Note:

The loading of either TMR1H or TMR1L causes the prescaler to be cleared. When Timer1 is in operation, extreme care should be taken in modifying either the TMR1H or TMR1L registers, since this automatically configures the prescaler to 1.

DS00580C-page 2

© 1997 Microchip Technology Inc.

AN580
EXAMPLE 1:
org Reset_V ; org PER_INT_V

TIMER1 CODE SEGMENT FOR ASYNCHRONOUS OPERATION

0x000 GOTO 0x004 BCF BTFSC GOTO

START

STATUS, RP0 PIR1, TMR1IF T1_OVRFL

; Bank0 ; Timer1 overflowed? ; YES, Service the Timer1 Overflow Interrupt

; ; Should NEVER get here ; ERROR1 ; NO, Unknown Interrupt Source BSF PORTD, 1 ; Toggle a port pin to indicate error BCF PORTD, 1 GOTO ERROR1 ; T1_OVRFL BCF PIR1, TMR1IF ; Clear Timer1 Interrupt Flag MOVLW 0x80 ; Since doing key inputs, clear TMR1 MOVWF TMR1H ; for 1 sec overflow. : : ; Do Interrupt stuff here : RETFIE ; Return / Enable Global Interrupts ; ; START ; POWER_ON Reset (Beginning of program) CLRF STATUS ; Do initialization (Bank0) BCF T1CON, TMR1ON ; Timer1 is NOT incrementing : : ; Do Initialization stuff here : MOVLW 0x80 ; TIM1H:TMR1L = 0x8000 gives 1 second MOVWF TMR1H ; overflow, at 32 KHz. CLRF TMR1L ; ; CLRF INTCON CLRF PIR1 BSF STATUS, RP0 ; Bank1 CLRF PIE1 ; Disable all peripheral interrupts ; if ( C74_REV_A ) ; See PIC16C74 Errata BSF TRISC, T1OSO ; RC0 needs to be input for the oscillator to function endif BSF PIE1, TMR1IE ; Enable TMR1 Interrupt ; ; Initialize the Special Function Registers (SFR) interrupts ; BCF STATUS, RP0 ; Bank0 CLRF PIR1 ; BSF INTCON, PEIE ; Enable Peripheral Interrupts BSF INTCON, GIE ; Enable all Interrupts ; MOVLW 0x0E MOVWF T1CON ; Enable T1 Oscillator, Ext Clock, Async, prescaler = 1 BSF T1CON, TMR1ON ; Turn Timer1 ON ; zzz SLEEP GOTO zzz ; Sleep, wait for TMR1 interrupt

© 1997 Microchip Technology Inc.

DS00580C-page 3

WORLDWIDE SALES & SERVICE
AMERICAS
Corporate Office
Microchip Technology Inc. 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 602-786-7200 Fax: 602-786-7277 Technical Support: 602 786-7627 Web: http://www.microchip.com

ASIA/PACIFIC
Hong Kong
Microchip Asia Pacific RM 3801B, Tower Two Metroplaza 223 Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-2-401-1200 Fax: 852-2-401-3431

EUROPE
United Kingdom
Arizona Microchip Technology Ltd. Unit 6, The Courtyard Meadow Bank, Furlong Road Bourne End, Buckinghamshire SL8 5AJ Tel: 44-1628-851077 Fax: 44-1628-850259

France
Arizona Microchip Technology SARL Zone Industrielle de la Bonde 2 Rue du Buisson aux Fraises 91300 Massy, France Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79

Atlanta
Microchip Technology Inc. 500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770-640-0034 Fax: 770-640-0307

India
Microchip Technology India No. 6, Legacy, Convent Road Bangalore 560 025, India Tel: 91-80-229-0061 Fax: 91-80-229-0062

Boston
Microchip Technology Inc. 5 Mount Royal Avenue Marlborough, MA 01752 Tel: 508-480-9990 Fax: 508-480-8575

Korea
Microchip Technology Korea 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea Tel: 82-2-554-7200 Fax: 82-2-558-5934

Germany
Arizona Microchip Technology GmbH Gustav-Heinemann-Ring 125 D-81739 Müchen, Germany Tel: 49-89-627-144 0 Fax: 49-89-627-144-44

Chicago
Microchip Technology Inc. 333 Pierce Road, Suite 180 Itasca, IL 60143 Tel: 630-285-0071 Fax: 630-285-0075

Italy
Arizona Microchip Technology SRL Centro Direzionale Colleone Palazzo Taurus 1 V. Le Colleoni 1 20041 Agrate Brianza Milan, Italy Tel: 39-39-6899939 Fax: 39-39-6899883

Shanghai
Microchip Technology RM 406 Shanghai Golden Bridge Bldg. 2077 Yan'an Road West, Hongiao District Shanghai, PRC 200335 Tel: 86-21-6275-5700 Fax: 86 21-6275-5060

Dallas
Microchip Technology Inc. 14651 Dallas Parkway, Suite 816 Dallas, TX 75240-8809 Tel: 972-991-7177 Fax: 972-991-8588

Singapore
Microchip Technology Taiwan Singapore Branch 200 Middle Road #10-03 Prime Centre Singapore 188980 Tel: 65-334-8870 Fax: 65-334-8850

JAPAN
Microchip Technology Intl. Inc. Benex S-1 6F 3-18-20, Shin Yokohama Kohoku-Ku, Yokohama Kanagawa 222 Japan Tel: 81-4-5471- 6166 Fax: 81-4-5471-6122 5/8/97

Dayton
Microchip Technology Inc. Two Prestige Place, Suite 150 Miamisburg, OH 45342 Tel: 937-291-1654 Fax: 937-291-9175

Los Angeles
Microchip Technology Inc. 18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 714-263-1888 Fax: 714-263-1338

Taiwan, R.O.C
Microchip Technology Taiwan 10F-1C 207 Tung Hua North Road Taipei, Taiwan, ROC Tel: 886 2-717-7175 Fax: 886-2-545-0139

New York
Microchip Technology Inc. 150 Motor Parkway, Suite 416 Hauppauge, NY 11788 Tel: 516-273-5305 Fax: 516-273-5335

San Jose
Microchip Technology Inc. 2107 North First Street, Suite 590 San Jose, CA 95131 Tel: 408-436-7950 Fax: 408-436-7955

Toronto
Microchip Technology Inc. 5925 Airport Road, Suite 200 Mississauga, Ontario L4V 1W1, Canada Tel: 905-405-6279 Fax: 905-405-6253

All rights reserved. © 1997, Microchip Technology Incorporated, USA. 6/97
Information contained in this publication regarding device applications and the like is intended for suggestion only and may be superseded by updates. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Microchip's products as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. The Microchip logo and name are registered trademarks of Microchip Technology Inc. in the U.S.A. and other countries. All rights reserved. All other trademarks mentioned herein are the property of their respective companies.

M

DS00580C-page 4

© 1997 Microchip Technology Inc.