Code Hopping Decoder Using a PIC16C56



Similar documents
AN709. System Level Design Considerations When Using I 2 C TM Serial EEPROM Devices INTRODUCTION INSURING BUS-FREE DURING POWER-UP

TC1270/TC Pin µp Reset Monitors. Features. Package Type. General Description. Applications. Device Selection Table. Typical Operating Circuit

AN688. Layout Tips for 12-Bit A/D Converter Application GETTING A GOOD START INTRODUCTION. Microchip Technology Inc. / 2 MCP602

AN680. Passive RFID Basics INTRODUCTION DEFINITIONS. Modulation. Reader. Tag. Carrier. Microchip Technology Inc.

Technical Brief Secure Learning RKE Systems Using KEELOQ Encoders

M Floating Point to ASCII Conversion

TCM809/TCM Pin Microcontroller Reset Monitors. General Description. Features. Applications. Pin Configurations. Typical Application Circuit

AN831. Matching Small Loop Antennas to rfpic Devices INTRODUCTION CALCULATING THE LOOP RADIATION RESISTANCE AND LOSS RESISTANCE EQUATION 2:

How to Implement ICSP Using PIC12C5XX OTP MCUs VDD. GP3/MCLR/VPP ICSP Connector. To application circuit Isolation circuits

FLASH Memory Programming Specification TABLE 1-1: PIN DESCRIPTIONS (DURING PROGRAMMING): PIC16F72

AN699. Anti-Aliasing, Analog Filters for Data Acquisition Systems ANALOG VERSUS DIGITAL FILTERS INTRODUCTION. Microchip Technology Inc.

M Floating Point to ASCII Conversion

How To Use A Temperature Sensor On A Microchip Computer (For Microchip)

AN713. Controller Area Network (CAN) Basics INTRODUCTION CAN PROTOCOL BASICS CAN OVERVIEW

AN562. Using Endurance Predictive Software. Using the Microchip Endurance Predictive Software INTRODUCTION TOTAL ENDURANCE PREDICTIVE SOFTWARE

A CAN Physical Layer Discussion

AN844. Simplified Thermocouple Interfaces and PICmicro MCUs INTRODUCTION. Linearization THERMOCOUPLE CIRCUITS. Absolute Temperature Reference.

Voltage-to-Frequency/Frequency-to-Voltage Converter

PIC16F877A. FLASH Memory Programming Specification 1.0 PROGRAMMING THE PIC16F87XA

TCM V To ±10V Voltage Converter. General Description. Features. Applications. Package Type. Typical Operating Circuit

TC652/TC653. Integrated Temperature Sensor & Brushless DC Fan Controller with FanSense Detect & Over-Temperature. Features.

Uninstalling Incorrect USB Device Drivers

AN685. Thermistors in Single Supply Temperature Sensing Circuits INTRODUCTION THERMISTOR OVERVIEW. Current-Over-Time Mode. Voltage-Versus-Current Mode

EEPROM Memory Programming Specification

TB026. Calculating Program Memory Checksums Using a PIC16F87X ACCESSING MEMORY INTRODUCTION. PIC16C7X vs. PIC16F87X. Microchip Technology Inc.

TB040. Fast Integer Square Root THE ALGORITHM INTRODUCTION SQUARE ROOT FLOW CHART

HCS200. KEELOQ Code Hopping Encoder DESCRIPTION FEATURES PACKAGE TYPES BLOCK DIAGRAM. Security. Operating. Other. Typical Applications

AN717. Building a 10-bit Bridge Sensing Circuit using the PIC16C6XX and MCP601 Operational Amplifier

Driving Power MOSFETs in High-Current, Switch Mode Regulators V GS(TH) In equation form: and. I G = Q G /t (transition) where: For example:

AN679. Temperature Sensing Technologies SO MANY TEMPERATURE SENSORS INTRODUCTION. Microchip Technology Inc.

TB056. Demonstrating the Set_Report Request With a PS/2 to USB Keyboard Translator Example INTRODUCTION. The Set_Report Request.

AN1303. Software Real-Time Clock and Calendar Using PIC16F1827 DATA INTERFACE INTRODUCTION IMPLEMENTATION INTERNAL REGISTER MAP

TB3016. Using the PIC MCU CTMU for Temperature Measurement IMPLEMENTATION BASIC PRINCIPLE MEASUREMENT CIRCUIT

WORKSHOP-IN-A-BOX 2: LOW POWER SOLUTIONS DEMONSTRATION BOARD

AN1275. KEELOQ with Advanced Encryption Standard (AES) Receiver/Decoder KEY FEATURES OVERVIEW. Microchip Technology Inc.

TC110. PFM/PWM Step-Up DC/DC Controller. Features. General Description. Applications. Functional Block Diagram. Device Selection Table

Analog-to-Digital Converters

AN826. Crystal Oscillator Basics and Crystal Selection for rfpic TM and PICmicro Devices INTRODUCTION OSCILLATOR MODELS. Microchip Technology Inc.

