Code Hopping Decoder Using A PIC16C56: Key Features
Code Hopping Decoder Using A PIC16C56: Key Features
Code Hopping Decoder Using A PIC16C56: Key Features
KEY FEATURES
Author: Steven Dawson • Stand-alone decoder
Microchip Technology Inc. • Compatible with Microchip HCS200, HCS201,
HCS300, HCS301, and NTQ106 encoders
• Automatic baud rate detection
OVERVIEW • Automatic encoder type detection
This application note fully describes the working of a • Four function outputs
code hopping decoder implemented on a Microchip • Six learnable transmitters
PIC16C56 microcontroller. Background is given on the • RC Oscillator
various KEELOQ® code hopping encoders that can be
used with the decoder, the decoder hardware described,
and descriptions of the various software modules com-
prising the system. The software can be used to imple-
ment a stand-alone decoder or integrated with full
function security systems. The decoder supports the
Microchip HCS200, HCS201, HCS300, HCS301, and
NTQ106 KEELOQ Code Hopping Encoders.
Notice:
This is a non-restricted version of Application Note AN642 which is available under the
KEELOQ License Agreement. The license agreement can be ordered from the Microchip
Literature Center as DS40149.
RF S0
Receiver RFIN S1
S2
S3
PIC16C56
Learn
CS Indication
EEPROM CLK
DIO
Learn
Init
PWM Format Figure 2 shows the sampling points when sampling data.
The first and last elements are used exclusively to verify
In general, all KEELOQ encoders share a common
the integrity of the received signal. The first element (sam-
transmission format.
ple point A) is always high, the second (sample point B) is
• A preamble to improve biasing of decision the complement of the data bit being sent, and the final
thresholds in super-regenerative receivers. The pre- element (sample point C) is always low. Because the
amble consists of alternate on and off periods, each period between the low portion of a bit (sample point C)
lasting as long as a single elemental period. and the rising edge of the following bit (sample point X)
• A calibration header, consisting of a low period of 10 can vary somewhat, the rising edge of the first element
elemental periods. Calibration actions should be (sample point X) is used to resynchronize the receiving
performed on the low period of the header to ensure routine to each incoming bit.
correct operation with header chopping. If random noise is being received, the probability of a set
• A string of 56 or 66 pulse width modulated bits, each of three samples producing a valid combination is only 2-2
consisting of three elements. The first element is = 1/4. For a string of 56 bits, the corresponding figure is
high, the second contains the data transmitted and 2-112 > 2 x 10-34. For longer strings, the probability is con-
is either high or low, the third element is always low. siderably less.
• A guard period is usually left between the Integrity checking on incoming signals is important. Code
transmissions. During this period nothing is hopping signals require significant processing, as well as
transmitted by the encoder. EEPROM access, to decrypt. Unnecessary processing
can be avoided by not attempting to decrypt incoming
codes that have bit errors.
2te te
1
X A B C
te 2te
PIC16C56
stored for the HCS300/301 includes the overflow bits. 4 MCLR OSC IN 15
5 GND VCC 14
The second portion of validation involves checking syn- 6 S0 FUNC OK 13
chronization information for that particular encoder. The 7 S1 EE CS 12
synchronization counter transmitted by all encoders is 16 8 S2 EE CK 11
bits long. Two copies of the full synchronization counter 9 S3 EE DIO 10
are stored for all valid encoders. The storing of two copies
of the synchronization information protects the decoder
from loosing synchronization with an encoder if one of the
counters is corrupted.
Reset
Get Learn
Pointer
MAIN
Delete TX
Yes At Learn
Reset Due To
Failed Learn? Position
WIPE_TX
No
Loop Back
Point
MAIN2
Learn
Pressed?
M_LOOP2-> Learn Routine
TST_LEARN Yes
No
Check For
Encoder TX
RECEIVE
Received 56
Or 66 Bits?
No M_LOOP2
Yes
Transmission
Validation
1 2 3 4 5 6 7 4 5
High Yes
3
Calibration
Counter/10
RCV6
No
Load
Cal Counter
RCV7
Receive
Data
DL1
Receive
Data
RCV7
3
Wait Half
Bit Period
DL1
Low
Input?
High
4
Wait Full
Bit Period
DL2
High
Input?
Low
5
Data = 1 Data = 0
Wait Full
Bit Period
DL3
High
7 Input?
Low
High 6
Low Input? No
RCV9/RCV10 Last Bit?
No Yes
Time-out?
Yes
No Received
Invalid 56 Bits?
RMT0
Yes
Reception
Cleanup Complete
RMT2 RMT1
The confidential and proprietary information contained in this section of AN642 has
been removed. The full application note is available under a license agreement and
can be ordered as DS40149 from Microchip Technology Inc.
TIMING PARAMETERS
TABLE 7: TIMING PARAMETERS
Parameter Typical Unit
Output activation duration 524 ms
Output pause if new function code received 131 ms
Erase all duration 8.4 s
Learn mode time-out 33.6 s
Learn successful LED flash duration 4.2 s
Learn successful LED flash rate 3.8 Hz
Learn failure LED on duration 1 s
FIGURE A1:
APPENDIX A:
AN661
U2 VCC
J1 D5 LM7805
12V 1 VO
VI G
VCC U4 2
1N4004/7 C2 N C3
LOW VOLTAGE DETECTOR 3
100 µF D 100 µF
J2
R3 VCC
1k 1 D6 LEARN
R8
RF INPUT
R4 D1 S0
U5
14 R5 D3 S1
R1 4 17
10k MCLR V RA0 R6 D4
18 S2
3
C RA1
T0CKI C RA2 1
2 R7 D2 S3
16 RA3
OSC1 R9 D7 FUNC OK
RB0 6
15 7
CLKOUT RB1
RB2 8
RB3 9
RB4 10
G RB5 11
C1 N RB6 12
10 pF D RB7 13
5 VCC VCC
PIC16C56
U1
1997 Microchip Technology Inc.
R2
10k 1 CS VCC 8
2 SK NC 7
3 DI NC 6
4 DO GND 5
2
S1 93C46
LEARN INIT SERIAL EEPROM
1
1997 Microchip Technology Inc.
FIGURE A2:
12V U2 VCC
J1 D5 LM7805
12V
12V 1 VO
VI G MOTOR CONTROL OUT J2
2 N 1
3 1N4004/7 C2 C3
GND 100 µF D 100 µF K2 CON1
DI NC NPN
AN661
D10 2 4 5
LEARN DO GND
S1
LEARN INIT 93C46
SERIAL EEPROM
1 GARAGE LIGHT
WORLDWIDE SALES & SERVICE
AMERICAS ASIA/PACIFIC EUROPE
Corporate Office Hong Kong United Kingdom
Microchip Technology Inc. Microchip Asia Pacific Arizona Microchip Technology Ltd.
2355 West Chandler Blvd. RM 3801B, Tower Two Unit 6, The Courtyard
Chandler, AZ 85224-6199 Metroplaza Meadow Bank, Furlong Road
Tel: 602-786-7200 Fax: 602-786-7277 223 Hing Fong Road Bourne End, Buckinghamshire SL8 5AJ
Technical Support: 602 786-7627 Kwai Fong, N.T., Hong Kong Tel: 44-1628-851077 Fax: 44-1628-850259
Web: http://www.microchip.com Tel: 852-2-401-1200 Fax: 852-2-401-3431 France
Atlanta India Arizona Microchip Technology SARL
Microchip Technology Inc. Microchip Technology India Zone Industrielle de la Bonde
500 Sugar Mill Road, Suite 200B No. 6, Legacy, Convent Road 2 Rue du Buisson aux Fraises
Atlanta, GA 30350 Bangalore 560 025, India 91300 Massy, France
Tel: 770-640-0034 Fax: 770-640-0307 Tel: 91-80-229-0061 Fax: 91-80-229-0062 Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79
Boston Korea Germany
Microchip Technology Inc. Microchip Technology Korea Arizona Microchip Technology GmbH
5 Mount Royal Avenue 168-1, Youngbo Bldg. 3 Floor Gustav-Heinemann-Ring 125
Marlborough, MA 01752 Samsung-Dong, Kangnam-Ku D-81739 Müchen, Germany
Tel: 508-480-9990 Fax: 508-480-8575 Seoul, Korea Tel: 49-89-627-144 0 Fax: 49-89-627-144-44
Chicago Tel: 82-2-554-7200 Fax: 82-2-558-5934 Italy
Microchip Technology Inc. Shanghai Arizona Microchip Technology SRL
333 Pierce Road, Suite 180 Microchip Technology Centro Direzionale Colleone
Itasca, IL 60143 RM 406 Shanghai Golden Bridge Bldg. Palazzo Taurus 1 V. Le Colleoni 1
Tel: 630-285-0071 Fax: 630-285-0075 2077 Yan’an Road West, Hongiao District 20041 Agrate Brianza
Dallas Shanghai, PRC 200335 Milan, Italy
Tel: 86-21-6275-5700 Tel: 39-39-6899939 Fax: 39-39-6899883
Microchip Technology Inc.
Fax: 86 21-6275-5060
14651 Dallas Parkway, Suite 816
Dallas, TX 75240-8809 Singapore
Tel: 972-991-7177 Fax: 972-991-8588 Microchip Technology Taiwan
JAPAN
Singapore Branch Microchip Technology Intl. Inc.
Dayton Benex S-1 6F
200 Middle Road
Microchip Technology Inc. 3-18-20, Shin Yokohama
#10-03 Prime Centre
Two Prestige Place, Suite 150 Kohoku-Ku, Yokohama
Singapore 188980
Miamisburg, OH 45342 Kanagawa 222 Japan
Tel: 65-334-8870 Fax: 65-334-8850
Tel: 937-291-1654 Fax: 937-291-9175 Tel: 81-4-5471- 6166 Fax: 81-4-5471-6122
Taiwan, R.O.C
Los Angeles
Microchip Technology Taiwan 5/8/97
Microchip Technology Inc.
10F-1C 207
18201 Von Karman, Suite 1090
Tung Hua North Road
Irvine, CA 92612
Taipei, Taiwan, ROC
Tel: 714-263-1888 Fax: 714-263-1338
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
M
Tel: 905-405-6279 Fax: 905-405-6253
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.