Ok, so further testing - this time using Audacity to record the waveforms as it gives me more freedom to scroll back and forth - has resulted in the following 3 waveforms: http://img527.imageshack.us/my.php?i...8222006dl4.png
I'm going to opt to completely ignore the first transmission sequence as the start of it is a little messed up and target the second transmission sequence (I pushed the button as fast as I could, I always got 2 or more sequences).
So the following code is what I've got (haven't run it yet).
Does it look right?
I was playing around with it before as '1's instead of '0's in pulsin but it was picking up the block of 0's not the block of 1's. (If that makes any sense)
I've decided to chop the data comming up as
ADDRESS-DATA-S
1111000100110101-11000000-0
1111000100110101-00110000-0
1111000100110101-00000011-0
Following the encoder's specs this is actually
110F01FF1000S
110F01FF0100S
110F01FF0001S
F = Floating
S = Sync
Further reading of the specs - there'll be 4 sequences. Seeing as the first of the sequence is trashed, I just need to record and compare the other 3
Code:
' Configure the FUSE options for the compiler
@ device pic16F628A, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off, bod_on, cpd_off, pwrt_off, mclr_off
' Running a 4Mhz clock
DEFINE OSC 20
DEFINE PULSIN_MAX 3000
' Setup the USART
DEFINE HSER_RCSTA 90h ' Receive register to receiver enabled
DEFINE HSER_TXSTA 20h ' Transmit register to transmitter enabled
DEFINE HSER_BAUD 9600 ' Set baud rate
CMCON = 7
ALL_DIGITAL
RFIN VAR PORTB.7
INPUT RFIN
PBITS VAR BYTE[17] ' The bits we've read
RAW VAR BYTE ' The raw pulsin value
ADDRESS VAR WORD ' Storage for the address
DBYTE VAR BYTE ' Storage for the data
X VAR BYTE
Y VAR BYTE
GET_ADD:
ADDRESS = 0 : RAW = 0 : DBYTE = 0
GET_PULSE:
' Count 4 long pulses.
FOR x = 0 TO 3
PULSIN RFIN, 0, RAW
if RAW < 220 OR RAW > 230 THEN GET_PULSE
NEXT X
' Count 3 short pulse.
FOR X = 0 to 2
PULSIN RFIN, 0, RAW
IF RAW < 70 OR RAW > 80 THEN GET_PULSE
NEXT X
' Read 9 address bits and 8 data bits
FOR X = 0 TO 16
PULSIN RFIN, 0, RAW
PBITS[x] = NCD RAW
NEXT X
' Read a sync bit
PULSIN RFIN, 0, RAW
IF RAW < 70 OR RAW > 80 THEN GET_PULSE
ADDRESS = 511 ' Maxmimum known ID
FOR X = 0 to 8
IF PBITS[x] > 7 THEN ADDRESS.0[X] = 0
NEXT X
DBYTE = 255 ' Maximum known data value
Y=0
FOR X = 9 TO 16
IF PBITS[X] > 7 THEN DBYTE.0[Y] = 0
Y = Y + 1
NEXT X
IF ADDRESS > 0 THEN
WRITE 1, ADDRESS.LowByte
WRITE 2, ADDRESS.HighByte
Write 3, DBYTE
HSEROUT ["ADD = ",IBIN9 ADDRESS," : ",IDEC ADDRESS,13,10]
HSEROUT ["DAT = ",IBIN8 DBYTE," : ",IDEC DBYTE,13,10]
ENDIF
GOTO GET_ADD
END
Bookmarks