Serout problem


Closed Thread
Results 1 to 40 of 95

Thread: Serout problem

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default Serout problem

    I just started to play with wireless transmision. I used this kit that
    I ordered:
    http://www.rentron.com/remote_contro...-bit-combo.htm

    I do get a signal at the receiver but I do not know how to interpret
    it or how to fix it. The signal is clear but not the same as the one I
    sent. I posted a picture of both signal
    http://www3.sympatico.ca/lerameur/

    can somebody tell me why the receiving signal is not identical?
    it seems the receiving signal cannot stay on more then 125ms

    I tried transfering at 2400bps,4800 and 9600, putting a single data in a cycle or a few. I get the same results..
    I am using this to generate my signal:
    serout2 portb.3,n9600, [2,4,6]

    thanks

    Ken

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Do a search on manchester encoding and use it.
    The transmitter/receiver use a sort of zero-crossing detector (at least I think that's what it's called). You can't just put serial into the transmitter and expect to get the same signal out.
    Basically, you convert all of your 0's into '01' and all of your 1's into '10', both at the transmitter end and the receiver end.
    Example:
    You want to send a $73 (hex 73):
    $73 = % 0111 0011
    manchester encoded becomes: 01 10 10 10 01 01 10 10

    decoded at the other end in reverse:
    receive:
    01 10 10 10 = $6A
    01 01 10 10 = $5a
    convert:
    01 = 0, 10 = 1, 10 = 1, 10 = 1; -> 0111 = $7 (upper half)
    01 = 0, 01 = 0, 10 = 1, 10 = 1; -> 0011 = $3 (lower half)

    put it back together to get $73.

    Yes, you do 'waste' half the bandwidth (ie. transmitting at 2400 baud only gives you 1200 effective baud).
    But you also have to 'train' the receiver to be able to recognize the halfway point between 0 and 1. You do this by sending about 5 ms (maybe more, maybe less) worth of $55 or $aa, whichever, it ends up the same in the end.

    Then you can start sending your data.

    I've got those same modules from Rentron. They work great, even in a sloppy solderless breadboard environment. I routinely can get a couple hundred feet of range from them at 9600baud (even though they aren't rated for that speed).

    Also, for a software idea for you, I split the bytes in half and used a 'look up' table to encode the sending data. To receive the data, I used the same 'look up' table to decode the data and then reassembled the bytes as required.

    A bit inefficient, but it's quick and simple and it works for me...
    JDG

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I choose a kit that came with an encode and a decoder. If I use them, will it be like utilizing a manchester coding type of technique ? I thought I would start with the basic and then add the encoder. i guess I should start puting in the encoders right a way

    k

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    I choose a kit that came with an encode and a decoder. If I use them, will it be like utilizing a manchester coding type of technique ? I thought I would start with the basic and then add the encoder. i guess I should start puting in the encoders right a way

    k

    The encoder and decoder modules do almost exactly that. The difference is generally in the outputs. Some decoder modules only turn switches on and off, others toggle, etc.etc., then again, other modules let you put serial in one end, and get serial out the other end.

    You can very easily do the same thing with a bit of software.
    And yes, generally the encoders would come first until you figure out that you don't need to use up that extra bit of board space with another chip!
    Good luck...

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Ok i understand what you mean by manchester encoding, My qustion is now, should I see the same signal at the output of the chip and at the output of he receiver ? That was the way My scope was hooked up before, and now it is reading a big flat black line at the receiving end with same amplitude. The transmitter is now sending spikes.

    ken

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    The spikes at the output are the result of the incoming signal from the transmitter, going from low to high, basically because you haven't 'trained' the receiver to know where the halfway point is.

    (forget about the encoder/decoder module for now)

    Try sending a string of continuous $55's at 2400 baud (which ends up being binary 0101010101010101010 etc) to the receiver, then watch the input and the output; Channel A at the serial output of the PIC, Channel B at the digital output of the receiver. They should be identical.

    Quite frankly, I don't know how I can easily explain to you how the receiver works without getting you (and myself) confused in the process! But I'll give it a quick try.
    There's a data slicer in the receiver that relies on the fact that you don't send a continuous string of zero's or one's. You have to train the receiver by sending it one's and zero's (50% duty cycle) so it can charge up a capacitor in the data slicer to about halfway. When that's done, the receiver can know the difference between a one and a zero (since it knows where the half point is).
    If you send it too many 1's in a row, that capacitor charges up too much and the halfway point gets closer and closer to the normal '1' level, eventually making everything look like a zero.
    If you send it too many 0's in a row, the same capacitor discharges too much and the halfway point drops too low, making everything look like a one at some point.
    Therefore, if you keep alternating one's and zero's (like manchester encoding does), you keep that capacitor in the data slicer section about halfway charged up and it doesn't lose it's mind.

    How's that for confusing? Any better?
    JDG
    P.S. I'm about to turn off for the night, so if you've got more questions, might want to make them quick...

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Some code I dug up from one of my earlier projects that used the modules from Rentron. They aren't complete, the meat of what the code actually does has been removed, but it might give you a decent starting point to work with...

    Transmitter code....


    'use TWS/RWS modules, portb.2 pwr to xmtr, portb.1 xmtr data in, slave controller PCB for data

    @ DEVICE PIC16F628A , INTRC_OSC , WDT_ON , PWRT_OFF , MCLR_OFF , BOD_ON , LVP_OFF , PROTECT_OFF

    'Int 4Mhz Osc, WDT off, PWR up timer off, mclr ext, brown out detect on, low volt prog off , code protect off

    resetplaceholder: 'arial black, size 8, reg, 16f628A code

    INCLUDE "modedefs.bas"

    DEFINE OSC 4 'using internal 4mhz, switch down to 37khz when in low power mode, eventually

    DISABLE

    CLEAR

    selectkey var portb.5 : rightkey var portb.6 : leftkey var portb.7 : upkey var portb.0 : downkey var portb.3
    input selectkey : input rightkey : input leftkey : input upkey : input downkey : dataout var portb.1 : output dataout
    dataout = 0 : xmtrpwr var portb.2 : output xmtrpwr : xmtrpwr = 0 : key var byte : option_reg = 8 : cmcon = 7

    'option = pullups enabled, ints disabled, prescaler to WDT, all comparators off

    mainloop: key = 0
    if ( selectkey = 1 ) and ( upkey = 1 ) and ( downkey = 1 ) and ( leftkey = 1 ) and ( rightkey = 1 ) then
    xmtrpwr = 0 : pcon.3 = 0 : nap 2
    'power down for a bit, slow clock to 37khz before going into nap

    else 'send manchester encoded numbers 0-4, 0=01, 1=10, therfore '1010' = '10 01 10 01'

    if xmtrpwr = 0 then
    pcon.3 = 1 : xmtrpwr = 1 : pause 5 : key = $55 : serout2 dataout , 84 , [ REP key \ 24 ]
    endif
    if upkey = 0 then key = $66 '5= 01 10 01 10
    if downkey = 0 then key = $56 '1= 01 01 01 10
    if leftkey = 0 then key = $6a '6= 01 10 10 01
    if rightkey = 0 then key = $5a '3= 01 01 10 10
    if selectkey = 0 then key = $65 '4= 01 10 01 01

    serout2 dataout , 84 , [ REP key \ 2 ] 'serout2 mode 188 = 4800 baud, 84 @ 9600, 8N1 formatting

    endif
    goto mainloop
    END










    Receiver code....
    @ DEVICE PIC16F628A , HS_OSC , WDT_OFF , PWRT_ON , MCLR_ON , BOD_ON , LVP_OFF , PROTECT_OFF
    'HS 20mhz, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off

    resetplaceholder: 'wordpad, arial black, size 8, reg, 1600x1200 screen, 16f628A code

    DEFINE OSC 20 '20mhz
    DEFINE NO_CLRWDT 1 'don't clear the watchdog timer, I'm not using it anyways
    DISABLE 'disable software interrupt checks
    CLEAR 'clear out the ram and do a software 'reset'

    upkey var portb.0 : downkey var portb.3 : rxpwr var portb.4 : selectkey var portb.5 : rightkey var portb.6
    leftkey var portb.7 : redled var porta.0 : greenled var porta.1 : blueled var porta.2 : chx var porta

    serdata var byte : serbuf1 var byte : serbuf2 var byte : serialselecthold var byte
    gooddatacount var byte : baddatacount var byte

    startupholder: goto skipsubs 'skip over all the commonly used subroutines

    ON INTERRUPT GOTO INTHANDLER
    DISABLE INTERRUPT
    INTHANDLER: if pir1.5 = 1 then 'if serial data rx'd
    pir1.5 = 0 'reset the RX flag
    if ( rcsta.1 = 1 ) or ( rcsta.2 = 1 ) then 'check for err, if frame/overrun error,
    rcsta.4 = 0 : rcsta.4 = 1 : serdata = rcreg : serdata = 0 'reset CREN, clear last data rx'd
    gooddatacount = 0 : if baddatacount < 255 then baddatacount = baddatacount + 1
    else
    serdata = rcreg : serbuf2 = serbuf1 : serbuf1 = serdata
    baddatacount = 0 : if gooddatacount < 255 then gooddatacount = gooddatacount + 1
    endif
    endif

    if nokeypress <> 0 then nokeypress = nokeypress - 1 'if a key has been hit lately, this counter serves as
    'a debounce/delay keeping another key hit from being
    'detected later

    intfinish: RESUME

    clearserbuf: serialselecthold = 0 : serdata = 0 : serbuf2 = 0 : serbuf1 = 0 : return 'clear serial buffer

    increasecolor: color = color + 1 : if color = 8 then color = 1 'used in a few routines for stepping the colors
    return

    ENABLE INTERRUPT

    DISABLE INTERRUPT 'pie1=$20 enables ser-port int., spbrg= 129@2400, 255@1200baud, 64@4800baud, 33@9600baud

    skipsubs: option_reg = 8 : pie1 = $20 : trisa = 0 : porta = 0 : trisb = $ef : portb = $10 : t1con = 0 : t2con = 0
    cmcon = 7 : ccp1con = 0 : vrcon = 0 : txsta = 0 : rcsta = $90 : pir1.5 = 0 : spbrg = 33 : mode = 0
    lastmode = 0 : intcon = $e0 : modeset = 1

    mainloop: if ( selectkey = 1 ) then
    if ( upkey = 1 ) then
    if ( downkey = 1 ) then
    if ( leftkey = 1 ) then
    if ( rightkey = 1 ) then goto mainmodeloop 'if no keys pressed, don't check
    endif
    endif
    endif
    endif

    if nokeypress > 1 then goto mainmodeloop 'if a certain key was pressed lately,
    ' don't check for any new keys

    if nokeypress < 10 then
    if serbuf2 = serbuf1 then
    select case serbuf1 'manchester encoded numbers 1-5
    case $66
    gosub clearserbuf : goto serialupkey
    case $56
    gosub clearserbuf : goto serialdownkey
    case $6a
    gosub clearserbuf : goto serialleftkey
    case $5a
    gosub clearserbuf : goto serialrightkey
    case $65
    if serialselecthold > 10 then
    gosub clearserbuf : goto serialselectkey
    else
    serialselecthold = serialselecthold + 1
    endif
    end select
    endif
    endif
    ENABLE INTERRUPT
    goto mainloop 'do it all over again
    END

Similar Threads

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