I posted a simple example for decoding a Holtek 8-bit encoder here;
http://www.picbasic.co.uk/forum/showthread.php?t=6581
The Holtek 640 encoder is similar to the one you have with 2 pulses per bit, but the Holtek
packets are 10-bit address with 8-bit data. It should at least give you a good base to start
from.
Here's a simple chopped-down version example of decoding a Holtek HT12E.
Code:
DEFINE OSC 20 ' 20MHz xtal
DEFINE PULSIN_MAX 3000 ' Set MAX wait for pulses to speed-up response time
PBIT VAR BYTE[12]' Pulse-in values after NCD
NUMS VAR WORD ' RAW pulsin value
ADDRESS VAR BYTE ' address
DBYTE VAR BYTE ' data byte
X VAR BYTE ' GP loop counter
Y VAR BYTE ' GP variable
DIN VAR PORTB.0 ' Data input direct from HT12E encoder IC
TRISB.0=1
GET_ADD:
ADDRESS=0 : DBYTE=0 : NUMS=0
GET_P:
PULSIN DIN,1,NUMS
IF NUMS < 100 THEN GET_P '
' if sync pulse is less than 200uS restart.
FOR X = 0 TO 11 ' read 12 pulses
PULSIN DIN,1,NUMS '
PBIT[X] = NCD NUMS ' convert high-bit-set
NEXT X ' loop until done
' Get address
ADDRESS=$FF ' start with all 1's and find each 0
FOR X = 0 TO 7 ' PBIT bytes 0 to 7 = address
IF PBIT[X] >7 THEN ADDRESS.0[X] = 0 ' If NCD val > 7 it's a 0
NEXT X
' Get data
Y=0
DBYTE=$0F ' start with all 1's and find each 0
FOR X = 8 TO 11 ' PBIT bytes 8 to 11 = encoder 4-bit data
IF PBIT[X] >7 THEN DBYTE.0[Y]=0' DBYTE bits 0 to 3 are our data-bits
Y=Y+1
NEXT X
' show results
HSEROUT ["ADD = ",IBIN8 ADDRESS," : ",IDEC ADDRESS,13,10]
HSEROUT ["DAT = ",IBIN4 DBYTE," : ",IDEC DBYTE,13,10]
GOTO GET_ADD
END
The .JPG file attached shows a logic analyzer capture of the HT12E output.
Serial terminal result;
ADD = %10111011 : #187
DAT = %1011 : #11
This matches the address & data I had set on the HT12E encoder when the program ran.
You can change the address & data, press /TE, and watch the results on-screen.
Note: This code example is a chopped version with only a single-pass. In most
applications you will want to do 2 or 3 passes, then verify multiple address/data packets
before you change a decoders outputs. Otherwise it's prone to errors.
This version is suceptible to noise. That's why it was tested with a direct connection from
encoder to PIC input. This remains stable. The data output of an RF receiver however, is a
diferent story. You'll se a TON of noise pulses there.
The tricky part is working in the multi-pass & verify routines. That part I can't share...;o}
Bookmarks