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
    yes , I actually came back now to edit my last mpost when I saw you answered. I was going to say that the reason why it did not work before is because i was not training my chip.
    i have two questions:
    1) How come the robot here do not use the training and apparently it works:
    http://mysite.verizon.net/res8dbeh/ruf.htm
    2) Why does the training code has to be different then the data code ?
    I tried sending the data code directly and it do not work.

    k
    1 -
    I don't know why it works. I suspect it's because in the RUFBOT project, data is continuously sent (if you look at the code, it can loop around very quickly), and therefore, the number of 1's and 0's evens out eventually and keeps the receiver trained continuously. In your case, I assumed you wouldn't be transmitting data continuously, which is apparently the case.
    I suppose you could rewrite your code a bit, get rid of the 'RX training code', and put everything in a loop, and have it send out data after data after data, and get rid of the manchester encoding altogether. As long as you don't wait much more than 3-4ms between data bytes, you might be alright. My big thing about using the manchester encoding is that it increases the data integrity and reliability factor immensely when compared to not using it. And if you're doing anything that needs to have a bit of integrity and reliability and don't use manchester, you need to figure out some method to make sure the data is correct (checksum, multiple data compares, etc.etc).
    Manchester just seemed easier to me.

    2-
    Why does the training code have to be different than the data code?

    I'm not exactly sure what you mean by this, but I hope this does it.
    In the program that I wrote up, the training codes are $55 and $AA. As I said before, those 2 bytes have an equal number of 1's and 0's, and they alternate equally, i.e. 01010101, 10101010. Other codes, like $59, 01011001, see there's 2 1's and 2 0's back to back. So, $55 and $AA are optimal for training the receiver. Once the receiver is trained, you should be able to send whatever to the receiver. The big thing is to send an equal number of 1's and 0's over 3-5ms. That keeps the data slicer charged up halfway so it can tell the difference between a 1 and a 0. Too many 1's, and eventually, everything looks like a 0, too many 0's, and eventually, everything looks like a 1.
    JDG

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Ok , does the training part has to do with the receiver recognizing the start it and end bit. I assume the Picbasic pro compiler adds this to the signal. If it does not how does it recognize the begining of the signal, As a matter of fact might as well be the middle or 2/3 into the signal. Is this what is meant about synchronization of transmitter and receiver?

    k

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    lerameur, What skimask means by training the receiver is actually "Preconditioning" the data slicer which is actually the comparator that gives you the data output. This is done by sending some type of preamble characters that represent approx. 50 % duty cycle as far as data is concerned..

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    By preconditioning you mean making sure the internal circuitry lets say capacitor will be ready . As in ready I mean not empty or full as to give a 1 instead of a 0 or the other way. BUt is there a start bit ? How does it know where the data start and end. I guess there is not start bit like in network communication, the training session replaces that . As en example, lets say the pic chip receives the 8bit is needs, on the next eight bit, it misses out (for a reason or another) a bit, Will it be taking its eight bit on the next sequence or simply drop the whole byte ? this is what I meant by how does it know the end and start of a byte series. In networking a packet has a lot of overhead, here there is none of that.

    k
    Last edited by lerameur; - 7th December 2006 at 17:20.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    By preconditioning you mean making sure the internal circuitry lets say capacitor will be ready . As in ready I mean not empty or full as to give a 1 instead of a 0 or the other way. BUt is there a start bit ? How does it know where the data start and end. I guess there is not start bit like in network communication, the training session replaces that . As en example, lets say the pic chip receives the 8bit is needs, on the next eight bit, it misses out (for a reason or another) a bit, Will it be taking its eight bit on the next sequence or simply drop the whole byte ? this is what I meant by how does it know the end and start of a byte series. In networking a packet has a lot of overhead, here there is none of that.

    k

    When you start training/preconditioning the receiver, you won't get much of a recognizable output, maybe half a byte here and there, with or without start or stop bits,...until the receiver is conditioned. Which is why I keep saying you have to train the receiver first and ignore that data, then send some sort of sync byte to get things going.

    In this project's case, we don't need much of anything so far, but with data transmission, you'll need to figure out some sort of packet method of transferring data.

    The TXPIC (and therefore transmitter) still sends start and stop bits. It's just that the receiver module doesn't care about any start or stop bits. The PIC (rather the program anyways) still sees the start and stop bits and acts on them accordingly (and remember, a start bit is a low, a stop bit is a high, so that's 50% 1's and 50% 0's, they even themselves out, just like they should with manchester encoding). It's the data in between that ends up encoded.
    If the PIC SerIn starts to receive a byte in the middle of it, it won't get the right stop bit, and jump out. If the PIC SerIn statement somehow never receives a full 8 bits and a stop bit, same thing, it'll timeout and jump to whatever you tell it to go to.

    I don't know how to explain it to you any farther except to tell you to get online like I told you to do awhile back and do some Google'ing on manchester encoding, 433 transmitter/receiver modules, figure out how they work, why they need to use manchester encoding, etc.
    The idea really isn't that hard to wrap your head around. And once you figure it out, you'll be all over it.
    JDG

  6. #6
    Join Date
    Nov 2005
    Location
    Cambridge UK
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I am having a couple of problems with the above code. I changed it so that I could run it on two 16f628 chips, this works with out any problems.
    Happy that I could tx and rx I wanted to tx using a 12f675 chip and rx on a 16f628.

    Changing the tx code for a 12f675 and compiling it gave no errors. The leds flash ok and when I put an led on the serout pin I see the data. When I tx the code to the rx 16f628 via a tx the rx wont respond. I then hardwired the 12f675 to the 16f628 removing the tx/rx, it still wont work.
    Can someone please check my code or suggest why it wont work.
    Here is the code;

    @ DEVICE PIC12F675, INTRC_OSC_NOCLKOUT
    ' System Clock Options (Internal)
    @ DEVICE PIC12F675, WDT_ON
    ' Watchdog Timer
    @ DEVICE PIC12F675, PWRT_ON
    ' Power-On Timer
    @ DEVICE PIC12F675, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE PIC12F675, BOD_OFF
    ' Brown-Out Detect
    @ DEVICE PIC12F675, CPD_OFF
    ' Data Memory Code Protect
    @ DEVICE PIC12F675, PROTECT_ON

    'PICBASIC PROGRAM

    ANSEL = 0
    CMCON = 7
    TRISIO =%001000


    INCLUDE "modedefs.bas"


    txout VAR GPIO.4 : Output txout : dataout VAR BYTE
    ledcount VAR BYTE
    led1 VAR GPIO.0 : Output led1 : led2 VAR GPIO.1 : Output led2
    led3 VAR GPIO.2 : Output led3 : led4 VAR GPIO.5 : Output led4
    key VAR GPIO.3 : Input key 'push button on gpio.3
    '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

    I am using the two 16f628's with internal clock selected with no problem

    thanks Nick
    Last edited by Agent36; - 24th February 2007 at 20:29.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    The internal clock on the 12F675 is probably too far off (i.e. 12F675 transmitting at 2350 baud, 16F628 receiving at 2400 baud, something like that).
    Try slowing down the baud rate or moving the OSCCAL value on the 12F675 around a bit and see what happens.

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