Вы находитесь на странице: 1из 13

The HT6P20x2 Encoder IC

The HT6P20x2 Encoder IC

D/N:AN0261E

Introduction
Holtek’s HT6P20x2, wireless remote control encoding IC, is capable of supporting up to a
22 bit address code and a five bit data input code. The device includes additional
advantages such as a wide operating voltage range of 2V~12V, low power consumption,
integrated RC oscillator, high noise immunity etc. The devices can be used in applications
such as car alarms, motorcycle/electric bike alarms, home security and gating products,
window remote control, doorbell remote control to name but a few.

Operation Declaration
IC Selection Table
The HT6P20x2 series of devices are packaged part numbered according to their different
Address Code Bits and Data Code Bits as shown in the following table:

Part Number Address code bits Data code bits


HT6P20B2 22 2
HT6P20D2 20 4
HT6P20F2 19 5

The corresponding pin assignments are illustrated as below:

1
The HT6P20x2 Encoder IC

Signal Trigger
The data input lines, D0~D4, in the HT6P20x2 are all connected to a pull-high resistor.
Under non operational conditions, the data inputs, D0~D4, will therefore remain at a high
level. After the device receives any or multiple high to low switch triggers on the D0~D4
lines, the device will start then to execute its internal encoding function and output its
corresponding address and data codes on the DOUT pin. As long as these D0~D4 lines
remain at a low level, the address and data codes will be transmitted continuously. The
timing of this protocol is shown in the figure below.

From the above figure, the DOUT data output of the encoding device is connected with
the trigger time of the data input pins as described below:
 When the trigger time of the data inputs, D0~D4, is shorter than one pilot code, the
DOUT output pulse length will be the same as the data input trigger which means that
it will be unable to transmit a complete pilot code.
 When the trigger time of the data inputs is longer than one pilot code and smaller or
equal to one code length, then the DOUT output will output a complete data code.
 When the trigger time of the data inputs is longer than one complete code, the DOUT
output time will be the same as the data inputs (D0~D4.) As long as the data inputs
trigger continues, then DOUT will continue to output data.

The diagram below shows three complete transmission signal code words:

Note:If the data line remains at a low level, then the signals will be output continuously.
One code word is a packet of information composed of a pilot code, an address code, a
data code and an end code among which the pilot and end codes are the same in all of
the HT6P20x2 series of devices. A complete code word breakdown is shown below:

2
The HT6P20x2 Encoder IC

Pilot Code
Each transmission has a pilot code preceding the address and data codes. This is to alert
the decoder that address and data codes are about to be transmitted. The pilot code
waveform is composed of a low pulse of 23λ duration followed by a high pulse of 1λ
duration. A 1λ time unit is equal to 32 internal oscillator time periods. When the data
(D0~D4) input pins change from high to low, note that the duration of the data input must
be greater than the pilot code length for a full signal transmission to occur. If the input low
signal is less than the pilot code length by 768 clock oscillator periods, then DOUT will
only output a pulse smaller than the pilot code and no address, data or end codes will be
transmitted.

Address/Data Bit Waveform


As address/data bits can be designated to be either 0 or 1 which must be encoded in
a certain way. One bit of data consists of one pulse cycle (which includes a certain ratio of
one low pulse and a high pulse) with each pulse cycle having a duration of 96 internal
oscillator periods. This means that one bit of data, either 0 or 1, must be completed in
96 oscillator periods. The following figure depicts the 0 or 1 waveforms showing the
high/low level ratio.

Note:
1λ = 32 internal oscillator time periods.
Bit 0 consists of a low pulse for 1λ then a high pulse for 2λ, marked as tDW in the
figure.
Bit 1 consists of a low pulse for 2λ then a high pulse for 1λ, marked as tDW in the
figure.

3
The HT6P20x2 Encoder IC

End Code Waveform


After the data/address codes from the HT6P20x2 series of devices are transmitted, a 4
bit end code with the bit pattern 0101 will be transmitted to complete the full code word
transmission as shown below.

Operation Flowchart
The flowchart describes the HT6P20x2 operation flow. After power on the device enter
the Stand-By Mode. A transition on the signal input pins, D0~D4, from high to low will
wake up the device at which point it will enter its transmission encoding mode and
transmit a full code word consisting of a pilot code, address code, data code and end
code.
After a code word is transmitted, check if the signal input pins, D0~D4, are still receiving
input signals. If yes, then keep transmitting code words or else return to the Stand-By
mode.

Power ON

Stand-by Mode

No Data Input Pin in


Low State

Yes

1 Word of Pilot
code/address/data/end Code
Transmitted

No Data Input Pin Yes


Still in Low State

4
The HT6P20x2 Encoder IC

Typical Circuit
 HT6P20B2
For a battery voltage between 2V~12V, a recommended application circuit is shown
below for a frequency of 315MHz.

Note: The RF circuit component values are for reference only. Users should modify the
values according to different frequency and voltage applications.

 HT6P20D2
For a battery voltage between 2V~12V, a recommended application circuit is shown
below for a frequency of 315MHz.

2.2uH

