Codec for PT2262 and PT2272 RC chips

Share:

pt2272 boardOverview

On this page you'll find an experimental codec that simulates both PT2272 decoder and PT2262 encoder chips. These two chips are commonly found in many inexpensive garage door openers and are of fixed code type. They provide a configuration word of 12 ternary digits which means that there are 312 = 531441 different code combinations.

This is by no means a secure solution since the code transmitted by these chips never changes and all it takes to duplicate one of these remote controllers is to listen for the transmission and then replay it. There are more secure solutions using rolling code techniques where the code changes every time the remote controller transmits. Rolling code solutions are more complex to implement and require constant synchronization between transmitter and receiver.

 

Schematic

The schematics presented below are based on a PIC 16F628 because both encoder and decoder firmwares were developed on a 16F628 but it shouldn't be hard to port to other PICs. The encoder schematic is on the left and the decoder on the right.

2262 schematic            2272 schematic

The output pin of the encoder is on RB3/CCP1 pin 9 and the input pin for the decoder is on RB4 pin 10. The signal on these pins is not modulated with any RF carrier. 

          

They can be bought at almost every online shop selling Arduino parts.

 

PCB

This is an experimental driver software to use in your own projects. It was developed on a white breadboard with lots of wires!

There is no PCB!

 

 

 

 

Software

The codec contains two modules that can be used independently of each other or together, because they don't share any of the PIC resources. They are separated into 2 files each:

There are other files that are auxiliary to the codec:

Currently both encoder and decoder modules run with a fixed 10KHz clock rate when the PIC is driven with a 10MHz crystal oscillator.

Binary digits and ternary digits

One thing that distinguishes PT2262 and PT2272 from other remote controller chips like MM53200 is the fact that they don't use binary digits (bits) for the 12 bits configuration word. While on a MM53200 those 12 digits can be 0 or 1, on the PT2262 and PT2272 the configuration digits can be 0, 1 and F (float). Using ternary digits for the configuration word increases the number of possible combinations from 212 = 4096 to 312 =  531441 as stated above in the overview.

The use of ternary digits means that each digits can not be stored in a single bit, i.e. a single bit is not enough to represent 3 states, just 2. We need to use more than 1 bit for each digit. On the next section is an example of the encoding the ternary digits using nibbles instead of bits!

Encoder PT2262 module

The encoder module simulates a PT2262 IC running with a 10KHz clock. The interface is quite minimalistic having one method to send a transmission and another to check if the previous transmission has ended:

#ifndef PT2262_H_EMITTER
#define PT2262_H_EMITTER

 
// setup timer1, ccp1, pins and interrupt flags
void pt2262_setup(void);
 
// to be invoked on TMR1IF and CCP1IF
void pt2262_isr(void);
 
// start a transmission with the nibbles pointed by address and data
// it will lock if the previous transmission is in progress
// - address should contain 3 bytes, each nibble with value 0..2
// - data should contain 3 bytes, each nibble with value 0..2

void pt2262_tx(unsigned char *address, unsigned char *data);
 
// is it still transmitting?
bit pt2262_busy(void);
 
#endif

The transmission function is pt2262_tx and it accepts the 12 ternary digits to be sent. These 12 digits divide themselves in 6 for the address and 6 for the data. So both address and data should be arrays of 3 bytes and each byte represents 2 ternary digits, i.e. one ternary digit on each nibble. Here's an example:

To encode the 6 ternary digits "1 0 F 1 F 0" of address the array should have the following 3 bytes: [0x10, 0x21, 0x20] where 'F' is represented by the value 2, '1' is represented by the value 1 and '0' by 0. Yes there are some unused bits on every nibble but this a simple solution that works and doesn't complicate the code that much.

On the transmitter main example program both address and data are being read from the EEPROM. This is not mandatory but since the address part is usually fixed I thought of providing it as an example. The data can, of course, be defined based on the value of several push buttons connected to the PIC. 

The output of the encoder module can be seen on these screenshots. On the left is a single code word and on the right is the same code word zoomed in.

code word     code word detail

Decoder PT2272 module 

The decoder module simulates a PT2272 IC also running with a 10KHz clock. Its interface, shown below, is also minimalistic:

#ifndef PT2272_H_RECEIVER
#define PT2272_H_RECEIVER

// setup IoC, timerX
void pt2272_setup(void);

// to be invoked on RBIF
void pt2272_isr(void);

// returns the last known message
// address will contain 3 bytes, each nibble with value 0..2
// data will contain 3 bytes, each nibble with value 0..2
// returns true if new data is available and false if no new data is available since last read

bit pt2272_rx(unsigned char *address, unsigned char *data);

// returns true if a new message is available
bit pt2272_poll(void);

#endif
 

The 2 important functions are pt2272_poll and pt2272_rx, the former tests if a valid frame has been received and the latter retrieves the 12 ternary digits only when a valid frame has been received. Calling pt2272_rx without a valid frame does nothing and returns false.

Like on the transmitter module, both address and data parameters should be arrays with 3 bytes. The 12 ternary digits received will be placed one per nibble on each array. The main program prints every correctly decoded frames to the serial port.

The output of the receiver example program, on the serial port, is this:

tera term rx

Frequencies and signal clock rate

The signal generated by a PT2262 represents 0, 1 and F as a sequence of pulses:

 

Ternary Digit Pulse Sequence
0 short pulse + short pulse
1 long pulse + long pulse
F short pulse + long pulse

pulses

 

To build a valid/complete transmission, 4 code words must be transmitted. Each code word consists of a sequence of 12 ternary digits encoded as indicated above, including a final sync short pulse with a period of 128 * Talfa.

With the current frequencies (FOSC = 10MHz, Falfa = 10KHz), the encoder needs timer1 in 16bit mode and ccp1 to generate the pulses with the proper timings. Currently the constants are:

  • Talfa = 250
  • Pulseshort = 4 * Talfa = 1000
  • Pulselong = 12 * Talfa = 3000
  • Tperiod = 16 * Talfa = 4000
  • Tsync = 128 * Talfa = 32000

The decoder uses timer0 in 8 bit mode with a 1:16 prescaler and the interrupt on change feature of port B.

  • Talfa = 15
  • Pulseshort = 4 * Talfa = 60
  • Pulselong = 12 * Talfa = 180
  • Tperiod = 16 * Talfa = 240
  • Tsync = 128 * Talfa = 1920 (8 bit overflow)

The overflow condition is detected by the timer0 interrupt that only fires at this situation. It then finalizes the decoding process and resets the state machine to prepare it for the next frame.

If you plan to use this codec in a circuit with another FOSC, please take time to review the macros in both pt2262.c and pt2272.c to make sure there are no overflows. The same thing must be done if you need another clock rate on the decoder or encoder.

 

Downloads

References

  1. Adafruit 2272 receiver board
  2. DX 2272 receiver board and remote controller
  3. DX pair of 433MHz transmitter and receiver

 

 

Published on Monday 2014/10/27, last modified on Tuesday 2014/11/04