AN1286. Water-Resistant Capacitive Sensing INTRODUCTION THEORY OF OPERATION. Sensing Steps. Sensing Steps Description DESIGN

dspic30f3012/3013 dspic30f3012/3013 Rev. B0 Silicon Errata dspic30f3012/3013 (Rev. B0) Silicon Errata Silicon Errata Summary

HCS301. KEELOQ Code Hopping Encoder DESCRIPTION FEATURES PACKAGE TYPES HCS301 BLOCK DIAGRAM. Security. Operating. Other. Typical Applications

AN956. Migrating Applications to USB from RS-232 UART with Minimal Impact on PC Software OVERVIEW INTRODUCTION. Microchip Technology Inc.

AN905. Brushed DC Motor Fundamentals INTRODUCTION PRINCIPLES OF OPERATION. Stator. Rotor SIMPLE TWO-POLE BRUSHED DC MOTOR. Microchip Technology Inc.

TB055. PS/2 to USB Mouse Translator IMPLEMENTATION OVERVIEW. Hardware FIGURE 1: PS/2 TO USB MOUSE TRANSLATOR HARDWARE DIAGRAM (1)

AN1142. USB Mass Storage Class on an Embedded Host INTRODUCTION. USB Mass Storage Class. Overview

AN1265. KEELOQ with AES Microcontroller-Based Code Hopping Encoder INTRODUCTION DUAL ENCODER OPERATION BACKGROUND FUNCTIONAL INPUTS AND

High Speed CAN Transceiver. 8 Externally controlled slope for reduced RFI emissions Detection of ground fault (permanent dominant) on TXD input

Operational Amplifier Topologies and DC Specifications

AN723. Operational Amplifier AC Specifications and Applications INTRODUCTION FREQUENCY DOMAIN SPECIFICATIONS

AN873. Using the MCP2515 CAN Developer s Kit INTRODUCTION. PC Node. PICmicro Node BLOCK DIAGRAM OF MCP2515 DEVELOPMENT BOARD

Recommended Usage of Microchip 23X256/23X640 SPI Serial SRAM Devices RECOMMENDED CONNECTIONS FOR 23X256,23X640 SERIES DEVICES VCC 23X256/ HOLD.

Installing and Licensing MPLAB XC C Compilers

AN1470. Manchester Decoder Using the CLC and NCO ABSTRACT INTRODUCTION MANCHESTER ENCODED DATA (AS PER G.E. THOMAS)

PIC10F200/202/204/206

AN Wire Communication with PIC Microcontroller INTRODUCTION. OVERVIEW OF THE 1-Wire BUS. 1-Wire Protocol. Prerequisites

MCP3021. Low Power 10-Bit A/D Converter With I 2 C Interface. Description. Features. Applications. Functional Block Diagram.

Universal Programming Module 2

TC648. Fan Speed Controller with Auto-Shutdown and Over-Temperature Alert. Package Types. Features TC648. General Description.

Interfacing Pressure Sensors to Microchip s Analog Peripherals V OUT- Silicon Substrate

RC Model Aircraft Motor Control. Solutions. PWM Rate khz 1 PIC12C508A limited None None PIC16F Yes Yes Yes 32, 8, 2

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

PIC32 Microcontroller Families

Timers: Timer0 Tutorial (Part 1)

Integrated Development Environment

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

AN1325. mtouch Metal Over Cap Technology THEORY OF OPERATION INTRODUCTION CROSS SECTION OF METAL OVER CAPACITIVE (UNPRESSED)

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AN974 APPLICATION NOTE

Software Real Time Clock Implementation on MC9S08LG32

AN687. Precision Temperature-Sensing With RTD Circuits RTD OVERVIEW INTRODUCTION EQUATION 1:

AN645. PIC16C57 Based Code Hopping Security System PINOUT OVERVIEW FEATURES BLOCK DIAGRAM RECOMMENDED READING

AN734. Using the PICmicro SSP for Slave I 2 C TM Communication INTRODUCTION THE I 2 C BUS SPECIFICATION

In-Circuit Serial Programming (ICSP ) Guide

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Flexible Active Shutter Control Interface using the MC1323x

HT12A/HT12E 2 12 Series of Encoders

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

MCP2515 Development Kit User s Guide

TCP/IP Networking: Web-Based Status Monitoring

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

MCP3204/ V 4-Channel/8-Channel 12-Bit A/D Converters with SPI Serial Interface. Features. Description. Applications. Functional Block Diagram

HCS361. KEELOQ Code Hopping Encoder. FEATURES Security DESCRIPTION PACKAGE TYPES HCS361 BLOCK DIAGRAM DESCRIPTION

Uninstalling Incorrect USB Device Drivers

TC4421/TC4422. Functional Block Diagram. TC4421 Inverting. TC4422 Non-Inverting V DD. 300 mv Output. Input 4.7V. GND Effective. Input.

Tire pressure monitoring

TC1047/TC1047A. Precision Temperature-to-Voltage Converter. General Description. Applications. Block Diagram. Features.

Radiowe zdalne sterowanie

