Microcontroller with 2 way paging application problem


Closed Thread
Results 1 to 31 of 31
  1. #1
    Join Date
    Mar 2007
    Posts
    42

    Default Microcontroller with 2 way paging application problem

    I am trying to make a 2 way paging system with a TLP-434, RLP-434, TLP-315 and RLP-315. The 434 MHz is the uplink and 315 MHz is the downlink. The uplink works perfectly since it always receives data and does operations on it. But the downlink does not work fully, there are instances where the microcontroller on the receiver side does not receive a signal and sometimes it receives it. I have to send the same code at the receiver (microcontroller attached to the RLP-434 with an output to the TLP-315) The microcontroller I am using is the PIC16F88. I have starred (**) the portions that I think might be having problems with. The code I am using is down below:

    TRANSMITTER (WORKS):
    'IEEE Encoding
    'Transmitter Code
    Include "Modedefs.bas"
    'trisb = 0
    main:
    u var byte : counter var byte : encode var byte : u = %1101
    'u is the byte containing the input in binary, counter is a byte that describes the amount of bits to encode
    'encode is the variable holding the encoded value
    'Manchester encoding
    For counter = 0 to 3
    If u.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter : serout PORTB.0, n2400, [ $55 , $55 ,$55, $55, $aa , encode ] 'send out preamble and encoded from Port B Pin 0
    write 0, encode 'Write to EEPROM Location 0
    High 1 'High on Port B Pin 1
    Pause 1000 'Pause
    Low 1 'Low on Port B Pin 1
    goto main

    RECEIVER (RLP-434 output to TLP-315) (works but not sure about serout)
    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : encode var byte: encode2 var byte 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: counter2 var byte'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    'counter2 counts the number of times acknowledge light blinks.
    encode1 var byte : action var byte : alert var byte : action2 var byte: B0=1 : B1=1: counter3 var byte
    'encode1 byte sized variable that holds encoded byte s, alert variable, action variable used for trakcing mode, action2 used for track and find mode, B0 and B1 are the hardwired address
    c var byte: d var byte: e var byte: s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0
    'c (track mode), d (track and find) and e(address) are bytes; initialize all values to zero
    'encode holds the encoded variable after ack made in track mode, encode2 holds the encoded variable after ack made in track and find mode.

    Main:

    Clr:
    s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
    Else
    goto maina 'if not $55, reset counter at main and restart
    Endif
    goto wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    'High 2 'High on Port B Pin 2
    'Pause 2000 'Pause
    'Low 2 'Low on Port B Pin 2


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    'High 6 'High on Port B Pin 6
    'Pause 2000 'Pause
    'Low 6 'Low on Port B Pin 6


    e = s 'Copy s to byte e
    If ((e.3=B0) and (e.2=B1)) Then 'Check if address matches (first two bits)
    goto L3 'if it matches go to L3
    Else
    write 2,s 'Write to EEPROM Location 2
    High 3 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 3 'Low on Port B Pin 2
    goto Clr
    Endif

    L3:
    'Tracking mode (mode is based on last two bits)
    c=s: d=s: 'Copy s to byte c and s to byte d
    If ((c.1=0) and (c.0=0)) Then
    action=s: 'Copy s to action byte
    action.1=1'set the third bit of action1 to 1 and send it back
    'alert = 0: 'set alert to 0
    write 3, action 'Write to EEPROM Location 3
    High 6 'High on Port B in 1
    Pause 2000 'Pause
    Low 6 'Low on Port B in 1
    'Manchester Encoding
    For counter = 0 to 3
    If action.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    write 8, encode 'Write encode to EEPROM Location 8
    Low 4 'Low on Port B Pin 4
    For counter = 0 to 5 'Blink LED 5 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter 'Back to beginning of loop
    **For counter = 0 to 10 'Send three times
    serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
    Next counter 'Next number
    goto Clr
    Endif

    'Tracking and Finding mode (is based on last two bits)
    If ((d.1=0) and (d.0=1)) Then
    action2=s 'Copy s to action2 byte
    action2.1=1 'set the third bit of action2 to 1 and send back
    'alert=1
    write 4, action2 'Write to EEPROM Location 4
    High 5 'High on Port B Pin 4
    Pause 2000 'Pause
    Low 5 'Low on Port B Pin 4
    'Manchester Encoding
    For counter = 0 to 3
    If action2.0[counter]=0 Then
    encode2.0[counter*2]=0 : encode2.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode2.0[counter*2]=1 : encode2.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    'serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $aa , encode2 ] 'send out preamble and code to Port B Pin 2
    write 9, encode2 'Write encode2 to EEPROM Location 9
    Low 4 'Low on Port B Pin 4
    For counter2 = 0 to 5 'Blink LED 50 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter2 'Back to beginning of loop
    Low 1 'Low on Port B Pin 4
    For counter = 0 to 50 'Blink LED 50 times
    Pause 400 'Pause
    High 1 'High on Port B Pin 1
    Pause 400 'Pause
    Low 1 'Low on Port B Pin 1
    Next counter: 'Back to beginning of loop
    **For counter3 = 0 to 5 'Send data times
    serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    End

    RECEIVER (after RLP-315, downlink) (works sometimes)
    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: 'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    encode1 var byte : B0=0 : B1=1
    'encode1 byte sized variable that holds encoded byte s, B0 and B1 are the hardwired address
    e var byte: s=0: encode1=0:e=0
    ' e are bytes; initialize s, encode1, and e values to zero
    'encode1 holds the encoded variable received.

    Main:

    Clr:
    s=0: encode1=0: e=0: 'encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
    Else
    goto maina 'if not $55, reset counter at main and restart
    Endif
    goto wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    High 7 'High on Port B Pin 7
    Pause 2000 'Pause
    Low 7 'Low on Port B Pin 7


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    High 6 'High on Port B Pin 6
    Pause 2000 'Pause
    Low 6 'Low on Port B Pin 6

    e=s
    If ((e.1==1)) Then 'Acknowledgment received because third bit is 1
    goto L4 'Jump to L4
    Else
    write 2,s 'Write to EEPROM Location 2
    High 2 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 2 'Low on Port B Pin 2
    goto Clr
    Endif

    L4:

    write 3, e 'Write to EEPROM Location 3
    High 1 'High on Port B in 1
    Pause 2000 'Pause
    Low 1 'Low on Port B in 1
    serout PORTB.3, n2400, [e] 'send out preamble and code on PORTB pin 1
    goto Clr


    End

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I remember this....
    Anyways, one of the things I suggested was to send a bunch of preamble bytes, wait until you received a bunch, switch to checking for another byte, waiting for that one, then getting your data.
    In your program, you send 4 $55's as the preamble. That's good amount for a preamble. I think the problem might be that on your receiver, you also wait for 4 $55's. It takes a little bit of time for those $55's to do their thing, to get the receiver's attention if you want to call it that. In other words, you send 4, but you might only get 2 at the receiver.

    Either try sending more than 4 $55's on the transmitter, and leave your receiver code the same, or try looking for only 2 $55's in your receiver and leave the transmitter the same.

  3. #3
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Also, should I continue to serout more than once at my receiver microcontroller (RLP-434 output to TLP-315)?

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    Also, should I continue to serout more than once at my receiver microcontroller (RLP-434 output to TLP-315)?
    Probably wouldn't be a bad idea. Add a byte for a 'data identifier number' and a checksum or something like that so you can receive the same data more than once but only act on it once and only if it's correct.

  5. #5
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I increased the amount of $55 at the receiver (to transmit) and kept the amount of $55 that the other receiver needs to detect the same, it seems to be working every time. Also, the data that it is receiving is correct also. So, it seems to be working.

  6. #6
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I updated my code and tested it out. But, I noticed that my code does not work in every case. There is one code that only works for one combination (1101) and nothing else. While there is another code that works for other cominbations (0101,0100,1100) but not one cominbation (1101). What I mean by work is it serouts to the 315 MHz transmitter and lights LEDs at the microcontroller after the 315 MHz receiver. When I serout I send about 8-9 $55, then a $aa, then my encoded data. At the microcontroller after the 315 MHz receiver, I tell it to look for 4 $55 instead of the 8 $55 I sent. I am not sure why this behaves weirdly.



    Receiver (after 434 MHz receiver and before 315 MHz transmitter) code 1
    (works ONLY for 1101)
    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : encode var byte: encode2 var byte 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: counter2 var byte'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    'counter2 counts the number of times acknowledge light blinks.
    encode1 var byte : action var byte : alert var byte : action2 var byte: B0=1 : B1=1: counter3 var byte
    'encode1 byte sized variable that holds encoded byte s, alert variable, action variable used for trakcing mode, action2 used for track and find mode, B0 and B1 are the hardwired address
    c var byte: d var byte: e var byte: s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0
    'c (track mode), d (track and find) and e(address) are bytes; initialize all values to zero
    'encode holds the encoded variable after ack made in track mode, encode2 holds the encoded variable after ack made in track and find mode.

    Main:

    Clr:
    s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
    Else
    goto maina 'if not $55, reset counter at main and restart
    Endif
    goto wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    'High 2 'High on Port B Pin 2
    'Pause 2000 'Pause
    'Low 2 'Low on Port B Pin 2


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    'High 6 'High on Port B Pin 6
    'Pause 2000 'Pause
    'Low 6 'Low on Port B Pin 6


    e = s 'Copy s to byte e
    If ((e.3=B0) and (e.2=B1)) Then 'Check if address matches (first two bits)
    goto L3 'if it matches go to L3
    Else
    write 2,s 'Write to EEPROM Location 2
    High 3 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 3 'Low on Port B Pin 2
    goto Clr
    Endif

    L3:
    'Tracking mode (mode is based on last two bits)
    c=s: d=s: 'Copy s to byte c and s to byte d
    If ((c.1=0) and (c.0=0)) Then
    action=s: 'Copy s to action byte
    action.1=1'set the third bit of action1 to 1 and send it back
    'alert = 0: 'set alert to 0
    write 3, action 'Write to EEPROM Location 3
    High 6 'High on Port B in 1
    Pause 2000 'Pause
    Low 6 'Low on Port B in 1
    'Manchester Encoding
    For counter = 0 to 3
    If action.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    write 8, encode 'Write encode to EEPROM Location 8
    Low 4 'Low on Port B Pin 4
    For counter = 0 to 5 'Blink LED 5 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter 'Back to beginning of loop
    For counter3 = 0 to 50 'Send three times
    serout PORTB.2, n2400, [ $55, $55, $55, $55, $55, $55, $55, $55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    'Tracking and Finding mode (is based on last two bits)
    If ((d.1=0) and (d.0=1)) Then
    action2=s 'Copy s to action2 byte
    action2.1=1 'set the third bit of action2 to 1 and send back
    'alert=1
    write 4, action2 'Write to EEPROM Location 4
    High 5 'High on Port B Pin 4
    Pause 2000 'Pause
    Low 5 'Low on Port B Pin 4
    'Manchester Encoding
    For counter = 0 to 3
    If action2.0[counter]=0 Then
    encode2.0[counter*2]=0 : encode2.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode2.0[counter*2]=1 : encode2.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    'serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $aa , encode2 ] 'send out preamble and code to Port B Pin 2
    write 9, encode2 'Write encode2 to EEPROM Location 9
    Low 4 'Low on Port B Pin 4
    For counter2 = 0 to 5 'Blink LED 50 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter2 'Back to beginning of loop
    Low 1 'Low on Port B Pin 4
    For counter = 0 to 50 'Blink LED 50 times
    Pause 400 'Pause
    High 1 'High on Port B Pin 1
    Pause 400 'Pause
    Low 1 'Low on Port B Pin 1
    Next counter: 'Back to beginning of loop
    For counter3 = 0 to 5 'Send data times
    serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $55, $55, $55, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    End

  7. #7
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Receiver (after 434 MHz receiver and before 315 MHz transmitter) code 1
    (works for 0101, 0100, 1100)

    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : encode var byte: encode2 var byte 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: counter2 var byte'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    'counter2 counts the number of times acknowledge light blinks.
    encode1 var byte : action var byte : alert var byte : action2 var byte: B0=1 : B1=1: counter3 var byte
    'encode1 byte sized variable that holds encoded byte s, alert variable, action variable used for trakcing mode, action2 used for track and find mode, B0 and B1 are the hardwired address
    c var byte: d var byte: e var byte: s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0
    'c (track mode), d (track and find) and e(address) are bytes; initialize all values to zero
    'encode holds the encoded variable after ack made in track mode, encode2 holds the encoded variable after ack made in track and find mode.

    Main:

    Clr:
    s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
    Else
    goto maina 'if not $55, reset counter at main and restart
    Endif
    goto wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    'High 2 'High on Port B Pin 2
    'Pause 2000 'Pause
    'Low 2 'Low on Port B Pin 2


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    'High 6 'High on Port B Pin 6
    'Pause 2000 'Pause
    'Low 6 'Low on Port B Pin 6


    e = s 'Copy s to byte e
    If ((e.3=B0) and (e.2=B1)) Then 'Check if address matches (first two bits)
    goto L3 'if it matches go to L3
    Else
    write 2,s 'Write to EEPROM Location 2
    High 3 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 3 'Low on Port B Pin 2
    goto Clr
    Endif

    L3:
    'Tracking mode (mode is based on last two bits)
    c=s: d=s: 'Copy s to byte c and s to byte d
    If ((c.1=0) and (c.0=0)) Then
    action=s: 'Copy s to action byte
    action.1=1'set the third bit of action1 to 1 and send it back
    'alert = 0: 'set alert to 0
    write 3, action 'Write to EEPROM Location 3
    High 6 'High on Port B in 1
    Pause 2000 'Pause
    Low 6 'Low on Port B in 1
    'Manchester Encoding
    For counter = 0 to 3
    If action.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    write 8, encode 'Write encode to EEPROM Location 8
    Low 4 'Low on Port B Pin 4
    For counter = 0 to 5 'Blink LED 5 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter 'Back to beginning of loop
    For counter3 = 0 to 50 'Send three times
    serout PORTB.2, n2400, [ $55, $55, $55, $55, $55, $55, $55, $55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    'Tracking and Finding mode (is based on last two bits)
    If ((d.1=0) and (d.0=1)) Then
    action2=s 'Copy s to action2 byte
    action2.1=1 'set the third bit of action2 to 1 and send back
    'alert=1
    write 4, action2 'Write to EEPROM Location 4
    High 5 'High on Port B Pin 4
    Pause 2000 'Pause
    Low 5 'Low on Port B Pin 4
    'Manchester Encoding
    For counter = 0 to 3
    If action2.0[counter]=0 Then
    encode2.0[counter*2]=0 : encode2.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode2.0[counter*2]=1 : encode2.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    'serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $aa , encode2 ] 'send out preamble and code to Port B Pin 2
    write 9, encode2 'Write encode2 to EEPROM Location 9
    Low 4 'Low on Port B Pin 4
    For counter2 = 0 to 5 'Blink LED 50 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter2 'Back to beginning of loop
    Low 1 'Low on Port B Pin 4
    For counter = 0 to 10 'Blink LED 50 times
    Pause 400 'Pause
    High 1 'High on Port B Pin 1
    Pause 400 'Pause
    Low 1 'Low on Port B Pin 1
    Next counter: 'Back to beginning of loop
    For counter3 = 0 to 50 'Send data times
    serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $55, $55, $55, $55, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    End


    Receiver code for microcontroller after the 315 MHz receiver.
    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: 'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    encode1 var byte : B0=0 : B1=1
    'encode1 byte sized variable that holds encoded byte s, B0 and B1 are the hardwired address
    e var byte: s=0: encode1=0:e=0
    ' e are bytes; initialize s, encode1, and e values to zero
    'encode1 holds the encoded variable received.

    Main:

    Clr:
    s=0: encode1=0: e=0: 'encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
    Else
    goto maina 'if not $55, reset counter at main and restart
    Endif
    goto wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    High 7 'High on Port B Pin 7
    Pause 2000 'Pause
    Low 7 'Low on Port B Pin 7


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    High 6 'High on Port B Pin 6
    Pause 2000 'Pause
    Low 6 'Low on Port B Pin 6

    e=s
    If ((e.1==1)) Then 'Acknowledgment received because third bit is 1
    goto L4 'Jump to L4
    Else
    write 2,s 'Write to EEPROM Location 2
    High 2 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 2 'Low on Port B Pin 2
    goto Clr
    Endif

    L4:

    write 3, e 'Write to EEPROM Location 3
    High 1 'High on Port B in 1
    Pause 2000 'Pause
    Low 1 'Low on Port B in 1
    serout PORTB.3, n2400, [e.3] 'send out first bit from PORTB Pin 3
    serout PORTB.4, n2400, [e.2] 'send out second bit from PORTB Pin 4
    goto Clr

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    e = s 'Copy s to byte e
    ...
    ...
    ...
    e=s

    on those two you missed the semicolon. As for the rest, try simple code, 4-5 preambles and a byte to see if you have good communication. Then try two bytes different this time. Your code needs a lot of examination and right now I can't read it.

    Ioannis

  9. #9
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Should I change my preamble to a different byte such as $66, $66, $66, $66, $bb,... or should I increase the size?

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    Should I change my preamble to a different byte such as $66, $66, $66, $66, $bb,... or should I increase the size?
    Preamble byte has to be an equal number of 0's and 1's equally spaced. $66/$BB don't work, not equally spaced.

  11. #11
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Ok, I guess I will keep $55 and $aa. But, I do not understand why my reverse link (315 MHz) works only for some combinations or not at all for other combinations, even though I am sending it 50 times.

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    But, I do not understand why my reverse link (315 MHz) works only for some combinations or not at all for other combinations, even though I am sending it 50 times.
    What combo works, and which don't...

  13. #13
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    In the receiver code I posted in post #6 only a code of 1101 works.
    In the receiver code I posted in post #7 1100, 0101, 0100 works but not 1101. In all these cases the forward link (434 MHz) works all the time (in the cases where the first two bits (address) are different I changed the two bits (B0, B1) that are hardcoded in the code so that everything will work) but the reverse link (315 MHz) works only for the combinations I specified above.
    Last edited by oneohthree; - 18th April 2007 at 17:34.

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    In the receiver code I posted in post #6 only a code of 1101 works.
    In the receiver code I posted in post #7 1100, 0101, 0100 works but not 1101. In all these cases the forward link (434 MHz) works all the time (in the cases where the first two bits (address) are different I changed the two bits (B0, B1) that are hardcoded in the code so that everything will work) but the reverse link (315 MHz) works only for the combinations I specified above.
    I suspect, in fact I'd bet on, a programming problem, some sort of logic flow problem somewhere. I had a feeling way back when, that all this bit changing was going to cause problems and there had to be an easier way of doing this.
    And again, I'd suggest just sending straight numbers back and forth, rather than changing bits around and the like, 'cause you're writing the program now and everything is clear to you. But what happens when you've let the program go for a couple of months and you come back to it to change something. Might not be so clear then why you did whatever...

  15. #15
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Would it be smarter if I just transmit two bits back because I only need the address bits on the other side anyway. That would not involve any bit changing just sending two bits. Also, would there be any reason why the microcontroller would not pick up anything on the other side or do it intermittently even though I am sending the same thing repeatedly? Also, if I were to do that how could, could I just reencode the code that was received and then send only the 4/8 bits that are part of the address, something like: serout PORTB.2, n2400, [ $55, $55, $55, $55, $55, $55, $55, $55, $55, $aa , encode.4, encode.5, encode.6, encode.7 ]?
    Last edited by oneohthree; - 18th April 2007 at 18:20.

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    Would it be smarter if I just transmit two bits back because I only need the address bits on the other side anyway. That would not involve any bit changing just sending two bits. Also, would there be any reason why the microcontroller would not pick up anything on the other side or do it intermittently even though I am sending the same thing repeatedly? Also, if I were to do that how could, could I just reencode the code that was received and then send only the 4/8 bits that are part of the address?
    Well, what I'm getting at is that you're only receiving X number of possible numbers which means that you're only going to send out X number of possible number. You could replace all that bit changing business with something like:
    If X = 10 then X = 15...
    Yes, it would probably be a bit more complicated than that, but you could 'name' all of your numbers (i.e. const warning=10 const alert=12 tracking=14 and so on) so you could more easily keep track of everything.

  17. #17
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I changed it so that it will only send the first two bits of the code that I sent in (the address). Did I write the code properly so that it will only take the address bits correctly. For example if my code is 1100, the address bits are 11 which are the third and fourth bit.

    For counter = 3 to 4 'take out address bits, (first two bits)
    f.0[counter]=action.0[counter]
    Next counter

  18. #18
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    I changed it so that it will only send the first two bits of the code that I sent in (the address). Did I write the code properly so that it will only take the address bits correctly. For example if my code is 1100, the address bits are 11 which are the third and fourth bit.

    For counter = 3 to 4 'take out address bits, (first two bits)
    f.0[counter]=action.0[counter]
    Next counter
    No, they are the 2nd and 3rd bit.
    Remember, we start counting from 0, not 1.

  19. #19
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I figured out that if I connect the two PICs I am having trouble with by a wire it works properly. But, when I use the RF modules it does not work properly and sometimes it reads in the wrong data.

  20. #20
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    I figured out that if I connect the two PICs I am having trouble with by a wire it works properly. But, when I use the RF modules it does not work properly and sometimes it reads in the wrong data.
    Which is why I suggested using some sort of checksum or data identifier way back in post #4.

  21. #21
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Can you give me an example of how to use checksum or a data identifier in my program? Also, is it a problem if I have to send it multiple times for the PIC to pick it up by wire?
    Last edited by oneohthree; - 18th April 2007 at 23:19.

  22. #22
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    Can you give me an example of how to use checksum or a data identifier in my program? Also, is it a problem if I have to send it multiple times for the PIC to pick it up by wire?
    Transmit the data, and also transmit it's complement (ie. transmit a $00, also send an $fe, transmit a $01, also send an $fd). Add them both up, they come out to $FF.
    At the receiver, get 2 bytes, add them up, if they don't come up to $FF, the packet isn't any good, reject it, maybe even send a seperate reject code back to the TX.
    Hundred ways to do this...

  23. #23
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I find that sometimes when I connect by wire it doesn't work. Sometimes my wireless connection works if I first connect the wire remove it and then I reconnect my wireless connection it works again. I'm not sure if the serout is not working correctly or the serin is not working correctly.

    Receiver (434)
    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : encode var byte: encode2 var byte 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: counter2 var byte'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    'counter2 counts the number of times acknowledge light blinks.
    encode1 var byte : action var byte : alert var byte : action2 var byte: B0=0 : B1=1: counter3 var byte
    'encode1 byte sized variable that holds encoded byte s, alert variable, action variable used for trakcing mode, action2 used for track and find mode, B0 and B1 are the hardwired address
    c var byte: d var byte: e var byte: s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0
    'c (track mode), d (track and find) and e(address) are bytes; initialize all values to zero
    'encode holds the encoded variable after ack made in track mode, encode2 holds the encoded variable after ack made in track and find mode.

    Main:

    Clr:
    s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
    Else
    goto maina 'if not $55, reset counter at main and restart
    Endif
    goto wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    'High 2 'High on Port B Pin 2
    'Pause 2000 'Pause
    'Low 2 'Low on Port B Pin 2


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    'High 6 'High on Port B Pin 6
    'Pause 2000 'Pause
    'Low 6 'Low on Port B Pin 6


    e = s 'Copy s to byte e
    If ((e.3=B0) and (e.2=B1)) Then 'Check if address matches (first two bits)
    goto L3 'if it matches go to L3
    Else
    write 2,s 'Write to EEPROM Location 2
    High 3 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 3 'Low on Port B Pin 2
    goto Clr
    Endif

    L3:
    'Tracking mode (mode is based on last two bits)
    c=s: d=s: 'Copy s to byte c and s to byte d
    If ((c.1=0) and (c.0=0)) Then
    action=s: 'Copy s to action byte
    action.1=1'set the third bit of action1 to 1 and send it back
    'alert = 0: 'set alert to 0
    write 3, action 'Write to EEPROM Location 3
    High 6 'High on Port B in 1
    Pause 2000 'Pause
    Low 6 'Low on Port B in 1
    'Manchester Encoding
    For counter = 0 to 3
    If action.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    write 8, encode 'Write encode to EEPROM Location 8
    Low 4 'Low on Port B Pin 4
    For counter = 0 to 5 'Blink LED 5 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter 'Back to beginning of loop
    For counter3 = 0 to 50 'Send three times
    serout PORTB.2, n2400, [ $55, $55, $55, $55, $55, $55, $55, $55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    'Tracking and Finding mode (is based on last two bits)
    If ((d.1=0) and (d.0=1)) Then
    action2=s 'Copy s to action2 byte
    action2.1=1 'set the third bit of action2 to 1 and send back
    'alert=1
    write 4, action2 'Write to EEPROM Location 4
    High 5 'High on Port B Pin 4
    Pause 2000 'Pause
    Low 5 'Low on Port B Pin 4
    'Manchester Encoding
    For counter = 0 to 3
    If action2.0[counter]=0 Then
    encode2.0[counter*2]=0 : encode2.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode2.0[counter*2]=1 : encode2.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    'serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $aa , encode2 ] 'send out preamble and code to Port B Pin 2
    write 9, encode2 'Write encode2 to EEPROM Location 9
    Low 4 'Low on Port B Pin 4
    For counter2 = 0 to 5 'Blink LED 50 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter2 'Back to beginning of loop
    Low 1 'Low on Port B Pin 4
    For counter = 0 to 10 'Blink LED 50 times
    Pause 400 'Pause
    High 1 'High on Port B Pin 1
    Pause 400 'Pause
    Low 1 'Low on Port B Pin 1
    Next counter: 'Back to beginning of loop
    For counter3 = 0 to 50 'Send data times
    serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $55, $55, $55, $55, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    End




    Receiver (315)

    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: 'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    encode1 var byte : B0=0 : B1=1
    'encode1 byte sized variable that holds encoded byte s, B0 and B1 are the hardwired address
    e var byte: s=0: encode1=0:e=0
    ' e are bytes; initialize s, encode1, and e values to zero
    'encode1 holds the encoded variable received.

    Main:

    Clr:
    s=0: encode1=0: e=0: 'encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa 'if $55 occurs 4 times in a row check for $aa
    Else
    goto maina 'if not $55, reset counter at main and restart
    Endif
    goto wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    High 7 'High on Port B Pin 7
    Pause 2000 'Pause
    Low 7 'Low on Port B Pin 7


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    High 6 'High on Port B Pin 6
    Pause 2000 'Pause
    Low 6 'Low on Port B Pin 6

    e=s
    If ((e.1==1)) Then 'Acknowledgment received because third bit is 1
    goto L4 'Jump to L4
    Else
    write 2,s 'Write to EEPROM Location 2
    High 2 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 2 'Low on Port B Pin 2
    goto Clr
    Endif

    L4:

    write 3, e 'Write to EEPROM Location 3
    High 1 'High on Port B in 1
    Pause 2000 'Pause
    Low 1 'Low on Port B in 1
    serout PORTB.3, n2400, [e.3] 'send out first bit from PORTB Pin 3
    serout PORTB.4, n2400, [e.2] 'send out second bit from PORTB Pin 4
    goto Clr


    End
    Last edited by oneohthree; - 19th April 2007 at 04:53.

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    I find that sometimes when I connect by wire it doesn't work. Sometimes my wireless connection works if I first connect the wire remove it and then I reconnect my wireless connection it works again. I'm not sure if the serout is not working correctly or the serin is not working correctly.
    Sounds like a goofy ground wire/connection somewhere, induced capacitance, missing pullup or pulldown, etc., maybe a sloppy PCB.
    Are you working on a solderless breadboard?

  25. #25
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Yes, I am using a breadboard. Do you think it is possible that maybe that area of the breadboard is messed up?
    Could it be a training problem for the transmitter/receiver also?
    Last edited by oneohthree; - 19th April 2007 at 05:17.

  26. #26
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Corrosion perhaps

    Quote Originally Posted by oneohthree View Post
    Yes, I am using a breadboard. Do you think it is possible that maybe that area of the breadboard is messed up?
    Could it be a training problem for the transmitter/receiver also?
    Hello oneohthree,
    I just trashed 4 breadboards due to corrosion. The contacts also wear out too. I really got tired of fighting to get even simple things to work, Oscillator sometimes wouldn't run, poor connections, bad things happen when components like PIC lose grounds too, anyway its worthwhile to check.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  27. #27
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    And you STILL DID NOT put those semicolons....

    Also I would choose a different setup for the serin command. Maybe with a time out and a wait character.This would require the Serin2 though...

    Ioannis


    P.S. Also why don't you try simple things first, like send one character then two and see what happens. After that try the manchester encoding and if succesful try the CRC or checksum. Take it step by step. You program is too long to follow and debug. About this routines (manchester and CRC) there are link on this forum. Do a search and find. One is Melanies and one is mine.
    Last edited by Ioannis; - 19th April 2007 at 09:37.

  28. #28
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    The serial out I plan to use at transmitter:
    serout PORTB.2, n2400, [ "A" , encode2 ]

    The serial in I plan to use at receiver:
    serin2 PORTB.0, n2400, [WAIT("A"),BIN8 encode1] 'take in data at pin 0 and place in encoded1

    I discover that this does not work so I reverted back to my old code which sometimes works and sometimes doesn't. It's either a serin problem, serout problem or a transmitter/receiver problem. I will also try to change the breadboard to see if it helps.
    Last edited by oneohthree; - 19th April 2007 at 19:43.

  29. #29
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I cleaned up my microcontroller codes. I am doing serout only once this time with 4 $55 and 1 $aa in the preamble. The problem now is my PIC to PIC communication works perfectly with a wire. But when I connected them to the TLP-315 and RLP-315 transmitter and receiver pairs it either does not work or works intermittently. I told the receiver to count for $55 four times. I am using a breadboards. On one breadboard I have a 315 MHz receiver and 434 MHz transmitter and the other breadboard I have a 315 MHz transmitter and 434 MHz receiver. After I get this problem fixed I will be putting it on a PCB. I have been trying all different combinations for the past week but it seems like my 315 MHz receivers are not working like they should.
    I do not know what is wrong I am basically doing the same thing in both links but one link works while the other does not. My link from 434 mhz transmitter to 434 mhz receiver is working but my link from 315 mhz transmitter to 315 Mhz receiver is working intermittently. I am using both PIC16F84A and PIC16F88. Is this a PIC problem or a RF module problem.

    Transmitter
    'IEEE Encoding
    'Transmitter Code
    Include "Modedefs.bas"
    trisb = 0
    main:
    u var byte : counter var byte : encode var byte : u = %1000
    'u is the byte containing the input in binary, counter is a byte that describes the amount of bits to encode
    'encode is the variable holding the encoded value
    'Manchester encoding
    For counter = 0 to 3
    If u.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    write 0, encode 'Write to EEPROM Location 0
    High 1 'High on Port B Pin 1
    Pause 1000 'Pause
    Low 1 'Low on Port B Pin 1
    serout PORTB.0, n2400, [ $55 , $55 ,$55, $55, $aa , encode ]: 'send out preamble and encoded from Port B Pin 0
    goto main



    Receiver (434 to 315)
    Include "Modedefs.bas"

    ct55 var byte: encoded1 var byte: s var byte: counter var byte: e var byte: action var byte:
    encoded var byte: encoded2 var byte: action2 var byte: B0 var bit: B1 var bit: B0=1: B1=0
    s=0: e=0: encoded1=0: counter = 0: action=0: action2=0: encoded=0: encoded2=0:

    Main:

    Clr:
    s=0: e=0: encoded1=0: action=0: action2=0: encoded=0: encoded2=0

    Maina:
    ct55=0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encoded1
    If encoded1 = $55 Then
    ct55 = ct55 + 1
    If ct55 = 4 Then goto Waitaa
    Else
    goto Maina
    Endif
    goto Wait55

    Waitaa:
    serin PORTB.0, n2400, encoded1
    If encoded1 <> $aa Then goto Maina
    serin PORTB.0, n2400, encoded1
    write 0, encoded1

    For counter = 0 to 3 : s.0[counter] = encoded1.0[counter*2]:Next counter
    write 1,s

    e = s:
    If ((e.3=B0) and (e.2=B1)) Then
    goto L3
    Else
    write 2, s
    goto Clr
    Endif

    L3:
    If((s.1=0) and (s.0=0)) Then
    action=s:
    action.1=1
    write 3, action
    High 6
    Pause 1000
    Low 6
    For counter = 0 to 3
    If action.0[counter]=0 Then
    encoded.0[counter*2]=0 : encoded.0[counter*2+1]=1
    Else
    encoded.0[counter*2]=1 : encoded.0[counter*2+1]=0
    Endif
    Next counter:
    write 8, encoded
    Low 4
    For counter = 0 to 4
    Pause 400
    High 4
    Pause 400
    Low 4
    Next counter:
    'For counter = 0 to 5
    serout PORTB.2, n2400, [$55,$55,$55,$55,$aa, encoded]
    goto Clr
    'Next counter:

    Endif

    If ((s.1=0) and (s.0=1)) Then
    action2 = s: action2.1 = 1:
    write 4, action2
    High 5
    Pause 2000
    Low 5
    For counter = 0 to 3
    If action2.0[counter]=0 Then
    encoded2.0[counter*2] = 0: encoded2.0[counter*2+1] = 1
    Else
    encoded2.0[counter*2] = 1: encoded2.0[counter*2+1] = 0
    Endif
    Next counter:
    write 9, encoded2
    Low 4
    For counter = 0 to 4
    Pause 400
    High 4
    Pause 400
    Low 4
    Next counter
    Low 1
    For counter = 0 to 10
    Pause 400
    High 1
    Pause 400
    Low 1
    Next counter:
    'For counter = 0 to 5
    serout PORTB.2, n2400, [$55,$55, $55, $55,$aa, encoded2]
    goto Clr
    'Next counter

    Endif
    End

    Receiver code (315 Link)
    Include "Modedefs.bas"
    ct55 var byte: encoded1 var byte: s var byte: counter var byte: e var byte:
    s = 0: e = 0: encoded1 = 0: counter = 0:

    Main:


    Maina:
    ct55=0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encoded1
    If encoded1 = $55 Then ct55 = ct55 + 1
    If ct55 = 4 Then
    goto Waitaa
    Else
    goto Wait55
    Endif
    'goto Wait55

    Waitaa:
    serin PORTB.0, n2400, encoded1
    If encoded1 <> $aa Then goto Maina
    serin PORTB.0, n2400, encoded1
    write 0, encoded1

    For counter = 0 to 3 : s.0[counter] = encoded1.0[counter*2]: Next counter
    write 1,s

    If (s.1=1) Then
    goto L4
    Else
    write 2,s
    High 2
    Pause 1000
    Low 2
    goto Maina
    Endif

    L4:
    e = s
    write 3, e
    High 1
    Pause 1000
    Low 1
    serout PORTB.3, n2400, [e]
    goto Maina

    End
    Last edited by oneohthree; - 20th April 2007 at 04:48.

  30. #30
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Delete the colon from the Next counter command!

    Quote Originally Posted by oneohthree View Post
    'Transmitter Code
    Include "Modedefs.bas"
    trisb = 0
    main:
    u var byte : counter var byte : encode var byte : u = %1000
    'u is the byte containing the input in binary, counter is a byte that describes the amount of bits to encode
    'encode is the variable holding the encoded value
    'Manchester encoding
    For counter = 0 to 3
    If u.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter : <<<<<<<<<<<------- Here!!
    write 0, encode 'Write to EEPROM Location 0
    High 1 'High on Port B Pin 1
    Pause 1000 'Pause
    Low 1 'Low on Port B Pin 1
    serout PORTB.0, n2400, [ $55 , $55 ,$55, $55, $aa , encode ]: 'send out preamble and encoded from Port B Pin 0
    goto main
    You do not need to count the preamble bytes. Just wait for the start character, $AA, and grab the next character


    Quote Originally Posted by oneohthree View Post
    Receiver (434 to 315)
    Include "Modedefs.bas"

    ct55 var byte: encoded1 var byte: s var byte: counter var byte: e var byte: action var byte:
    encoded var byte: encoded2 var byte: action2 var byte: B0 var bit: B1 var bit: B0=1: B1=0
    s=0: e=0: encoded1=0: counter = 0: action=0: action2=0: encoded=0: encoded2=0:

    Main:

    Clr:
    s=0: e=0: encoded1=0: action=0: action2=0: encoded=0: encoded2=0

    Maina:
    ct55=0 'counter for $55 is zero

    ''''''''''''Wait55:
    ''''''''''''serin PORTB.0, n2400, encoded1
    ''''''''''''If encoded1 = $55 Then
    ''''''''''''ct55 = ct55 + 1
    ''''''''''''If ct55 = 4 Then goto Waitaa
    ''''''''''''Else
    ''''''''''''goto Maina
    ''''''''''''Endif
    ''''''''''''goto Wait55

    Waitaa:
    serin PORTB.0, n2400, [($AA)],encoded1
    write 0, encoded1
    I think here you have error in decoding the manchester. I suggest thew following:

    Quote Originally Posted by oneohthree View Post
    For counter = 0 to 3 : s.0[counter] = encoded1.0[counter*2]:Next counter
    write 1,s

    For counter=0 TO 3
    IF encoded1.0[counter*2]=0 Then
    IF encoded1.0[counter*2+1]=1 Then
    s.0[counter]=0
    EndIF
    Else
    s.0[counter]=1
    EndIF
    Next

    e = s: <<<<<<<<<<<<<<<< DO NOT PUT SPACES IN LABELS!!!
    I have no time to follow the rest of your code now. Please try the suggested encoding for the transmission and see how it goes for one direction. Then try it on the other direction and make sure you have good RF com.

    Ioannis
    Last edited by Ioannis; - 20th April 2007 at 07:53.

  31. #31
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I think my decoding is ok. When I tried my decoding and your decoding the same result happened. But when I only wait for $AA it messes up my data. I tested it by putting a PIC next to the transmitter with a precoded sequence and sent it across. I get an incorrect message at the output and the correct message. Then I changed it to using serin2 but that only works by wire. By wireless, it works when I send the data multiple times but wrong data and correct data is coming through. It seems like my data is not getting transmitted correctly through the RF Link modules or there is a synchronization problem. Should I enter pauses or add more of a training sequence to prevent this from happening?

    New Receiver code (434 and 315)
    Include "Modedefs.bas"

    ct55 var byte: encoded1 var byte: s var byte: counter var byte: e var byte: action var byte:
    encoded var byte: encoded2 var byte: action2 var byte: B0 var bit: B1 var bit: B0=0: B1=1
    s=0: e=0: encoded1=0: counter = 0: action=0: action2=0: encoded=0: encoded2=0:

    Main:

    Clr:
    s=0: e=0: encoded1=0: action=0: action2=0: encoded=0: encoded2=0

    Maina:
    ct55=0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encoded1
    If encoded1 = $55 Then
    ct55 = ct55 + 1
    If ct55 = 4 Then goto Waitaa
    Else
    goto Maina
    Endif
    goto Wait55

    Waitaa:
    serin PORTB.0, n2400, encoded1
    If encoded1 <> $aa Then goto Maina
    serin PORTB.0, n2400, encoded1
    write 0, encoded1

    For counter = 0 to 3 : s.0[counter] = encoded1.0[counter*2]:Next counter
    write 1,s

    e = s
    If ((e.3=B0) and (e.2=B1)) Then
    goto L3
    Else
    write 2, s
    goto Clr
    Endif

    L3:
    If((s.1=0) and (s.0=0)) Then
    action=s:
    action.1=1
    write 3, action
    High 6
    Pause 1000
    Low 6
    For counter = 0 to 3
    If action.0[counter]=0 Then
    encoded.0[counter*2]=0 : encoded.0[counter*2+1]=1
    Else
    encoded.0[counter*2]=1 : encoded.0[counter*2+1]=0
    Endif
    Next counter:
    write 8, encoded
    Low 4
    For counter = 0 to 4
    Pause 400
    High 4
    Pause 400
    Low 4
    Next counter:
    For counter = 0 to 5
    serout PORTB.2, n2400, [$55,$55,$55,$55,$aa, encoded]
    Next counter
    goto Clr
    'Next counter

    Endif

    If ((s.1=0) and (s.0=1)) Then
    action2 = s: action2.1 = 1:
    write 4, action2
    High 5
    Pause 2000
    Low 5
    For counter = 0 to 3
    If action2.0[counter]=0 Then
    encoded2.0[counter*2] = 0: encoded2.0[counter*2+1] = 1
    Else
    encoded2.0[counter*2] = 1: encoded2.0[counter*2+1] = 0
    Endif
    Next counter:
    write 9, encoded2
    Low 4
    For counter = 0 to 4
    Pause 400
    High 4
    Pause 400
    Low 4
    Next counter
    Low 1
    For counter = 0 to 10
    Pause 400
    High 1
    Pause 400
    Low 1
    Next counter:
    For counter = 0 to 5
    serout PORTB.2, n2400, [$55,$55, $55, $55,$aa, encoded2]
    Next counter
    goto Clr
    Endif
    End


    Include "Modedefs.bas"
    ct55 var byte: encoded1 var byte: s var byte: counter var byte: e var byte: c var byte
    s = 0: e = 0: encoded1 = 0: counter = 0: c = 0:

    Main:


    Maina:
    ct55=0 'counter for $55 is zero

    Wait55:
    'serin PORTB.0, n2400, encoded1
    'If encoded1 = $55 Then ct55 = ct55 + 1
    'If ct55 = 4 Then
    'goto Waitaa
    'Else
    'goto Wait55
    'Endif
    'goto Wait55

    Waitaa:
    'Pause 1000
    serin2 PORTB.0, 16780, [WAIT($55, $55, $55, $55, $aa) , encoded1]
    'serin PORTB.0, n2400, encoded1
    'If encoded1 <> $aa Then goto Maina
    'serin PORTB.0, n2400, encoded1
    write 0, encoded1

    For counter = 0 to 3 : s.0[counter] = encoded1.0[counter*2]: Next counter

    write 1,s
    c = s
    If (c.1=1) Then
    goto L4
    Else
    write 2,s
    High 2
    Pause 1000
    Low 2
    goto Maina
    Endif

    L4:
    e = s
    write 3, e
    High 1
    Pause 1000
    Low 1
    serout PORTB.3, n2400, [e]
    goto Maina

    End
    Last edited by oneohthree; - 21st April 2007 at 02:47.

Similar Threads

  1. PIC KIT 2 writing problem ?
    By KaanInal in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2010, 12:59
  2. Unusual Interrupts Application Problem
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2009, 11:55
  3. Replies: 7
    Last Post: - 15th December 2008, 05:18
  4. PWM Problem
    By cihhan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th June 2008, 18:43
  5. Replies: 18
    Last Post: - 24th January 2008, 22:44

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts