Problems controlling multiple pics


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Lightbulb Thankyou so much!

    Awesome coding suggestions. I was able to get rid of 4 pages of code using similar thinking after you showed me that. (guess my brain just finally started working) ^^

    also, I tried something just as a blind guess at a way to fix the problem, or help a little, and it worked really well. I put a 470 ohm resistor to the ground from the picin pin on the slave. seems to have gotten rid of noise that was causing it to think it was recieving data when it wasn't, and it lowered the number of errors in general pretty significantly.

    Maybe thats standard practice? Or was it really insanity to genius. Anyways hopefully that fixed it. ^^
    Last edited by gandora; - 29th May 2007 at 00:16.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gandora View Post
    Awesome coding suggestions. I was able to get rid of 4 pages of code using similar thinking after you showed me that. (guess my brain just finally started working) ^^

    also, I tried something just as a blind guess at a way to fix the problem, or help a little, and it worked really well. I put a 470 ohm resistor to the ground from the picin pin on the slave. seems to have gotten rid of noise that was causing it to think it was recieving data when it wasn't, and it lowered the number of errors in general pretty significantly.

    Maybe thats standard practice? Or was it really insanity to genius. Anyways hopefully that fixed it. ^^
    Hmmmm, What it does is short out the hi impeadence noise, since the noise doesn't have the amperage to carry through, but the signal does.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    May 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by Joe S. View Post
    Hmmmm, What it does is short out the hi impeadence noise, since the noise doesn't have the amperage to carry through, but the signal does.
    Thats what I thought it was doing, I did the same thing with the line in from the pc and I haven't had any errors since, but I still have the double buffer system that will make sure i know when i get one.

    Now I can move on to the next challenge. Which is, having multiple commands qued to be executed at once.

    I will get to work on that task and post my results when I get somewhere with it.

  4. #4
    Join Date
    May 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Post New capabilities.

    I have now given the master an 8 command buffer. And finnally life is good ^^.

    I think I am going to up the buffer to 16, but that will require that I use 2 buffer arrays. For now, heres the master code, feel free to make any suggestions, and just let me know if you use it in any projects.

    :MSmaster:
    Code:
    '****************************************************************
    '*  Name    : MSERVMASTER.BAS                                      *
    '*  Author  : Joseph Dattilo                                    *
    '*  Notice  : Copyright (c) 2007 Joseph Dattilo                 *
    '*          : All Rights Reserved                               *
    '*  Date    : 5/25/2007                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
            define OSC 8
            OSCCON = %1111110 ' sets internal osc to run at 8MHZ
    
    '----------turn analog on porta off, and use as digital input/output
    '----------this is used to allow serial input on the A bus.
            CMCON = 7 'Comparators OFF
            ANSEL = 0 'A/D OFF -- Port pins all digital
    '----------
    
    '---**Pins
    rsoutpin var porta.0
    rsinpin var porta.1
    
    picinpin var portb.4
    picoutpin var portb.5
    
    porta=0
    portb=0
    
    '---vars
    
    temp var byte
    qued var byte
    outqued var byte
    
    message  var byte[24]
    
    '-up to 8 commands can be buffered in que array.
    que var byte[96]
    '---------------
    
    
    qued = 0 'set number in que to 0
    goto pcin
    
    '############################## pc recieve ################################
    'que up messages from pc
    '##########################################################################
    
    pcin:
    
            '---- let pc know we are ready to recieve message.      
            serout2 rsoutpin, 16468, ["waiting!"] 'call for data           
            '---- ready to recieve message
            serin2 rsinpin, 16468, [str message\24]
            
        '------------------------------------------------------------------------
        'compare both arrays checking for bad data if data bad request it again.
        for temp = 0 to 11 : if message[temp] <> message[temp+12] then goto baddata
        next temp
        '------------------------------------------------------------------------
    
        
        serout2 rsoutpin, 16468, [str message\12] 'send confirmation of reciept.
        
        '------------------inque-----------------
         for temp = 0 to 11:que[(12*qued)+temp]=message[temp]:next temp
         serout2 rsoutpin, 16468, ["Qued:",str que\(12*qued+12)] 'display all in que
         
        
        '----------------------------------------
        
        if message[11] = "n" then
        serout2 rsoutpin, 16468, ["still more commands!?"] 'debug statement
        
        qued=qued+1 'go to next position in que
        
        goto pcin   'request the data for the next item.
        
        else
        
        outqued = 0 'set picout que start position to 0 (first item in que first)
        
        goto picout 'we are ready to command the servo controller.
        
        endif
        
        
            
            '-------------------------
            'where bad data takes you.
            baddata:
            serout2 rsoutpin, 16468, ["bad data!"]    
            goto pcin
            '-------------------------
    
    
    
    '############################## pic transmit #############################
    '---- picout procedure waits for high on picinpin and then transmits data
    '#########################################################################
    
    picout:
    
    '---------------------unque next item into message array        
    for temp = 0 to 11:message[temp]=que[(12*outqued)+temp]
    message[temp+12]=que[(12*outqued)+temp]:next temp
    '------------------------------------------------------- 
    
        input picinpin
    
            while picinpin = 0
            pause 1
            wend       
    
    
        serout2 picoutpin, 16468, [str message\24]
        pause 7
    
            if picinpin = 1 then      'checks if data was recieved
            goto picout  're-send until recieved
            endif
            
    serout2 rsoutpin, 16468, ["SUCCESS|",str message\12,"|"] 'tell computer
    
    if outqued < qued then
    
    outqued = outqued +1 'move to next qued item
    goto picout          'proceed to transmit it.
    else
    serout2 rsoutpin, 16468, ["|ALL",DEC (qued+1),"items transmitted succesfully|"]
    qued=0
    goto pcin
    endif
    
    
    end

    It is important that you attribute for the pause 7 in the master in the slaves procedure to prevent the master from constantly retransmitting the first message in the que.

    This is the modified recieve part of the function which allows the mserv slave to recieve any number of messages in a row.
    :MSslave:
    Code:
    '############################SLAVE RECIEVE################################
           
    '######################################################################
    
    recieve:
    
            '----send serial request, and get user input for motor drive timeout 70 ms       
             
             high picoutpin
                    
            '----
            
            serin2 picinpin, 16468,20,drivemotor, [dec2 servonum[0],skip 1,_
            dec3 rate[0],skip 1,dec3 position[0],skip 1,donecommanding[0],_
            dec2 servonum[1],skip 1,dec3 rate[1],skip 1,dec3 position[1],skip 1,_
            donecommanding[1]]
            
            if servonum[0]!=servonum[1] or rate[0]!=rate[1] or _ 
            position[0]!=position[1] or donecommanding[0]!=donecommanding[1] then
            'data is bad recieve again      
            goto recieve 'try again
            endif
            
            low picoutpin
            '-----
    
                'setup the servo chosen
                goalarray[servonum-1]=position[0]  'set servo goal
                ratearray[servonum-1]=rate[0]      'set servo rate
                '
            'allow for multiple commands.
            if donecommanding[0] = "n" then
            pause 7 'pause long enough to make sure master does not attempt retrans.
            goto recieve
            endif
            
            
            
    goto drivemotor
    Last edited by gandora; - 29th May 2007 at 08:31.

  5. #5
    Join Date
    May 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Cool

    Okay so that wasn't too hard.

    The master transmitter now uses pretty much all of the ram available on the 16F88 as a buffer. Allowing 16 commands to be stored and transmitted from 2 seperate buffers.

    I am pretty sure I will not be needing more then that for this project and so here it is.

    :MSmaster:
    Code:
    '****************************************************************
    '*  Name    : MSERVMASTER.BAS                                      *
    '*  Author  : Joseph Dattilo                                    *
    '*  Notice  : Copyright (c) 2007 Joseph Dattilo                 *
    '*          : All Rights Reserved                               *
    '*  Date    : 5/25/2007                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
            define OSC 8
            OSCCON = %1111110 ' sets internal osc to run at 8MHZ
    
    '----------turn analog on porta off, and use as digital input/output
    '----------this is used to allow serial input on the A bus.
            CMCON = 7 'Comparators OFF
            ANSEL = 0 'A/D OFF -- Port pins all digital
    '----------
    
    '---**Pins
    rsoutpin var porta.0
    rsinpin var porta.1
    
    picinpin var portb.4
    picoutpin var portb.5
    
    porta=0
    portb=0
    
    '---vars
    
    temp var byte
    qued var byte
    outqued var byte
    
    message  var byte[24]
    
    '-up to 8 commands can be buffered in each que array adding up to 16 altogether.
    que var byte[96]
    que2 var byte[96]
    '---------------
    
    
    qued = 0 'set number in que to 0
    goto pcin
    
    '############################## pc recieve ################################
    'que up messages from pc
    '##########################################################################
    
    pcin:
    
            '---- let pc know we are ready to recieve message.      
            serout2 rsoutpin, 16468, ["waiting!"] 'call for data           
            '---- ready to recieve message
            serin2 rsinpin, 16468, [str message\24]
            
        '------------------------------------------------------------------------
        'compare both arrays checking for bad data if data bad request it again.
        for temp = 0 to 11 : if message[temp] <> message[temp+12] then goto baddata
        next temp
        '------------------------------------------------------------------------
    
        
        serout2 rsoutpin, 16468, [str message\12] 'send confirmation of reciept.
        
        '------------------inque-----------------
         
         for temp = 0 to 11
             if qued<8 then  'add to first que
             que[(12*qued)+temp]=message[temp]
             else             'add to second que
             que2[(12*(qued-8))+temp]=message[temp]
             endif
         next temp
         
             if qued>7 then
             serout2 rsoutpin, 16468, ["Que 1:",str que\96, _ 
             "Que 2:",str que2\(12*(qued-8)+12)]
             
             else
             
        serout2 rsoutpin, 16468, ["Que 1:",str que\(12*qued+12)] 'display all in que
        
             endif
        '----------------------------------------
        
        if message[11] = "n" and qued<15 then
        
        serout2 rsoutpin, 16468, ["still more commands!?"] 'debug statement
        
        qued=qued+1 'go to next position in que
        
        goto pcin   'request the data for the next item.
        
        else
        
        outqued = 0 'set picout que start position to 0 (first item in que first)
        
        goto picout 'we are ready to command the servo controller.
        
        endif
        
        
            
            '-------------------------
            'where bad data takes you.
            baddata:
            serout2 rsoutpin, 16468, ["bad data!"]    
            goto pcin
            '-------------------------
    
    
    
    '############################## pic transmit #############################
    '---- picout procedure waits for high on picinpin and then transmits data
    '#########################################################################
    
    picout:
    
    '---------------------unque next item into message array        
    for temp = 0 to 11
    
    
    
    if outqued<8 then  'add to first que
             message[temp]=que[(12*outqued)+temp]
             message[temp+12]=que[(12*outqued)+temp]
             else             'add to second que
             message[temp]=que2[(12*(outqued-8))+temp]
             message[temp+12]=que2[(12*(outqued-8))+temp]
             endif
    
    next temp
    '------------------------------------------------------- 
    
        input picinpin
    
            while picinpin = 0
            pause 1
            wend       
    
    
        serout2 picoutpin, 16468, [str message\24]
        pause 7
    
            if picinpin = 1 then      'checks if data was recieved
            goto picout  're-send until recieved
            endif
            
    serout2 rsoutpin, 16468, ["SUCCESS|",str message\12,"|"] 'tell computer
    
    if outqued < qued then
    
    outqued = outqued +1 'move to next qued item
    goto picout          'proceed to transmit it.
    else
    serout2 rsoutpin, 16468, ["|ALL",DEC (qued+1),"items transmitted succesfully|"]
    qued=0
    goto pcin
    endif
    
    
    end

    As a note no changes need be made to the slave from last version for cross compatability.

Similar Threads

  1. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 15:18
  2. Multiple Pics accessing single EEPROM
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd February 2008, 17:22
  3. Retrieving infos from multiple PICs on a bus/chain
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th October 2007, 04:42
  4. Multiple PIC's with 1 crystal
    By puma in forum Schematics
    Replies: 11
    Last Post: - 20th March 2007, 17:02
  5. Multiple Pics to One serial port
    By Rleonard in forum Serial
    Replies: 1
    Last Post: - 18th January 2007, 18:30

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