Fondamenti su strumenti di sviluppo per microcontrollori PIC

AN1156. Battery Fuel Measurement Using Delta-Sigma ADC Devices INTRODUCTION REVIEW OF BATTERY CHARGING AND DISCHARGING CHARACTERISTICS

HT6221/HT6222 Multi-Purpose Encoders

IRTC Compensation and 1 Hz Clock Generation

AN880. Converting from 8051 to Microchip Assembler: A Quick Reference INTRODUCTION

Section 15. Input Capture

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AN3265 Application note

General Porting Considerations. Memory EEPROM XRAM

MX PIC24F Educational Module User Manual

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AN3998 Application note

AN885. Brushless DC (BLDC) Motor Fundamentals INTRODUCTION CONSTRUCTION AND OPERATING PRINCIPLE. Stator. Padmaraja Yedamale Microchip Technology Inc.

Transcription:

Code Hopping Decoder Using a PIC6C56 AN66 Author: OVERVIEW Steven Dawson Microchip Technology Inc. This application note fully describes the working of a code hopping decoder implemented on a Microchip PIC6C56 microcontroller. Background is given on the various KEELOQ code hopping encoders that can be used with the decoder, the decoder hardware described, and descriptions of the various software modules comprising the system. The software can be used to implement a stand-alone decoder or integrated with full function security systems. The decoder supports the Microchip HCS200, HCS20, HCS300, HCS30, HCS360, HCS36 and HCS40 KEELOQ Code Hopping Encoders. KEY FEATURES Stand-alone decoder Compatible with Microchip HCS200, HCS20, HCS300, HCS30, HCS360, HCS36 and HCS40 encoders Automatic baud rate detection Automatic encoder type detection Four function outputs Six learnable transmitters RC Oscillator tice: This is a non-restricted version of Application te AN642 which is available under the KEELOQ License Agreement. The license agreement can be ordered from the Microchip Literature Center as DS4049. KEELOQ is a registered trademark of Microchip Technology, Inc. Microchip s Secure Data Products are covered by some or all of the following patents: Code hopping encoder patents issued in Europe, U.S.A., and R.S.A. U.S.A.: 5,57,87; Europe: 045978; R.S.A.: ZA93/4726 Secure learning patents issued in the U.S.A. and R.S.A. U.S.A.: 5,686,904; R.S.A.: 95/5429 998 Microchip Technology Inc. DS0066B-page

INTRODUCTION TO KEELOQ ENCODERS All KEELOQ encoders use the KEELOQ code hopping technology to make each transmission by an encoder unique. The encoder transmissions have two parts. The first part changes each time the encoder is activated and is called the hopping code part. The second part is the serial number of the encoder, identifying it to a decoder. Hopping Code The Hopping Code contains function information, a discrimination value, and a synchronization counter. This information is encrypted by an encryption algorithm before being transmitted. A 64-bit encryption key is used by the encryption algorithm. If one bit in the data that is encrypted changes, the result is that an average of half the bits in the output will change. As a result, the hopping code changes dramatically for each transmission and can not be predicted. Function Information The encoder transmits up to four bits of function information. Up to 5 different functions are available (0000 is related to the reset condition in all the current encoders, and can never be transmitted). Discrimination Value Stored in the encoder EEPROM, this information is used to check integrity of decryption operation in the decoder. If known information is inserted into the transmitted string before encryption, the same information can be used at the decoder to check whether the information has been decrypted correctly. In the Microchip HCS encoders, up to 2 bits (including overflow bits) are available. Synchronization Counters The transmitted word contains a 6-bit synchronization counter. The synchronization information is used at the decoder to determine whether a transmission is valid, or a repetition of a previous transmission. Previous codes are rejected to safeguard against code grabbers. The HCS300/30 encoder transmits two overflow bits which may be used to extend the range of the synchronization counter from 65,536 to 96,608 button operations. Fixed Code Serial Number The encoder s serial number is transmitted every time the button is pressed. The serial number is transmitted unencrypted as part of the transmission, and serves to identify the encoder to the decoder. The number can be used during learning operations to calculate the key to be used for decrypting the transmissions. Other Status and Function formation In The HCS300/30 encoders include provision for four bits of function information and two status bits in the fixed code portion of its transmission. The two status bits indicate whether a repeated transmission is being sent, and whether the battery voltage is low. The HCS200/20 does not send repeated transmission information and the bit is permanently set to 0. Transmission Format Table contains a summary of the information contained in transmissions from each of the KEELOQ encoders that can be learned by the Microchip decoder. FIGURE : BLOCK DIAGRAM RF Receiver RFIN S0 S S2 S3 PIC6C56 EEPROM CS CLK DIO Learn Indication Learn Init DS0066B-page 2 998 Microchip Technology Inc.