10n VBAT
10p
HT6P20D2
ANT 1.5p 5p
1 8
2.5p VDD NC
S4
2 7
VSS D3
S3
56K 3 6
DOUT D2
S2
2SC3356 4 5
D0 D1
220
S1

100
LED

Note: The RF circuit component values are for reference only. Users should modify the
values according to different frequency and voltage applications.

5
The HT6P20x2 Encoder IC

 HT6P20F2
For a battery voltage between 2V~12V, a recommended application circuit is shown
below for a frequency of 315MHz.

Note: The RF circuit component values are for reference only. Users should modify the
values according to different frequency and voltage applications.

Application Example
From the above information, this application will construct a remote controller using the
HT6P20x2. The data generated using the HT6P20x2 will then be received using a
superregeneration RF receiver and decoded using an MCU which is the HT46R065 in
this example. The decoded address and data will then be displayed on an 8 digit 7
segment display.

Application Block Diagram


Example Hardware Block Diagram

6
The HT6P20x2 Encoder IC

Hardware Description
Transmission Code: When an input data change is detected on the HT6P20x2, the data
and address codes will be transmitted using the RF resonator circuit.
Receive Code: The HT46R065 MCU, in this example, receives the transmitted code from
the HT6P20x2 through the superregeneration RF receiver module and displays it on the
display after decoding. The decoding method uses a level time checking, interrupt timer
and algorithm etc. This example uses an interrupt timer decoding method by reading the
data level period using interrupts and then comparing the width of both high and low
pulses in each bit (every pulse cycle) to implement data decoding.
When using level period checking for decoding, note that as the internal clock in the
HT6P20x2 is an internal RC type, then different voltages will affect the data level period.

RF Transmit and Receive Circuit


With the above information and using the accompanying typical circuit diagram, a
common application program and common PCB can be designed that is compatible for
the encoding devices such as the HT6P20B2, HT6P20D2, and HT6P20F2.

The RF receiver in the application program uses a superregeneration receiver module


with an MCU to decode the data and uses two seven segment displays to display the
received address and data bits.
After power on, select the decoding device, whether it be HT6P20B2, HT6P20D2 or
HT6P20F2, using the through input pins. The selected device will be displayed on the
display. After the RF signal is received, the buzzer will beep once, and the original
displayed device number on the display will disappear and be replaced by the address
code decoded from the RF signal in addition to the corresponding input switch value. To
display the HT6P20B2 22 bits of address code requires six digits. The 7th digit will
display a “6” to indicate that there are six digits to display the address, while the 8th digit
shows the switch value of 1 or 2. The 20 bit address code of the HT6P20D2, requires
a 5 digit display and will and show 5 on the 7th digit to indicate that there are five
address digits to be displayed. The 8th digit shows the switch value of 1~4. The 19 bit
address code of the HT6P20F2, requires a 5 digit display and will show 5 on the 7th digit
to indicate that there are five address digits to be displayed. The 8th display shows the
switch value of 1~5.

7
The HT6P20x2 Encoder IC

Application Flowchart
The flowchart for the application program is composed of two parts, the main flowchart
and the interrupt decoding flowchart.

Main Flowchart
After the main program initializes the MCU and related control flag bits, read the
data/address codes by checking the PGM_OK flag bit. Only after two successive
readings of the same data/address codes will the decoding be considered to be
successful after which the decoded data/address codes will be shown on the display.
After the decoding is complete, the program will keep checking if the data is the same as
the previous decoded data. If it is the same, then the program will remain in the checking
loop. Only when a difference between present data and the previous is detected will the
program initialize the related control flag bit. After the data is decoded it will be displayed.

8
The HT6P20x2 Encoder IC

9
The HT6P20x2 Encoder IC

Interrupt Decoding Program Flowchart


The example uses Timer1 to setup a time of 50us to check for transitions on the I/O pin
for decoding. When a transition on the I/O pin level is detected, then check the times of
the two levels. After checking the length and comparing twice, determine if the bit is either
a 1 or 0. After all the encoded data sent from the HT6P20x2 has been decoded, set
the PGM_OK flag bit to indicate the completion of an address/data transmission.
During decoding, if an external interrupt code or pilot code occurs, then as this time will
exceed the level maximum duration, the program will initialise the decoding related
registers and flag bits and not restart decoding until it is complete. Check the following
program example description for details.

Program Description
The program here is composed of a main program and an interrupt decoding programs.
In the main program, the flag bits will be initialized and the TMR enabled and check for
reception of data from the HT6P20x2. Check for one decoded data reception using the
PGM_OK flag and then disable the TMR. After reading the data, setup the related flags,
enable the TMR, then read the data again and disable the TMR. If the data is the same,
then show the decoded data/address codes on the eight digit display, or enable the TMR
to recheck the codes. For details see the attached program file and the TMR decoding
flowchart.

10
The HT6P20x2 Encoder IC

Interrupt decoding program: Use the TMR function of the MCU to receive the RF signals
from the Encoder at every Time Out and decode the encoded signals using the following
program and convert it to a format for suitable display or for control signals.

;TMR Interrupt subroutine:


