Having Serin Serout problems


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2013
    Posts
    12

    Default Having Serin Serout problems

    I'm trying to make several modules that configure themselves automatically as master and slaves all pics being programed with the exact same code. I'm using serin with a timeout and serout. I only have 4 modules built. and it recognizes properly about 70% of the time with 4. I need it to recognize properly every time up to 16 modules. Also I am sending serout 4 times more that I would like. After master is set it sits and waits for ground pluses from each slave so the master knows how many slaves there are. I am sending serin and out on same wire as I am sending the ground pulses back to the master but the ground pulse back happens after serout is complete. Any help would be greatly appreciated. Also just a question how does PBP know on serin when you use a time out that it just isn't more bytes to be sent.(head scratcher since documentation in PBP3 book is kind of vague. just commas) also using onboard oscillators, and B.0 for serin commands and B.1 for serout commands. and the problem I seem to be having when it doesn't sync properly is that serin times out. because down the communication line the 2nd or 3rd module with say its the master also with slaves.
    here is my code.

    Initial: if ign=1 then
    goto initial
    else
    Initiall: if x=0 then
    serin ign, 2, 600, setmaster, ["~"], module
    goto setmaster
    else
    pause 50
    seroutrpt: if a<=5 then 'sends serout command 5 times
    serout OUT, 2,["~",module]
    a=a+1
    goto seroutrpt
    endif
    trisb.1=1 'makes out and input temporarly
    trisb.0=0 'makes ign and output temporarly
    ign=0 'sends ground pulse to previous slave for slave count
    pause 50
    ign=1 'idles pulse
    goto waitcnt
    endif
    endif
    setmaster: Write 1, module
    OUT=0 'wakes next slave to get ready for serin
    pause 50
    out=1 'gets exsisting ready for serout
    x=1 'been through one cycle for serin now will serout
    module=module+1
    goto Initiall
    waitcnt: read 1, master1
    if master1=0 then
    temp=0
    count out, 4000, temp 'counts how many pulses on masters out pin in 4 sec
    write 5, temp 'writes how many slaves in series
    trisb.0=1 'sets ign back to input
    trisb.1=0 'sets out back to output
    goto begin
    else
    keeploop: ign=1 'counts loop for when passthrough is not active
    if temp < 255 then 'sets delay loop to keep checking for inputs
    if out=0 then
    while out=0
    ign=0
    wend
    goto keeploop
    else
    temp=temp+1
    pause 15
    goto keeploop
    endif
    else
    trisb.0= 1 'resets b.0 to input
    trisb.1= 0 'resets b.1 to output
    temp=0
    goto begin
    endif
    endif

    thank you,
    Joe

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597

    Default Re: Having Serin Serout problems

    Have you tried with just master and 1 slave? Make sure slaves aren't talking at the same time first, then add 1 slave at a time.

    A schematic how you wire the PICs would help.

    Robert

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Having Serin Serout problems

    Just a quick read through...
    You do not reset "a" to zero after this routine, think what will happen the next time this routine is called, when a=6.
    Code:
    seroutrpt: if a<=5 then 'sends serout command 5 times
    serout OUT, 2,["~",module]
    a=a+1
    goto seroutrpt
    endif
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Apr 2013
    Posts
    12

    Default Re: Having Serin Serout problems

    Name:  photo(9).JPG