TABLE : TABLE 2: TABLE 3: TABLE 4: TABLE 5: TABLE 6: TABLE 7: KEELOQ ENCODER TRANSMISSION SUMMARY HCS200/20 # of bits HCS200/20 AND HCS300/30 CODE HOPPING TRANSMISSION FORMAT HCS200/20 AND HCS300/30 SEED TRANSMISSION FORMAT HCS360/36 CODE HOPPINGTRANSMISSION FORMAT HCS360/36 SEED TRANSMISSION FORMAT HCS40 CODE HOPPING TRANSMISSION FORMAT HCS40 SEED TRANSMISSION FORMAT HCS300/30 # of bits HCS360/36 # of bits HCS40 # of bits Total Transmission Length 66 66 67 69 Code Hopping Portion 32 32 32 32 Sync Counter 6 6 6 6 Discrimination bits 2 0 8 0 User Bits 0 0 2 0 Overflow Bits 0 2 2 Independent Mode 0 0 0 Function Code 4 4 4 4 Fixed Portion 34 34 35 37 Serial number 28 28 28/32 28/32 Function Code 4 4 4/0 4/0 Low Voltage Indicator Repeat Bit 0 0 CRC 0 0 2 2 Queue Bits 0 0 0 2 Code Hopping Portion Fixed Portion Sync Counter Discrimination Func Serial Number Func VLOW REPT Sync Counter Sync Counter Seed Portion Fixed Portion Seed Serial Number Func VLOW REPT Code Hopping Portion Discrimination OVR, IND Seed Portion Seed (48 bits) Code Hopping Portion Discrimination OVR Func Func Seed Portion Seed (60 bits) Serial Number (28/32 bits) Fixed Portion Serial Number (2/6 MS bits) Serial Number (28/32 bits) Fixed Portion Fixed Portion Func (4/0 bits) Func (4/0 bits) Func (4/0 bits) VLOW REPT VLOW REPT VLOW CRC QUE Fixed Portion Func (4/0 bits) VLOW CRC QUE 998 Microchip Technology Inc. DS0066B-page 3

PWM Format In general, all KEELOQ encoders share a common transmission format. A preamble to improve biasing of decision thresholds in super-regenerative receivers. The preamble consists of alternate on and off periods, each lasting as long as a single elemental period. A calibration header, consisting of a low period of 0 elemental periods. Calibration actions should be performed on the low period of the header to ensure correct operation with header chopping. A string of 66 pulse width modulated bits, each consisting of three elements. The first element is high, the second contains the data transmitted and is either high or low, the third element is always low. A guard period is usually left between the transmissions. During this period nothing is transmitted by the encoder. Figure 2 shows the sampling points when sampling data. The first and last elements are used exclusively to verify the integrity of the received signal. The first element (sample point A) is always high, the second (sample point B) is the complement of the data bit being sent, and the final element (sample point C) is always low. Because the period between the low portion of a bit (sample point C) and the rising edge of the following bit (sample point X) can vary somewhat, the rising edge of the first element (sample point X) is used to resynchronize the receiving routine to each incoming bit. If random noise is being received, the probability of a set of three samples producing a valid combination is only 2-2 = /4. For a string of 56 bits, the corresponding figure is 2-34. For longer strings, the probability is considerably less. Integrity checking on incoming signals is important. Code hopping signals require significant processing, as well as EEPROM access, to decrypt. Unnecessary processing can be avoided by not attempting to decrypt incoming codes that have bit errors. FIGURE 2: KEELOQ PWM TRANSMISSION FORMAT Bit Format I Sampling Points 0 2t e t e X A B C t e 2t e DS0066B-page 4 998 Microchip Technology Inc.

IMPLEMENTATION The Microchip decoder s primary hardware componenets are a PIC6C56 RISC microcontroller and a 93LC46B EEPROM. However, this solution can be implemented in any PICmicro microcontroller with at least K words of programming. The operating frequency of the controller is 4 MHz. The microcontroller is used to capture transmissions from the various encoders, decrypt transmissions captured, and check the validity of the transmission based on the information in the decrypted transmission and information stored in the EEPROM. If a transmission from a valid encoder is received, the Microchip decoder activates the outputs dictated by the transmission. Encoder information, such as serial number, synchronization information, and decryption key are stored externally in an EEPROM. The EEPROM used is a Microchip 93LC46B CMOS serial EEPROM. The information stored in the EEPROM is encrypted to protect the decoders from cloning. The EEPROM encryption is less secure than the KEELOQ code hopping algorithm. A more secure implementation of the decoder would be to modify the software in the application note and use a PIC6CXX with an internal EEPROM such as a PIC6C84. In this way communication between the PIC6C56 and EEPROM cannot be monitored. As can be seen from the section on encoder transmissions there are differences in the transmission formats of the different encoders that are compatible with the system. The following section summarizes how the differences in transmitted data are dealt with by the decoder. As the serial number information follows after the code hopping portion of the transmission, any number of serial number bits can be received and processed. In the Microchip decoder described 28 bits of the serial number are stored. The serial number is used to identify the memory block used to store the 64-bit decryption key for a particular encoder because of the relationship between serial number and decryption key. In other words, the serial number is stored with the key. When a transmission is received, the decoder finds the correct memory block by checking all blocks until a matching serial number is found. The key is then retrieved from that particular memory block. A serial number of 0000000 6 is considered invalid. Validation of a received transmission consists of two parts. The first includes checking the integrity of the decryption operation. Here the decoder compares the 2-bit discrimination value received with the stored discrimination value. The discrimination value stored for the HCS300/30 includes the overflow bits. The second portion of validation involves checking synchronization information for that particular encoder. The synchronization counter transmitted by all encoders is 6 bits long. Two copies of the full synchronization counter 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. FIGURE 3: LEARN INIT LEARN IND VDD MCLR GND S0 S S2 S3 PINOUTS OF MICROCHIP KEELOQ DECODER 2 3 4 5 6 7 PIC6C56 8 7 6 5 4 3 2 RFIN NC OSC OUT OSC IN VDD FUNC OK EE CS 8 EE CK 9 0 EE DIO FUNCTIONAL INPUTS AND OUTPUTS TABLE 8: Mnemonic MICROCHIP DECODER FUNCTIONAL INPUTS AND OUTPUTS Pin Input / Function Number Output RF IN 8 I Demodulated PWM signal from RF receiver. The decoder uses this input to receive encoder transmissions. LEARN INIT I Input to initiate learning. LEARN INDICATION 2 O Output to show the status of the learn process (in an integrated system this will be combined with the system status indicator). FUNC OK 3 O Indication that the received button code matches the learned button code. S0, S, S2, S3 6, 7, 8, 9 O Function outputs, correspond to encoder input pins. EE DIO 0 I/O EEPROM Data. EE CK O EEPROM Clock. EE CS 2 I EEPROM Chip Select. 998 Microchip Technology Inc. DS0066B-page 5

PROGRAM FLOW The software for the Microchip decoder has been written for the PIC6C56 microcontroller. The compiler used is MPASM. The operating frequency of the PIC6C56 is 4 MHz. The clock speed is important as the reception routine (RECEIVE) has some critical timing specifications. Other decoder functions that rely on a 4 MHz clock speed are the hold times of the various outputs, time-outs, etc. The main program flow is described here. More detailed descriptions of the modules can be found further in the application note. On power-up the decoder reads the learn indicator from the external EEPROM. The status flags are checked to see if a learn routine was interrupted when the microcontroller was reset. If so, it is assumed the learn cycle was not successfully completed and the encoder at the learn indicator subsequently deleted (WIPE_TX). The encoder then enters the main loop where it spends most of its time. The main loop checks to see if the learn button is being activated (TST_LEARN). If so, the decoder enters the learn mode. If learn has not been initiated, the microcontroller then checks for transmissions from encoders (RECEIVE). If 64 bits (HCS encoders) are received, the microcontroller validates the transmission received. If the transmission received is a valid transmission from an encoder learned into the system, the system sets the appropriate outputs (M_BUT). FIGURE 4: MICROCHIP DECODER MAIN PROGRAM FLOW Reset Get Learn Pointer MAIN Reset Due To Failed Learn? Delete TX At Learn Position WIPE_TX Loop Back Point MAIN2 Learn Pressed? M_LOOP2-> TST_LEARN Learn Routine Check For Encoder TX RECEIVE Received 56 Or 66 Bits? M_LOOP2 Transmission Validation DS0066B-page 6 998 Microchip Technology Inc.

FUNCTIONAL MODULES Reception The reception routine (RECEIVE) is based on a reliable algorithm which has successfully been used in previous implementations of KEELOQ decoders. Automatic baud rate detection is used to compensate for variations in baud rate of different encoders of a specific type, as well as the difference in baud rate between different encoders (HCS200 and HCS300). The reception routine is able to handle 64-bit transmissions. This is easily extended to receive more bits. The reception routine is able to determine the type of encoder by the number of bits in the transmission. The reception algorithm performs the following functions when an output is detected from the receiver:. Calibrate on the header low period to determine the actual elemental period for the transmission being received. The required elemental period is 0% of the low header period. In the diagram below (Figure 5) the header calibration sample points are marked through 3. The calibration flow chart (Figure 6) shows at what points in the source code samples, 2, and 3 are taken. Elemental periods outside the capture range of the algorithm (either too long or too short) should be rejected, since they would be due either to noise or to reception of an incomplete signal. 2. Using the determined elemental period, three samples after the first rising edge following the header are taken. The first sample is taken half an elemental period after the rising edge (Sample 4); the second, one elemental period later (Sample 5), and the third, another one elemental period later (Sample 6). The first sample must be high, the second could be either high or low, and the third sample must be low. If either the first or the third sample is not as expected, the attempt at capturing a transmission is abandoned. In the diagram below (Figure 5), the data sample points are points 4 through 6. The flow chart describing data reception (Figure 7) shows where in the code the samples are taken. 3. If all 64 bits have been captured, each with the correct first and third elements, the transmission can be assumed to be correct, and decryption can commence. The receiving routine should be called often enough to ensure that the high portion in the header is not missed (Sample, Figure 5). In systems where the receive routine is called to check if there is activity on the receiver input, the routine should poll the input for a valid transmission for at least the time taken to complete one transmission if activity is detected on the input line. This makes provision for the receive routine being called while a transmission is in progress. Having missed the first header, the first transmission will be invalid and be discarded. The decoder should continue sampling the input through the guard time in order to catch the next header and transmission (i.e., for a decoder designed to capture HCS300 transmissions the time spent polling for a valid transmission should be at least 00 ms if activity is detected in the input line). The diagram below (Figure 5) gives all the major sampling points in the receive algorithm. te: FIGURE 5: The sample points are labeled in the receive routine flow diagrams that follow. SAMPLING POINTS USED IN RECEIVE ALGORITHM Preamble Header Data 2 3 4 5 6 74 5 998 Microchip Technology Inc. DS0066B-page 7