;===============================================================
;0C TIMER1 INTERRUPT(Time control)
;===============================================================
TIMER1:
CLR WDT
PUSH
;===============================================================
;Judge the signal input :
MOV a, 56
MOV TMR0,a

SNZ SIO_PIN ;Scan the SIO pin status


JMP SIOPIN_LO ;If the SIO pin is low jump to SIOPIN_LO level
;===============================================================
;Count remained at high level to receive the signal duration:

SIOPIN_HI:
SNZ SIO_STATUS ;Check the SIO pin former status
JMP SIOPIN_LO2HI

SIOPIN_HI2H:
INC HI_COUNT
SZ Z
DEC HI_COUNT ; Max. count is FFH
JMP EXITINT

SIOPIN_LO2H:
SET SIO_STATUS ;Change to the current status
XMOV HI_COUNT_SAVE,HI_COUNT ;Save LO_COUNT
CLR HI_COUNT ;Refresh LO _COUNT
LSERJ HI_COUNT_SAVE,MAXDURATION ;If LO_COUNT_SAVE is smaller than the MAXDURATION
JMP SIO_COUNT_INITIAL ; Code is wrong

;===============================================================
;Compare the ratio of the high and low signal levels and thus determine if it is "1" or "0"
LBERJ LO_COUNT_SAVE,HI_COUNT_SAVE ;If LO_COUNT_SAVE>HI_COUNT_SAVE,Write "0" TO C
JMP SIO_0_CODE ;else write "1" TO C
JMP SIO_1_CODE
;===============================================================
;Count remained at low level to receive the signal duration:

SIOPIN_LO:
SZ SIO_STATUS ;Check the SIO pin former status
JMP SIOPIN_HI2LO

SIOPIN_LO2LO:
INC LO_COUNT
SZ Z
DE LO_COUNT ; Max. count is FFH
JMP EXITINT ;Exit TMR Interrupt

SIOPIN_HI2LO:
CLR SIO_STATUS ;Change to the current status
XMOV LO_COUNT_SAVE,LO_COUNT ;Save HI_COUNT

11
The HT6P20x2 Encoder IC

CLR LO_COUNT ;Refresh HI_COUNT


LSERJ LO_COUNT_SAVE,MAXDURATION ;If HI_ COUNT _ SAVE is smaller than the MAXDURATION
JMP SIO_COUNT_INITIAL ; Code is wrong
JMP EXITIN ;Exit TMR Interrupt

SIO_0_CODE:
CLR C
JMP $+2

SIO_1_CODE:
SET C
RLC ENCODER_DATA[3] ;Store data code
RLC ENCODER_DATA[2] ;Store address code
RLC ENCODER_DATA[1] ;Store address code
RLC ENCODER_DATA[0] ;Store address code
SDZ BITCOUNTER ;Code length counter
JMP EXITINT ;Exit TMR Interrupt
SET PGM_OK ;PGM_OK flag is set high
JMP EXITINT ;Exit TMR Interrupt

;===============================================================
;Input signal does not meet the proportional requirements for an encoded bit code, or to realize
pilot code will jump to the loop to execute
SIO_COUNT_INITIAL:
XMOV BITCOUNTER,CODELENGTH ;Code length set
CLR ENCODER_DATA[0] ;Clear register
CLR ENCODER_DATA[1] ;Clear register
CLR ENCODER_DATA[2] ;Clear register
CLR ENCODER_DATA[3] ;Clear register
CLR PGM_OK
JMP EXITINT ;Exit TMR Interrupt
;===============================================================
;Leave TMR interrupt
EXITINT:
POP
RETI
;==========================================

PCB Layout Notes


The figure below shows an example of the Encoder (HT6P20x2) Transmitter Layout. The
frequency is 315MHz. See the attached file for more information.

12
The HT6P20x2 Encoder IC

Component Placement
 The first consideration for component placement are their signal lines which must be as
short as possible
 The routing space for the VCC and GND lines should be reserved in advance
 In addition to the antenna matching components, the RF PAOUT pin area should avoid
being occupied with components which may influence proper RF operation.

Routing
 As right angles more easily accumulate charge, they will have larger discharges which
will influence PCB stability. It is recommended to conduct all routing using 45 degree
bevels or curves.
 The distance between tracks should not be less than 6 mils
 The distance between the wires and the apertures should not be less than 6 mils
 The distance between two linked apertures should not be less than 6 mils
 The width of the VCC and GND tracks should not be less than 12 mils
 Each IC power source must have a decoupling capacitor located adjacent to the IC
 The RF antenna trace should not have a ground plane so as not to affect performance

Antenna
 Stock dipole 50 SMA plug for the Patch Antenna
 λ/4 width of copper wire, single core wire, stranded wire
 RF antenna PCB layout
 Antenna width = 35mil (min)
 Antenna length (L) formula is ((Lightspeed)/(4*f* )),ε= 4.7 for FR4 material of PCB;
f = resonance frequency.
 ANT Layout Example

Conclusions
The above example has introduced the HT6P20x2 related features and encoding
principles as well as an encoding and decoding example description for the user to refer
to when implementing actual application development.

13