Text preview for : Chien de garde.pdf part of PIONEER KEH-1850 KEH-1800 KEH-1800 X1M/UC KEH-1850 X1M/UC XM/ES X1M/ES ETC... ORDER NO. CRT2266



Back to : Pioneer Keh 1800 Keh 1850 | Home

TB004
Automatic Calibration of the WDT Time-out Period
Author: Stan D'Souza Advanced Microcontroller Technology Division

CONCLUSION
The calibration of the WDT is simple and takes very little overhead in a program. The code in Appendix A is written for a PIC16C84 device, but can be translated to work on any PIC16CXXX product. The code in Appendix B is written for the PIC16C5X family. RAM Used: 2 Bytes ROM Used: 50 Words Execution time: Up to a max. of 132 ms from start-up.

INTRODUCTION
The WDT timer is a simple RC timer with a typical time-out period of about 18 ms. This time-out period is dependent on Voltage, Temperature and Silicon process variations. Hence the tolerance on the time-out period is very wide: Min. of 9 ms to a Max. of 33 ms (please refer to appropriate datasheet for device dependent value). There are applications where an additional timer would be useful as an approximate time keeper, hence getting a more precise value of the WDT time-out is useful. This Tech Brief implements an automatic calibration of the WDT time-out period on start-up.

FIGURE 1: PROGRAM FLOWCHART

START

CodeByte = 0xA5? No

Yes

IMPLEMENTATION
The hardware used for this brief is the PICDEM1 board. It is assumed that the main processor oscillator is an accurate crystal or ceramic resonator running at 4 MHz. The program flowchart is depicted in Figure 1. A check is made to see if a certain Codebyte exists, if it does not then a power-up is assumed and the calibration is executed. Note that instead of using the 8-bit wide CodeByte, the PD bit in the STATUS register could also be used for this very same purpose. The calibration uses an internal timed 1 ms interval. To get a better resolution, the WDT is postscaled by 4 in order to measure a longer time period . Every 1 ms interval is kept track by incrementing the WDTValue. The WDT will eventually time-out and cause a reset. The value in WDTValue in then divided by 4 to get the exact WDT time-out period and displayed as a binary number on PORTB. In order to check for repeatability, just press the reset button on the PICDEM1 board and the whole calibration process will be repeated. A power-down, followed by a power-up will also have the same effect. CodeByte = 0xA5 WDTValue = 0 OPTION = 0B11111010

Wait 1 ms increment WDTValue

WDT Reset

WDTValue PORTB

LOOP

© 1996 Microchip Technology Inc.

DS91003A-page 1

This document was created with FrameMaker 4 0 4

TB004
APPENDIX A:
MPC "C" COMPILER BC.193 22-Aug-1995 PAGE 1

/* In this example, a PIC16C84s WDT is calibrated on startup for better accuracy. Accuracy is exact to +/- 0.25mS. The code written in C works on a PICDEM1 board. The WDT value is written to PORTB at the end of the calibration. The value is in binary. */ #pragma option v #include #pragma option +1; #define MAXROM 1019 #pragma memory ROM [MAXROM] #pragma memory RAM [36] #pragma option +1; #include #pragma option +l; 000D 000E char WdtValue; chr CodeByte; void InitPorts(void) { PORTB = 0; //configure PORTB as output TRISB = 0; } void main(void) { InitPorts(); if(CodeByte != 0xA5)

03FB 0005 03FB 000C 0024

@ 0x05; @ 0x0C;

0005 0006 0007 0008 0009

1283 0186 1683 0186 0008

BCF CLRF BSF CLRF RETURN

STATUS,RP0 PORTB STATUS,RP0 PORTB

000A 000B 000C 000D 000E 000F 0010 0010 0011 0012 0013 0014 0015 0016 0017

2005 30A5 1283 0212 1903 281E 1283 0191 30A5 0092 30FA 1683 0081 0064

CALL MOVLW BCF SUBWF BTFSC GOTO BCF CLRF MOVLW MOVWF MOVLW BSF MOVWF CLRWDT

