Microcontroller with 2 way paging application problem


Closed Thread
Results 1 to 31 of 31

Hybrid View

  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

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 : 0

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