This is a multi-part message in MIME format. ------=_NextPart_000_02A5_01C7956D.A613D540 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > That would be lovely, thanks! Okey-doke. Any questions, please ask As I said, I want to write this up properly, so for now I'll keep it to an understandable minimum The attached diagram will help explain. Note that I do not recall what ID is represented in that diagram, and that bits of a byte are on screen as MSB on the left and LSB on the right. Each original data bit is converted to a bit pair by the Manchester The first thing with these receivers is that with no signal present they turn up the AGC, looking for any 433MHz, resulting in random noise from the output. The second thing is that the output needs to be stabilised with a DC-balanced preamble (equal-ish number of '0' and '1') before you can get meaningful data out. IOW, the output needs to settle down for a few ms at least, and a pre-amble will do that My application uses two 12F675s clocked with 4MHz internal. The receiver PIC needs to match its timing to the transmitter, which uses (approx) 1ms bit length. Two bytes of data are sent = 32 bits of Manchester So, from left to right - (my application in particular) The PIC waits with a timer running that has a rollover of about 4ms. Noise is generally shorter than this (occassionally it isn't but I'll get to that). The timer is reset anytime there's a transition before rollover, so PIC only moves on to data detection if the timer rolls over ;================== t1off macro bcf t1con,tmr1on endm t1on macro bsf t1con,tmr1on endm #define rx_data gpio,2 ;output from receiver #define echo gpio,4 ;echo received data #define marker gpio,5 ;indicator #define t1over pir1,tmr1if ;================== clrf tmr1l ;reset Timer1 movlw 0xf1 ;4ms (approx) to rollover movwf tmr1h bcf t1over ;clear rollover flag t1on ;start Timer1 reload1 clrf tmr1l movlw 0xf1 movwf tmr1h bcf t1over ;clear rollover flag test1 btfss rx_data ;skip if pin still high goto reload1 ;pin went low before rollover btfss t1over ;rollover goto test1 ;pin still high, re-test Once it's detected a long '1' the PIC assumes a pre-amble and looks for the transitions. When it gets to the 55 it measures 4 bits. That timing is used as the basis for the 1-bit data sampling t1on ;start timing bsf marker ;time 4 bits btfsc rx_data goto $-1 ;'0' btfss rx_data goto $-1 ;'1' btfsc rx_data goto $-1 ;'0' btfss rx_data goto $-1 ;'1', start of bit5 t1off ;stop timing bcf marker ;calculate during data = 1 time movfw tmr1l movwf temp0 movfw tmr1h movwf temp1 movlw d40 ;a little compensation for subwf temp0 ;reload delays skpc decf temp1 clrc ;/4 = 1 bit time rrf temp1 rrf temp0 clrc rrf temp1 rrf temp0 movfw temp0 ;1 bit time in reload movwf reload_lo movfw temp1 movwf reload_hi comf reload_lo ;negate for count up comf reload_hi incfsz reload_lo goto $+2 incf reload_hi clrc ;/2 = 1/2 bit time rrf temp1 rrf temp0 comf temp0 ;negate comf temp1 incfsz temp0 goto $+2 incf temp1 movfw temp0 ;1/2 bit time in timer movwf tmr1l movfw temp1 movwf tmr1h Part of the pre-amble detection is rejection of a long (>4ms) '1' followed by noise that doesn't conform to the pre-amble format. In one situation I wondered why the receiver was appearing to be triggered by a transmitter that wasn't powered up. The answer turned out to be simple (and my fault). It's possible for a long '1' to be followed by a quiet period. The PIC was sampling that quiet period and producing an ID of h00. What ID was the receiver looking for ? Yup, h00. So I toughened up the detection routine God bless logic analysers The pre-amble is terminated by a 1111 -> 0 transition. At this point the PIC waits for 1/2-bit, then starts sampling After 32 bits have been received, the bits are compiled back to two data bytes and compared with the ID of the transmitter (they operate in ID-matched pairs) ;================================================ ; Get data bits ;================================================ ;rx_byte+0 is start of 4-byte array for received bits movlw .31 ;pick up and shift 31 bits movwf cnt0 next_bit bsf in_bit ;assume bit = 1 btfss rx_data bcf in_bit ;else bit = 0 movfw rx_byte+3 ;echo received bit on gpio andlw b'10000000' bnz echo1 ;in_bit = 1 echo0 bcf echo goto rotate echo1 bsf echo rotate clrc rrf rx_byte+3 rrf rx_byte+2 rrf rx_byte+1 rrf rx_byte+0 bsf marker bcf t1over btfss t1over goto $-1 ;delay until middle of next bit bcf marker t1off movfw reload_lo movwf tmr1l movfw reload_hi movwf tmr1h t1on decfsz cnt0 goto next_bit last_bit bsf in_bit ;get last bit, no shift btfss rx_data bcf in_bit ;================================================ ;decode 4 bytes of Manchester t1off bsf marker movlw rx_byte+0 movwf fsr movfw indf ;combine rx_byte+0 movwf temp0 incf fsr movfw indf ;and rx_byte+1 movwf temp1 call combine movfw temp2 movwf in_byte1 ;into 1 byte incf fsr movfw indf ;combine rx_byte+2 movwf temp0 incf fsr movfw indf ;and rx_byte+3 movwf temp1 call combine movfw temp2 movwf in_byte2 ;into 1 byte movlw byte1 ;compare received with ID xorwf in_byte1,w bnz no_match movlw byte2 xorwf in_byte2 bnz no_match match - routine here for IDs equal (accepts more data etc) no_match - routine here for IDs different (resets back to waiting) ;================================================ ; convert 2 bytes Manchester to 1 byte data ;================================================ combine rrf temp0,w andlw b'00000001' btfsc temp0,3 iorlw b'00000010' btfsc temp0,5 iorlw b'00000100' btfsc temp0,7 iorlw b'00001000' movwf temp2 swapf temp2 rrf temp1,w andlw b'00000001' btfsc temp1,3 iorlw b'00000010' btfsc temp1,5 iorlw b'00000100' btfsc temp1,7 iorlw b'00001000' addwf temp2 swapf temp2 return ;================== ; Transmitter output ;================== ;16-bit ID sent from transmitter byte1 set "I" ;LSB byte2 set "D" ;MSB ; M L ;eg 'A' 0x41 converted to 01 10 01 01 01 01 01 10 ; 0 1 0 0 0 0 0 1 ; ; p/a L M ;and sent LSB first 1111 01 10 10 10 10 10 01 10 ; 1 0 0 0 0 0 1 0 ;================================================ ;Convert bytes to Manchester convert1 movlw byte1 movwf temp movlw b'01010101' ;assume all bits are 0 movwf man1_lo movwf man1_hi movlw b'00000011' ;setup invert mask btfsc temp,0 ;test bit 0 xorwf man1_lo ;invert code if 1 btfsc temp,4 ;test bit 4 xorwf man1_hi ;invert code if 1 movlw b'00001100' ;same as above, repeated 3 times btfsc temp,1 xorwf man1_lo btfsc temp,5 xorwf man1_hi movlw b'00110000' btfsc temp,2 xorwf man1_lo btfsc temp,6 xorwf man1_hi movlw b'11000000' btfsc temp,3 xorwf man1_lo btfsc temp,7 xorwf man1_hi convert2 movlw byte2 movwf temp movlw b'01010101' ;assume all bits are 0 movwf man2_lo movwf man2_hi movlw b'00000011' ;setup invert mask btfsc temp,0 ;test bit 0 xorwf man2_lo ;invert code if 1 btfsc temp,4 ;test bit 4 xorwf man2_hi ;invert code if 1 movlw b'00001100' ;same as above, repeated 3 times btfsc temp,1 xorwf man2_lo btfsc temp,5 xorwf man2_hi movlw b'00110000' btfsc temp,2 xorwf man2_lo btfsc temp,6 xorwf man2_hi movlw b'11000000' btfsc temp,3 xorwf man2_lo btfsc temp,7 xorwf man2_hi ;Send pre-amble to stabilise receiver and time-align decoding PIC ; ;Pre-amble is 0f 0f 55 f0 0 ;Each whole byte sent LSb first ;-> bits received in order f0 f0 55 0f 0 ; 1111>0 ^ marks end of pre-amble bytes preamble movlw 0x0f movwf temp0 call snd_byte movlw 0x0f movwf temp0 call snd_byte movlw 0x55 movwf temp0 call snd_byte movlw 0xf0 movwf temp0 call snd_byte ;send '0' bit to signal end of pre-amble ;marks end of '1111' bits of f0 bcf tx_data ;0 call ms1 ; routine to send Manchester send movlw .16 ;send first 16 bits movwf cnt0 ;Each bit loop takes 1ms @ 4MHz tx_loop bcf tx_data ;assume 0 bit btfss out_bit ;test for actual value goto data_tx ;bit is 0 bsf tx_data ;bit is 1 data_tx call ms1 ;hold for 1ms rrf man1_hi rrf man1_lo decfsz cnt0 goto tx_loop movfw man2_lo ;next 16 bits movwf man1_lo movfw man2_hi movwf man1_hi decfsz cnt1 goto send movfw gpio movwf temp0 bcf temp0,1 bcf temp0,4 movfw temp0 movwf gpio nop nop bcf led ------=_NextPart_000_02A5_01C7956D.A613D540 Content-Type: image/gif; name="sampling.gif" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="sampling.gif" R0lGODlhsQRUAIAAAAAAAP///ywAAAAAsQRUAEAC/oyPqcvtD6OctNqLs968+w+G4kiW5omm6sq2 7gvH8kzX9gwYObDrQe7jJYC/YvCwIwJ7x+LyBo3WnkOks3o19pTGrvR7IXrHwqtYyzRbuVCum5k8 puFnsP2Oz+v3/B/vWcfwN0hYaHiImKi4yNjo+AgZGdhHGSV5iTlYufmV6fkJGio6SlpqeoqaqrrK 2orKCRvbMClbq0JraZsn9odU5qdE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vZHup2ugiji2xhlsVTFNSNsmTtc534Xg9Ft33LFG17yJte01v1ee3lU3b+JVat2jWvx RjpJ5B73tec1b3r9q1/v9reQAZbkc1Vrz/dmdrOGzet90bte4maSvxEG735ZC93/EpjCBVZuhbdL TwWfKL71wyuGYzteAAv4wq3troFTvOEXa9i1J8avZEVcIRK7F8UDprGHO5xhIPP4wyqWMZFj3OIJ 1xjE88QxhXTMPRMnubxIDvKKr8zhLBtZyBbG8o+1POUZV3bMZC6zmc+M5jSrec1sbrOb3wznOMt5 zjDTqMzUukdqJRZ0tugkjhua/hYY+9jKtZjuMnp45Nn57sCopPKgJexoF2NS0PBytIZYeucC8hFu sQIkAz1V6UQjuoKJBFqP8+vl2Qr6eJSWNHuVrOoe7zbMpD6Ond0SkjyvcM9/ZBguwfivUHNZvcMG tqlFzWgI1/rUI3D1kItdZUjzWdbJHuxGbn1ZPGu7Jbwm4Qu//Zduz5rTgmTxs7d8yFI3S5ZFpjW0 H31Fczvy3at195LbDUlKV1vcncZjpqe163HPO2JWDPdu/wzLGTu7y4WGJrujzfB7Q9zg8o43mF+9 alibld5J1LgEE7YNf+Na27adhT/lVHCCX1FbTA22x5WNbkKpe0bmwre0kR1B/mbLkeOtznjOEy3w iG/c5V89h8izrWk9B53iKq+iO0qusHL/uuLqizRyEonSlxM71UOX+NKrrvOwU93aPKci1zc7tXIc HVQkNyC/891wRG4C0MK++M3t3mjazlzod8f71i0pZq3bnO82trrZ/R4Gwa+7a3RuvOMfD/nI58/J kq+85S9f99BifvOc7zwN91jMiUJ97p4vveml69TuYIjyQz29619fz/qCXrvUGT3sVwZc0Oon7bfv POt7D1cjfVX2MVWab013HmSWFapfm+vXEQb86EtfOUkbPn2jKUvGnxzcZPWsYGOJC1pmYvrkL7+v u5kkkAbTRjVf6frfL6eKKMJ/rexP6/zhY/786/+s+++///8PgAEogANIgAVogAeIgAmogBNQAAAA Ow== ------=_NextPart_000_02A5_01C7956D.A613D540 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ------=_NextPart_000_02A5_01C7956D.A613D540--