Serout problem


Closed Thread
Results 1 to 40 of 95

Thread: Serout problem

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    Ok, I tried it, everything is fine, its working, The four leds flashes if no data from sending chip after 5 seconds, everything like you said.

    ken


    GREAT!!! That's great news. I'm at work at the moment. I'll post a bit more in a few hours when I get some spare time.
    JDG

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    thanks alot, I wont be home till late again today so no hurry.
    I just tried putting it through the RF module just to see what would happen, but it was not going through nicely.
    Waiting for your next instruction.

    k

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    thanks alot, I wont be home till late again today so no hurry.
    I just tried putting it through the RF module just to see what would happen, but it was not going through nicely.
    Waiting for your next instruction.

    k
    Now go back and read thru this whole thread and see if you can tell me why that data did not go thru the RF modules correctly. The correct answer is in the thread, young grasshopper.

    Same thing. I probably won't get back to this for a few hours yet. But if you're around, we should be able to get it all working within about 4-5 thread posts.
    JDG

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Well a big rule I learn not long ago is to use encoding techniques. and perhaps keep on sending the data a little while longer with serout command.

    k

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    Well a big rule I learn not long ago is to use encoding techniques. and perhaps keep on sending the data a little while longer with serout command.

    k

    Ok, so as it stands, you have:
    TXPIC: one button, 4 leds, serial out on PortB.2
    RXPIC: 4 leds, serial in on PortB.5

    All works well, data appears to transfer from TXPIC to RXPIC, LEDs match on both, then go out on RXPIC after 5 seconds without button push on TXPIC....

    If that's all good....Read on...I'll be typing up the next post while you read this one....
    JDG

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Wireless serial comm's continued...

    Now then....

    Remove the wire between the 2 PICs. Connect the transmitter input to TXPIC-PortB.2, connect the receiver digital output to RXPIC-PortB.5. You're not ready to send data yet. You have to encode the data from the TXPIC and then decode it at the RXPIC using manchester encoding/decoding techniques.

    The receiver module relies on bit transitions, not steady state levels. So therefore, with manchester encoding, 1 bit become 2 bits, either a low-high or high-low transition. So, out of one byte (256 values), we can only send 1/2 byte (16 values) of code. 2 of these values have to be reserved for 'training' the receiver, getting the data slicer in the receiver charged up (according to the datasheets for the core of this module, you have to do it for about 5ms).
    If we sent all 1's, the data slicer would be charged up to a full 1, if we sent all 0's, the data slicer wouldn't get charged at all, so we send alternating 1's and 0's, hence the 2 reserved byte values, $AA (10101010) and $55 (01010101). Remember, each bit becomes 2 bits in manchester encoding, 0 becomes 01, 1 becomes 10. This gives us 16 values to play with in a byte
    hex value----binary value-----manchester encoded binary (hex) value
    0------------0000------------01 01 01 01 ($55)
    1------------0001------------01 01 01 10 ($56)
    2------------0010------------01 01 10 01 ($59)
    3------------0011------------01 01 10 10 ($5A)
    4------------0100------------01 10 01 01 ($65)
    5------------0101------------01 10 01 10 ($66)
    6------------0110------------01 10 10 01 ($69)
    7------------0111------------01 10 10 10 ($6A)
    8------------1000------------10 01 01 01 ($95)
    9------------1001------------10 01 01 10 ($96)
    A------------1010------------10 01 10 01 ($99)
    B------------1011------------10 01 10 10 ($9A)
    C------------1100------------10 10 01 01 ($A5)
    D------------1101------------10 10 01 10 ($A6)
    E------------1110------------10 10 10 01 ($A9)
    F------------1111------------10 10 10 10 ($AA)

    Only hex $0 and hex $F (left column) are true repeating manchester binary patterns with true alternating values (right column) , so you reserve those for training the receiver only. Everything else from hex $1 - $f (left column) are free.

    So, this is what we'll do:
    Modify the transmitter code to send the code for each LED 1-4 out the serial port to the transmitter in manchester format, but instead of using hex $0 for reset the LEDs, we'll use hex $5. And don't forget, we have to train the receiver (by sending data with the transmitter) each time we send a new code.


    So the transmitter code changes to:


    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    txout var portb.2 : output txout : dataout var byte
    ledcount var byte
    led1 var porta.0 : output led1 : led2 var porta.1 : output led2
    led3 var porta.2 : output led3 : led4 var porta.3 : output led4
    key var portb.0 : input btn 'push button on portb.0
    '1K-10K resistor from portb.0 to ground (pulldown)
    'push button is wired between portb.0 and +5v
    'initial LED check
    led1 = 1 : pause 500 : led1 = 0 : led2 = 1 : pause 500 : led2 = 0
    led3 = 1 : pause 500 : led3 = 0 : led4 = 1 : pause 500 : led4 = 0

    mainloop:

    if key = 0 then 'button not pressed
    goto mainloop
    endif
    if key = 1 then
    pause 50 'wait 50ms for switch to debounce then check again
    if key = 1 then 'if it's still pressed, then increment the count
    ledcount = ledcount + 1
    dataout = $55 ($55 = manchester encoded $0)
    'train the receiver by sending 5 each of the $55's, may need more
    'just copy the line below to make it send out more characters
    serout txout, n2400, [ dataout, dataout, dataout, dataout, dataout ]
    endif
    endif

    if ledcount = 0 then 'all leds off
    dataout = $66 'manchester encoded $5, use because $0 is reserved
    serout txout, n2400, [ dataout ]
    'may have to send data more than once depending on how well the receiver
    'can capture the data. Shouldn't have a problem sending it once
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    if ledcount = 1 then '1st led on
    dataout = $56 'manchester encoded $1
    serout txout, n2400, [ dataout ]
    led1 = 1 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    if ledcount = 2 then '2nd led on and so on and so on down the line....
    dataout = $59 'manchester encoded $2
    serout txout, n2400, [ dataout ]
    led1 = 0 : led2 = 1 : led3 = 0 : led4 = 0
    endif

    if ledcount = 3 then
    dataout = $5a 'manchester encoded $3
    serout txout, n2400, [ dataout ]
    led1 = 0 : led2 = 0 : led3 = 1 : led4 = 0
    endif

    if ledcount = 4 then
    dataout = $65 'manchester encoded $4
    serout txout, n2400, [ dataout ]
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 1
    endif

    if ledcount = 5 then 'reset led count, roll it back to 0
    ledcount = 0 'and turn leds off since count is back to 0
    dataout = $66 'manchester encoded $5 (same thing as ledcount = 0 above)
    serout txout, n2400, [ dataout ]
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    goto mainloop

    END






    This code should still change the LEDs on TXPIC, but won't do anything for RXPIC until we change that code...
    Receiver code in next post....
    JDG
    Last edited by skimask; - 7th December 2006 at 03:57.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Wireless serial comm's continued...(RXPIC)

    Now for the receiver code....

    The receiver has to be trained as noted in the last post, and almost everything applies to the receiver as far as manchester encoding/decoding goes.


    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    rxin var portb.5 : input rxin : datain var byte

    ledcount var byte
    led1 var porta.0 : output led1 : led2 var porta.1 : output led2
    led3 var porta.2 : output led3 : led4 var porta.3 : output led4

    key var portb.0 : input btn
    led1 = 1 : pause 500 : led1 = 0 : led2 = 1 : pause 500 : led2 = 0
    led3 = 1 : pause 500 : led3 = 0 : led4 = 1 : pause 500 : led4 = 0

    mainloop:

    serin rxin, n2400, 5000, nodatarx, datain
    'if no data received in 5 seconds, jump to nodatarx

    '2 byte values, $55 and $aa set aside for training the receiver, ignore them
    if datain = $55 then 'manchester encoded $0, training the receiver
    goto mainloop
    endif

    if datain = $aa then 'manchester encoded $f, training the receiver
    goto mainloop
    endif

    if datain = $66 then 'manchester encoded $5, all leds off
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    if datain = $56 then 'manchester encoded $1, led1 on
    led1 = 1 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    if datain = $59 then 'manchester encoded $2, led2 on
    led1 = 0 : led2 = 1 : led3 = 0 : led4 = 0
    endif

    if datain = $5a then 'manchester encoded $3, led3 on
    led1 = 0 : led2 = 0 : led3 = 1 : led4 = 0
    endif

    if datain = $65 then 'manchester encoded $4, led4 on
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 1
    endif

    goto mainloop

    nodatarx: 'flash the leds 3 times
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    led1 = 1 : led2 = 1 : led3 = 1 : led4 = 1 : pause 400
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0 : pause 400
    led1 = 1 : led2 = 1 : led3 = 1 : led4 = 1 : pause 400
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0 : pause 400
    led1 = 1 : led2 = 1 : led3 = 1 : led4 = 1 : pause 400
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    goto mainloop

    END






    You may have also notice I shortened up the program a bit by cramming a few of the lines together. There's no reason for it, it just takes up less space on the screen if you have more than one command on a line. I like to pack as much info on the screen as I can, other people can't stand to have more then one command on a line. Personal preference.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 21:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 17:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 18:11
  4. Strange SerOut Problem
    By masosi in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 23rd April 2007, 07:06
  5. Replies: 11
    Last Post: - 13th July 2005, 20:26

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