Views: 761
Size:  61.1 KB

    Demon: with just a slave and a master. It still only works most of the time not all. Thinking about adding a pull up resister to connecting lines. Kind of been wondering if the internal pull ups are not enough to keep logic high while the serin processor is waiting for serout processor.

    mackracket: The "a" gets reset later in the program. Each micro only makes the loop one time. a cycle of serin and serout. If my logic is correct it won't matter in this section.


    This is my first time playing with serin and serout. at 9600 baud on a 8mhz chip. Should be extremely reliable right?

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597

    Default Re: Having Serin Serout problems

    First time through that logic, what guarantees the initial values of X and A?

    9600baud at 8MHz has 0.16% error rate for hardware USART, I assume it should be somewhat similar for software communication.

    Internal pull-ups should be adequate. Personallly I'd put a pull-up on all B0 pins; I don't trust myself to configure internal pull-ups properly.

    Robert
    Last edited by Demon; - 5th April 2013 at 17:57.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597

    Default Re: Having Serin Serout problems

    This is confusing.

    Code:
    Initial:
    if ign=1 then
      goto initial
    else
    Initiall:
      if x=0 then
        serin ign, 2, 600, setmaster, ["~"], module
        goto setmaster
      else
        pause 50
    seroutrpt:
        if a<=5 then 'sends serout command 5 times
          serout OUT, 2,["~",module]
          a=a+1
          goto seroutrpt
        endif
        trisb.1=1 'makes out and input temporarly
        trisb.0=0 'makes ign and output temporarly
        ign=0 'sends ground pulse to previous slave for slave count
        pause 50
        ign=1 'idles pulse
        goto waitcnt
      endif
    endif

    You can do simple IF for first test:

    Code:
    Initial:
    if ign=1 then
      goto initial
    endif
    
    Initiall:
    if x=0 then
      serin ign, 2, 600, setmaster, ["~"], module
      goto setmaster
    else
      pause 50
    seroutrpt:
      if a<=5 then 'sends serout command 5 times
        serout OUT, 2,["~",module]
        a=a+1
        goto seroutrpt
      endif
      trisb.1=1 'makes out and input temporarly
      trisb.0=0 'makes ign and output temporarly
      ign=0 'sends ground pulse to previous slave for slave count
      pause 50
      ign=1 'idles pulse
      goto waitcnt
    endif

    There are other ways to make constant loops too (WHILE-WEND for example).

    It would definitely help if you posted all your code.

    (I'm still digesting the rest of the logic, bit confusing for me)

    Robert
    Last edited by Demon; - 5th April 2013 at 18:12.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597

    Default Re: Having Serin Serout problems

    While you're changing pins from inputs to outputs lower in the chain, how does the PIC higher in the chain know to change as well?

    Robert

    EDIT: This is what we used to call daisy-chain design, there's a reason why it's not used much any more.

    There's a reason why people use 2 programs; one dedicated to program a master and another for the slaves. I'm sure you can get this working, somehow, but it's so much simpler to use newer designs.

    Too bad you're using 16F818, it doesn't have hardware USART. You could do this at 115200baud, the master runs at 48MHz, the slaves at 64MHz:
    http://www.picbasic.co.uk/forum/showthread.php?t=17282
    Last edited by Demon; - 5th April 2013 at 18:43.

  8. #8
    Join Date
    Apr 2013
    Posts
    12

    Default Re: Having Serin Serout problems

    I'm trying to make it idiot proof(trying to prevent 10k phone calls because people are to lazy to read instruction sheet) and I only want to sell one sku if at all possible. and I could make another data line. But I would like only three wires between modules vcc, ground, and data.

    a and x are initialized to 0 two lines above don't know why I didn't include that. And you are correct on the if statement.

    The way that it works:

    All processors Idle till they receive a 0 on ign. Once the first processor in line goes to zero. It goes to serin. if serin times out. This processor is then assumed to be the master. module is incremented by one to send ID to next processor. It then sends a ground signal out of "out" to advanced the next processor into serin. The master then serouts 5 times (even though I want it to be one). Then goes to a pulse counting state on "out". The second processor receives its module number from serin. stores to eeprom then, increments "module" sends a ground pulse to next processor to get it ready for serin in. After that each slave after that does the same. after it sends serout to next processor. It sends a ground pulse back to previous processor to count. Then it listens on "out" for ground pulse and everytime it gets a ground pulse it just sends the pulse out of "ign" back to the master which then counts how many slaves have been generated. Everything in program works flawlessly except for the serin and serout. as for some reason serin times out and then a slave thinks it is the master also. Just need to know why this is. It is either setup timing, noise (doubt it) or possibly when in serin state it looses its pull up resistor state on B.0 (which is enabled)

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597

    Default Re: Having Serin Serout problems

    Quote Originally Posted by Elusiveinc View Post
    ... I would like only three wires between modules vcc, ground, and data.
    ...
    You might have a point with the internal pull-up resistor being disrupted with the pin being used as input and output. Try an external on each B0, see how that goes.

    Robert
    Last edited by Demon; - 5th April 2013 at 21:00. Reason: Correction to my reply, only 3 wires are indeed required

Similar Threads

  1. Using SEROUT and SERIN
    By acinorth in forum Test Area
    Replies: 1
    Last Post: - 20th July 2011, 11:33
  2. Serin Serout Help
    By MangoKid in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 13th December 2010, 20:00
  3. SERIN and SEROUT
    By CumQuaT in forum mel PIC BASIC
    Replies: 10
    Last Post: - 3rd September 2009, 00:17
  4. serin and serout
    By yeelooi in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th December 2007, 08:35
  5. help with SERIN & SEROUT
    By navaismo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th September 2005, 01:49

Members who have read this thread : 2

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