Flow Diagrams The first flow diagram (Figure 6) describes the calibration routine which is used to determine the actual transmission rate of the encoder so that the decoder can compensate for deviations from nominal timing. There are four different exit points, each of which should branch to a point in the program where housekeeping and input monitoring can be resumed. There is only one exit point for a valid calibration operation (RCV7). At this point, it is assumed that a valid header has been received and that a string of data bits will follow. The second flow diagram (Figure 7) handles the reception of bits once the calibration routine has been successfully completed. The data bits are all sampled three times each to ensure that a noise free transmission has been received. The receive routine uses the calibrated elemental period, determined in the calibration routine, to ensure that the samples are spaced correctly. The routine resynchronizes itself on the rising flank of each bit. Provision for identification of the encoder type, based on the number of bits received, is included. Keeloq encoders transmit at least 66 bits. The decoder only receives 64 bits of the transmission, the remaining status bits aren t used by the decoder. If all of the control samples in all of the bits are sampled correctly (i.e., the first element is high and the last element is low), the routine checks whether 56 bits have been received correctly. If not, the routine returns to the calling procedure. FIGURE 6: Calibrate RECEIVE High Input? Reset Time-out Counter Input? RCV Low 2 Clear Calibration Counter RCV2 CALIBRATION FLOW CHART Low High Time-out? Update Time-out Counter RCV5 Invalid Header RMT_0 Input? RCV3 High 3 Calibration Counter/0 RCV6 Low Too Long? RCV4 Too Short? RCV6 Load Cal Counter RCV7 Invalid Header RMT_0 Receive Data DL DS0066B-page 8 998 Microchip Technology Inc.

FIGURE 7: DATA RECEPTION IN RECEIVE Receive Data RCV7 3 Wait Half Bit Period DL Input? Low High 4 Wait Full Bit Period DL2 Input? High Low 5 Data = Data = 0 Wait Full Bit Period DL3 7 Input? High High Low 6 Low Input? RCV9/RCV0 Last Bit? Time-out? Invalid Received 56 Bits? RMT0 Cleanup RMT2 Reception Complete RMT 998 Microchip Technology Inc. DS0066B-page 9

VALIDATION SYNCHRONIZATION FUNCTION INTERPRETATION OUTPUT ACTIVATION KEY GENERATION DECRYPTION LEARN ROM MEMORY MAP EEPROM MEMORY MAP RAM MEMORY MAP 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 DS4049 from Microchip Technology Inc. DS0066B-page 0 998 Microchip Technology Inc.

DEVICE PINOUTS The device used in the application note is a PIC6C56 PDIP. TABLE 9: DEVICE PINOUTS PIN PIC6C56 Function Decoder Function PIN PIC6C56 Function Decoder Function PORTA Bit2 LEARN Input Active 8 PORTA Bit RF Input Low 2 PORTA Bit3 LRN IND Output Active 7 PORTA Bit0 t used High 3 TIME Connect to VDD 6 Osc In RC osc (4 MHz) 4 MCLR Brown out detect 5 Osc Out 5 GND Ground 4 VDD +5V supply 6 PORTB Bit0 S0 3 PORTB Bit7 FUNC OK 7 PORTB Bit S 2 PORTB Bit6 EEPROM CS () 8 PORTB Bit2 S2 PORTB Bit5 EEPROM CLK (2) 9 PORTB Bit3 S3 0 PORTB Bit4 EEPROM DIO (3+4) TIMING PARAMETERS TABLE 0: TIMING PARAMETERS Parameter Typical Unit Output activation duration 524 ms Output pause if new function code received 3 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 s SOURCE CODE LISTING A diskette is supplied containing source code for the Microchip decoder in the file mcdec2.asm. The code has been compiled using MPASM v02.3.00. Certain functions are dependent on the oscillator speed for correct functioning. Examples of time dependent functions include RECEIVE and TST_RTCC. The PIC6C56 Microcontroller should run at 4 MHz. LIST OF IMPORTANT FUNCTIONS Function Name Description Function Length CALC_KEY Key generation routine. 62 DECRYPT Decryption routine for Code Hop. 6 EEREAD The data in the EEPROM at ADDRESS is read and decrypted to TMP 3 and TMP2. te that TMP, TMP2 and ADDRESS are user defined registers. EEWRITE The data in TMP and TMP2 is encrypted and written to the EEPROM at 48 ADDRESS. te that TMP, TMP2 and ADDRESS are user defined registers. M_DIS Check discrimination value. 9 M_CNT Check synchronization (counter) values. 69 RECEIVE Start of the RF receive routine. 2 TST_LEARN Check for learn mode and entry to learn. 2 TST_RTCC Check TIMER0 and do whatever real time tasks are required. 38 998 Microchip Technology Inc. DS0066B-page

