, , ,

E-MAIL: acturcato (at) gmail.com

00 – 20-DEC-2013 – Initial release
01 – 27-DEC-2013 – Fix the issue when an invalid code ANTI-CODE was received (thanks to Gilson Oguime @oguime)
02 – 10-JAN-2014 – Code optimization. Created a main function to return ADDRESS CODE and BUTTONS and decrease use of global variables
03 – 11-JAN-2014 – Code optimization again. Created a struct for controls and remove global variables
04 – 18-JUN-2014 – New code optimization. Variable lambda is Global. This make the code most compatible with others Arduinos boards (by Henrique Brancher Gravina)

The HT6P20B generates a code 28-bit, 22-bit for ADDRESS, 2-bit for DATA and 4-for “ANTI-CODE” (verification code).
The ADDRES is fixed for a given Encoder (each HT6P20 has a different address).
The DATA changes according to the pressed button.
ANTI-CODE is always the same: “0101”.

For HT6P20D model there are 20-bit for ADDRESS and 4-bit for DATA.
For HT6P20F model there are 19-bit for ADDRESS and 5-bit for DATA.
(see table in Datasheet for details)

The bits of ADDRESS and DATA are transmitted using 3 clock cycles.

Connecting a 2M2 resistor at pins 4 and 5 of HT6P20B, it has 2 KHz internal clock and therefore a 500 us clock cycle. Thus, each bit is transmitted in 1500 us.
Connecting a 1M4 resistor at pins 4 and 5 of HT6P20B, it has 3 KHz internal clock and therefore a 333 us clock cycle. Thus, each bit is transmitted in 1000 us.
Some newer models HT6P20 already have internal oscillator (no need external resistor).

The complete code contains four main parts: PILOT, ADDRESS, DATA and ANTI-CODE:
– The PILOT is formed by 23 cycles of “0” and one cycle of “1”;
– The ADDRESS consists of 22 bits (66 cycles);
– The DATA is formed by 2 bits (6 cycles).
– The ANTI-CODE consists of 4 bits (12 cycles). It is always “0101”.

See figure on page 4 of datasheet!

To know if the transmitted bit is “0” or “1”, you must analyze the second cycle of each bit (remembering each bit transmitted using 3 cycles):
– The “first cycle” of each bit is always “0” (ZERO);
– The “second cycle” will be “1” if the transmitted bit is “0” (ZERO) or “0” if the transmitted bit is “1” (ONE).
– The “third cycle” is always “1” (ONE).

So, to know the transmitted bit, just “to measure” the “1” pulse duration for every three cycles.
– If the duration of the pulse “1” is equal to one cycle, means “second cycle” is “0”, then the transmitted bit is “1”;
– If the duration of the pulse “1” is equal to twice a cycle, means “second cycle” is “1”, then the transmitted bit is “0”.

See figure on page 5 of datasheet!

So, the routine´s role is to identify the “PILOT period” and then read every bit of ADDRESS and DATA.
To identify the “PILOT period”, it monitors output of the RF receiver module and check how long it remains at “0”.
To account for variations that code may suffer (due to variations of the resistor and/or battery voltage), it is considered here one cycle of internal clock between 400 us and 600 us.
Thus, the interval of 23 cycles in level “0” must be between 9.2 ms (23 x 400 us) to 13.8 ms (23 x 600 us).

Values outside this range are discarded!

After these 23 cycles at level “0”, there is a cycle in level “1”. That must be an interval of 400 us to 600 us.
Detecting this time at “0” after one cycle at “1”, it is considered that this is a “PILOT period”. And so, now it needs analyze the bits that will be later the ADDRESS, DATA and ANTI-CODE.
In this part, we calculate the lambda time (one pulse duration) as the total time at “0” divided by 23.
If the next three cycles, the time at “1” is between 0.5 and 1.5 lambda(s), the transmitted bit is “1”;
If the time at “1” is between 1.5 and 2.5 lambdas, the transmitted bit is “0”…
And so on until the bit counter reaches the value of 28 bits received: 22 for ADDRESS, 2 for DATA and 4 for ANTI-CODE.

When all 28 bits have been received, the routine checks whether ANTI-CODE is OK, that is, checks if it is equal to “0101”.
If so, the received data is OK and can be used…

Connection of components: Arduino MEGA 2560 R3 + RF Receiver Module 433MHz.

Arduino MEGA com módulo RF

Arduino MEGA + RF module





Download from GitHub:

ACT_HT6P20B_RX-04.ino (Rev.04)

ACT_HT6P20B_RX-01.ino (Rev.01)