Microcontroller with 2 way paging application problem


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    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.

  2. #2
    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 : 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