APPENDIX A: APPENDIX SCHEMATIC DIAGRAMS FIGURE A: SCHEMATIC DIAGRAM OF MICROCHIP KEELOQ DECODER U4 LOW VOLTAGE DETECTOR VI G VO ND R3 k R 0k 4 3 6 5 MCLR T0CKI OSC CLKOUT C 0 pf PIC6C56 4 V C C G ND 5 RA0 RA RA2 RA3 RB0 RB RB2 RB3 RB4 RB5 RB6 RB7 U5 7 8 2 6 78 9 0 2 3 2 J 2V 23 GND CON3 J2 RF INPUT R2 0k S LEARN INIT D5 N4004/7 C2 00 µf POWER SUPPLY R8 R4 R5 R6 R7 R9 k 23 4 U2 LM7805 VI G VO ND D6 D D3 D4 D2 D7 U CS SK DI DO NC NC GND 8 76 5 93LC46B SERIAL EEPROM C3 00 µf LEARN S0 S S2 S3 FUNC OK DS0066B-page 2 998 Microchip Technology Inc.

FIGURE A2: TYPICAL GARAGE DOOR OPENER SCHEMATIC 2V GND J 23 CON3 2V D5 N4004/7 C2 00 µf POWER SUPPLY U4 LOW VOLTAGE DETECTOR VI G VO ND R3 K R 0k C 0 pf 4 3 6 5 MCLR T0CKI OSC CLKOUT PIC6C56 V C C G ND 4 5 RA0 RA RA2 RA3 RB0 RB RB2 RB3 RB4 RB5 RB6 RB7 U2 LM7805 VI G VO ND C3 00 µf ANTENNA U5 7 8 2 RF INPUT 6 78 S0 S 9 0 2 3 R4 k R2 0k LEARN D0 2 S LEARN INIT 23 4 D8 N4004/7 J3 23 S0 4 56 7 89 0 2 3 4 5 RF RECEIVER MODULE U CS SK DI DO NC NC GND 8 76 5 93LC46B SERIAL EEPROM 2V MOTOR CONTROL OUT K2 J2 CON RELAY SPST Q NPN DOOR MOTOR L GARAGE LIGHT 2V V 0VAC D9 K N4004/7 RELAY SPST S Q2 NPN GARAGE LIGHT 998 Microchip Technology Inc. DS0066B-page 3

NOTES: DS0066B-page 4 998 Microchip Technology Inc.

NOTES: 998 Microchip Technology Inc. DS0066B-page 5

te the following details of the code protection feature on PICmicro MCUs. The PICmicro family meets the specifications contained in the Microchip Data Sheet. Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today, when used in the intended manner and under normal conditions. There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet. The person doing so may be engaged in theft of intellectual property. Microchip is willing to work with the customer who is concerned about the integrity of their code. Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as unbreakable. Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our product. If you have any further questions about this matter, please contact the local sales office nearest to you. Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. 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. licenses are conveyed, implicitly or otherwise, under any intellectual property rights. Trademarks The Microchip name and logo, the Microchip logo, FilterLab, KEELOQ, microid, MPLAB, PIC, PICmicro, PICMASTER, PICSTART, PRO MATE, SEEVAL and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. dspic, ECONOMONITOR, FanSense, FlexROM, fuzzylab, In-Circuit Serial Programming, ICSP, ICEPIC, microport, Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM, MXDEV, PICC, PICDEM, PICDEM.net, rfpic, Select Mode and Total Endurance are trademarks of Microchip Technology Incorporated in the U.S.A. Serialized Quick Turn Programming (SQTP) is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. 2002, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. Printed on recycled paper. Microchip received QS-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona in July 999. The Company s quality system processes and procedures are QS-9000 compliant for its PICmicro 8-bit MCUs, KEELOQ code hopping devices, Serial EEPROMs and microperipheral products. In addition, Microchip s quality system for the design and manufacture of development systems is ISO 900 certified. 2002 Microchip Technology Inc.

M WORLDWIDE SALES AND SERVICE AMERICAS Corporate Office 2355 West Chandler Blvd. Chandler, AZ 85224-699 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: 480-792-7627 Web Address: http://www.microchip.com Rocky Mountain 2355 West Chandler Blvd. Chandler, AZ 85224-699 Tel: 480-792-7966 Fax: 480-792-7456 Atlanta 500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770-640-0034 Fax: 770-640-0307 Boston 2 Lan Drive, Suite 20 Westford, MA 0886 Tel: 978-692-3848 Fax: 978-692-382 Chicago 333 Pierce Road, Suite 80 Itasca, IL 6043 Tel: 630-285-007 Fax: 630-285-0075 Dallas 4570 Westgrove Drive, Suite 60 Addison, TX 7500 Tel: 972-88-7423 Fax: 972-88-2924 Detroit Tri-Atria Office Building 32255 rthwestern Highway, Suite 90 Farmington Hills, MI 48334 Tel: 248-538-2250 Fax: 248-538-2260 Kokomo 2767 S. Albright Road Kokomo, Indiana 46902 Tel: 765-864-8360 Fax: 765-864-8387 Los Angeles 820 Von Karman, Suite 090 Irvine, CA 9262 Tel: 949-263-888 Fax: 949-263-338 New York 50 Motor Parkway, Suite 202 Hauppauge, NY 788 Tel: 63-273-5305 Fax: 63-273-5335 San Jose Microchip Technology Inc. 207 rth First Street, Suite 590 San Jose, CA 953 Tel: 408-436-7950 Fax: 408-436-7955 Toronto 6285 rtham Drive, Suite 08 Mississauga, Ontario L4V X5, Canada Tel: 905-673-0699 Fax: 905-673-6509 ASIA/PACIFIC Australia Microchip Technology Australia Pty Ltd Suite 22, 4 Rawson Street Epping 22, NSW Australia Tel: 6-2-9868-6733 Fax: 6-2-9868-6755 China - Beijing Microchip Technology Consulting (Shanghai) Co., Ltd., Beijing Liaison Office Unit 95 Bei Hai Wan Tai Bldg.. 6 Chaoyangmen Beidajie Beijing, 00027,. China Tel: 86-0-8528200 Fax: 86-0-8528204 China - Chengdu Microchip Technology Consulting (Shanghai) Co., Ltd., Chengdu Liaison Office Rm. 240, 24th Floor, Ming Xing Financial Tower. 88 TIDU Street Chengdu 6006, China Tel: 86-28-6766200 Fax: 86-28-6766599 China - Fuzhou Microchip Technology Consulting (Shanghai) Co., Ltd., Fuzhou Liaison Office Unit 28F, World Trade Plaza. 7 Wusi Road Fuzhou 35000, China Tel: 86-59-7503506 Fax: 86-59-750352 China - Shanghai Microchip Technology Consulting (Shanghai) Co., Ltd. Room 70, Bldg. B Far East International Plaza. 37 Xian Xia Road Shanghai, 20005 Tel: 86-2-6275-5700 Fax: 86-2-6275-5060 China - Shenzhen Microchip Technology Consulting (Shanghai) Co., Ltd., Shenzhen Liaison Office Rm. 35, 3/F, Shenzhen Kerry Centre, Renminnan Lu Shenzhen 5800, China Tel: 86-755-235036 Fax: 86-755-2366086 Hong Kong Microchip Technology Hongkong Ltd. Unit 90-6, Tower 2, Metroplaza 223 Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-240-200 Fax: 852-240-343 India Microchip Technology Inc. India Liaison Office Divyasree Chambers Floor, Wing A (A3/A4)., O Shaugnessey Road Bangalore, 560 025, India Tel: 9-80-229006 Fax: 9-80-2290062 Japan Microchip Technology Japan K.K. Benex S- 6F 3-8-20, Shinyokohama Kohoku-Ku, Yokohama-shi Kanagawa, 222-0033, Japan Tel: 8-45-47-666 Fax: 8-45-47-622 Korea Microchip Technology Korea 68-, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea 35-882 Tel: 82-2-554-7200 Fax: 82-2-558-5934 Singapore Microchip Technology Singapore Pte Ltd. 200 Middle Road #07-02 Prime Centre Singapore, 88980 Tel: 65-334-8870 Fax: 65-334-8850 Taiwan Microchip Technology Taiwan F-3,. 207 Tung Hua rth Road Taipei, 05, Taiwan Tel: 886-2-277-775 Fax: 886-2-2545-039 EUROPE Denmark Microchip Technology rdic ApS Regus Business Centre Lautrup hoj -3 Ballerup DK-2750 Denmark Tel: 45 4420 9895 Fax: 45 4420 990 France Microchip Technology SARL Parc d Activite du Moulin de Massy 43 Rue du Saule Trapu Batiment A - ler Etage 9300 Massy, France Tel: 33--69-53-63-20 Fax: 33--69-30-90-79 Germany Microchip Technology GmbH Gustav-Heinemann Ring 25 D-8739 Munich, Germany Tel: 49-89-627-44 0 Fax: 49-89-627-44-44 Italy Microchip Technology SRL Centro Direzionale Colleoni Palazzo Taurus V. Le Colleoni 2004 Agrate Brianza Milan, Italy Tel: 39-039-6579- Fax: 39-039-6899883 United Kingdom Arizona Microchip Technology Ltd. 505 Eskdale Road Winnersh Triangle Wokingham Berkshire, England RG4 5TU Tel: 44 8 92 5869 Fax: 44-8 92-5820 0/8/02 2002 Microchip Technology Inc.