0005h A5h STATUS,RP0 TMR1L,W STATUS,Z 001Eh STATUS,RP0 PIR2 A5h TMR1L FAh STATUS,RP0 TMR0

{ WdtValue = 0; CodeByte = 0xA5; OPTION = 0B11111010; // set WDT post scaler = 4

CLRWDT(); while(1) { 01h 002Ah Delay_Ms_4MHz(1); // delay for 1mS // count mS

0018 3001 0019 202A 001A 001A 1283 001B 0A91 001C 2818 001D 2827 001E 1283 001F 0192

MOVLW CALL

BCF INCF GOTO GOTO BCF CLRF

STATUS,RP0 PIR2 0018h 0027h STATUS,RP0 TMR1L

WdtValue++; } } else { CodeByte = 0;

DS91003A-page 2

© 1996 Microchip Technology Inc.

TB004
0020 0811 0021 0022 0023 0024 0025 0026 008D 0C8D 0C8D 303F 050D 0086 MOVF MOVWF RRF RRF MOVLW ANDWF MOVWF PIR2,W PIR1 PIR1 PIR1 3Fh PIR1,W PORTB } while(1) CLRWDT(); } void Delay_Ms_4MHz(registerw delay) { #asm BCF STATUS, RP0 ;1 MOVWF __WImage ;1 DLMS4M1 002C 30F9 002D 0084 DLMS4M2 002E 0000 002F 0B84 0030 282E 0031 0B8D 0032 282C 0033 0008 0000 3000 0001 008A 0002 280A RETURN MOVLW MOVWF GOTO 00h PCLATH 000Ah NOP DECFSZ GOTO FSR DLMS4M2 RADIX DEC MOVLW 249 MOVWF FSR ;Use decimal values ;1 ;1 ; 4 cycles ;1 ;1 ;2 ;1 ;2 PORTB = WdtValue >> 2; ; // divide by 4 for // exact timeout value

0027 0064 0028 2827 0029 0008

CLRWDT GOTO 0027h RETURN

// loop forever

0000 002A 1283 002B 008D

DECFSZ __WImage GOTO DLMS4M1 #endasm }

ROM USAGE MAP 0000 to 0002 0005 to 0033 Total ROM used 0032

Errors Warnings

: :

0 0

© 1996 Microchip Technology Inc.

DS91003A-page 3

TB004
APPENDIX B:
MPC "C" COMPILER BC.193 22-Aug-1995 PAGE 1

/* In this example, a PIC16C54s WDT is calibrated on startup for better accuracy. Accuracy is exact to +/- 0.25 mS. The code written in C works on a PICDEM1 board. The WDT value is written to PORTB at the end of the calibration. The value is in binary. */ #pragma option v #include #pragma option +l; // Enable header to show branch islands #define MAXROM 512 #pragma memory ROM [MAXROM] @ 0x00; #pragma memory RAM [24] @ 0x08; // Reserve byte for ; // __WImage #pragma option +l; #include #pragma option +l;

0200 0000 0200 0008 0018

0009 000A

char WdtValue; char CodeByte;

0000 0001 0002 0003

0066 0C00 0006 0800

CLRF MOVLW TRIS RETLW

PORTB 00h PORTB 00h

void InitPorts(void) { PORTB = 0; //set PORTB as output __TRIS(0,PORTB); } void main(void) { InitPorts(); if (CodeByte != 0xA5)

0004 0005 0006 0007 0008 0009 0009 000A 000B 000C 000D 000E

0900 0CA5 008A 0643 0A14 0069 0CA5 002A 0CFA 0002 0004

CALL MOVLW SUBWF BTFSC GOTO CLRF MOVLW MOVWF MOVLW OPTION CLRWDT

0000h A5h 0A,W STATUS,Z 0014h 09 A5h 0A FAh

{ WdtValue = 0; CodeByte = 0xA5; __OPTION(0B11111010); // set WDT post scaler = 4 CLRWDT(); while(1) {

000F 0010 0011 0011 0012

0C01 091F 02A9 0A0F

MOVLW CALL INCF GOTO GOTO

01h 001Fh 09 000Fh 001Ch } else { CodeByte = 0; PORTB = WdtValue >> 2; Delay_Ms_4MHz(1); // delay for 1 mS WdtValue++; // count 1ms delays }

0013 0A1C

0014 006A 0015 0209 0016 0027 0017 0327

CLRF MOVF MOVWF RRF

0A 09,W PORTC 07

//divide by 4 for exact // timeout value

DS91003A-page 4

© 1996 Microchip Technology Inc.

TB004
0018 0019 001A 001B 0327 0C3F 0147 0026 RRF MOVLW ANDWF MOVWF 07 3Fh 07,W PORTB } while(1) CLRWDT(); // loop forever }

001C 0004 001D 0A1C 001E 0800

CLRWDT GOTO 001Ch RETLW 00h

0000 001F 0000 0020 0027

void Delay_Ms_4MHz(registerw delay) { #asm NOP ;1 MOVWF __WImage ;1 DLMS4M1 RADIX DEC ;Use decimal values MOVLW 249 ;1 MOVWF __FSRImage ;1 DLMS4M2 ;4 cycles NOP ;1 DECFSZ __FSRImage ;1 goto DLMS4M2 ;2 DECFSZ __WImage goto DLMS4M1 #endasm } ;1 ;2

0021 0CF9 0022 0028

0023 0000 0024 02E8 0025 0A23 0026 02E7 0027 0A21 0028 0800 01FF 0A04 RETLW GOTO 00h

0004h

ROM USAGE MAP 0000 to 0028 01FF to 01FF Total ROM used 002A

Errors Warnings

: :

0 0

© 1996 Microchip Technology Inc.

DS91003A-page 5

TB004
NOTES:

DS91003A-page 6

© 1996 Microchip Technology Inc.

TB004
NOTES:

© 1996 Microchip Technology Inc.

DS91003A-page 7

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 Atlanta Microchip Technology Inc. 500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770 640-0034 Fax: 770 640-0307 Boston Microchip Technology Inc. 5 Mount Royal Avenue Marlborough, MA 01752 Tel: 508 480-9990 Fax: 508 480-8575 Chicago Microchip Technology Inc. 333 Pierce Road, Suite 180 Itasca, IL 60143 Tel: 708 285-0071 Fax: 708 285-0075 Dallas Microchip Technology Inc. 14651 Dallas Parkway, Suite 816 Dallas, TX 75240-8809 Tel: 972 991-7177 Fax: 972 991-8588 Dayton Microchip Technology Inc. Suite 150 Two Prestige Place Miamisburg, OH 45342 Tel: 513 291-1654 Fax: 513 291-9175 Los Angeles Microchip Technology Inc. 18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 714 263-1888 Fax: 714 263-1338 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

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 India Microchip Technology India No. 6, Legacy, Convent Road Bangalore 560 025 India Tel: 91 80 529 4846 Fax: 91 80 559 9840 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 Shanghai Microchip Technology Unit 406 of Shanghai Golden Bridge Bldg. 2077 Yan'an Road West, Hongiao District Shanghai, Peoples Republic of China Tel: 86 21 6275 5700 Fax: 011 86 21 6275 5060 Singapore Microchip Technology Taiwan Singapore Branch 200 Middle Road #10-03 Prime Centre Singapore 188980 Tel: 65 334 8870 Fax: 65 334 8850 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

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 Germany Arizona Microchip Technology GmbH Gustav-Heinemann-Ring 125 D-81739 Muenchen, Germany Tel: 49 89 627 144 0 Fax: 49 89 627 144 44 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 689 9883

JAPAN
Microchip Technology Intl. Inc. Benex S-1 6F 3-18-20, Shin Yokohama Kohoku-Ku, Yokohama Kanagawa 222 Japan Tel: 81 45 471 6166 Fax: 81 45 471 6122

11/25/96

All rights reserved. © 1996, Microchip Technology Incorporated, USA. 11/96
Printed on recycled paper.
Information contained in this publication regarding device applications and the like is intended through 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. All rights reserved. All other trademarks mentioned herein are the property of their respective companies.

DS91003A-page 8

© 1996 Microchip Technology Inc.