Help with 2 way communication


Closed Thread
Results 1 to 3 of 3
  1. #1
    jessey's Avatar
    jessey Guest

    Default Help with 2 way communication

    Hello,

    I wrote some very basic code to communicate back and forth between a 16F688 & 18F452 and would like to get some feed back on it or any suggestions for an alternate way of doing it, if its within my comprehension. I'm using one wire connected between pin 11 of the 688 and pin 7 of the 452, both pic's in/out pins have a 10k pull-downs and also a ground wire connected between the power supplies of the 2 circuits.

    The code I wrote works as follows:
    When its time to turn on or off a pump the code enters a WHILE - WEND where I change the Communications_Pin to an output and send a + signal to the 18F for 100 ms then I set it back to an input and pause for 50 ms for a confirmation back from the 18F that the signal was received. This repeats until the 18F replies. When the 18f replies then that gets us out of the WHILE - WEND and we enter another WHILE - WEND and remain there for the time that the 18F sends its + confirmation signal back that it received our request.

    Then when the 18F's + confirmation signal times out, we set the Communications_Pin to an output again and send a + signal back for 1500 ms to turn on the pump and/or 2500 ms to turn off the pump. While receiving, the 18F's code sits in a WHILE - WEND with a counter and ends up with a number that's used in IF - THEN's to decide what to do. Everything seems to work good with no problems. I'm using the INTRC_OSC_NOCLKOUT on the 16F and OSC 4 on the 18F. Will temperature become a problem with this set up, I can't seem to get anything out of the data sheets for this one concern I have?

    Thanks
    jessey

    16F code:
    Code:
        TRISA.2 = 1 'pin is input before entering while - wend
    
    WHILE Communications_Pin = 0'18F sends + to get us out of this loop  
        Wait_Time2 = Wait_Time2 + 1'sound an alarm if we don't get a + back
        IF Wait_Time2 >= 80 THEN'setting C to 0 allows alarm prints to show    
            GOSUB Set_PORTA5_To_Output:GOSUB Sound_Alarm:C=0 
        ENDIF  
        TRISA.2 = 0 ' set Communications_Pin output to enable send to 18F  
        Communications_Pin=1'+ signal is now being sent to 18F controller
        GOSUB Pause_100 ' send the + signal for 1/10 of a second 
        TRISA.2 = 1 'set pin input to receive a confirmation back from 18F   
        GOSUB Show_Waiting_And_Or_Error_Print
        PAUSE 50             
     WEND'we get out of this WHILE-WEND loop after receiving confirmation
        LCDOut $fe, 1, "Confirmation Has"  
        LCDOut $fe, $c0, " Been Received  "
       'WHILE-WEND for the 18F Confirmation     
        WHILE Communications_Pin = 1 : WEND ' 18f sends + back for 500ms here
        TRISA.2 = 0' set Communications_Pin to an output to reply   
        Communications_Pin = 1'+ signal is now being sent to 18F controller
        IF Moisture <= Alarm_Set_Point THEN Pump=On_:PAUSE 1500
        IF Probes=0 THEN Probes=1:Pump=Off_:PAUSE 2500                 
        Communications_Pin = 0'stop the 18F from counting any more...
        Confirmation = Was_Confirmed'prevents ending up back here next pass 
        TRISA.2 = 1 ' Communications_Pin is set to input before returning
    18F code:
    Code:
    Receive_1st_Incoming_Pulse:
        LCDOut $fe, 1,"Received Request"
     LCDOut $fe, $c0, "Snd Confirmation"
     WHILE Communications_Pin = 1 : WEND'wait here until 688 is finished sending +  
     TRISA.5 = 0 ' make Communications_Pin an output to send confirmation to 688 
     PAUSE 10
     Communications_Pin = 1' sending confirmation now  
     Pulse_Length = Is_Not_Counted 
     PAUSE 500 ' send confirmation for 1/2 second to be sure its received    
     TRISA.5 = 1 ' make Communications_Pin an input again to receive 2nd pulse 
    
    Receive_2nd_Incoming_Pulse_Loop:
       LCDOut $fe, 1, " Receive Pulse  "
     LCDOut $fe, $c0, "CountPulseLength" 
     WHILE Communications_Pin = 1'wait here until finished receiving pulse from 688 
         Time_In_Loop = Time_In_Loop + 1
           LCDOut $fe, 1, " Receiving Now  "
         LCDOut $fe, $c0, "PulseLength =",DEC Time_In_Loop'Count the length of pulse   
         Pulse_Length = Is_Counted : PAUSE 100
     WEND 
     IF Pulse_Length = Is_Counted THEN Use_Count_To_Decide_What_To_Do
     PAUSE 100 
    GOTO Receive_2nd_Incoming_Pulse_Loop 'stay here until incoming pulse is received 
    
    Use_Count_To_Decide_What_To_Do:          
     IF Time_In_Loop <= 18 THEN Pump = Is_Turned_On    
     IF Time_In_Loop >= 20 THEN Pump = Is_Turned_Off   
     Time_In_Loop=0  
    RETURN

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jessey
    Will temperature become a problem with this set up,
    I wouldn't think so. You've got a pretty big margin of error with that routine.

    Looking at Figures 15-37 thru 15-40 of the 16F688 datasheet, it looks like there's only a +/- 3% change in freq across the -40 to +125°C range.

    So the 1500ms will be 1455-1545ms, and 2500ms will be 2425-2575ms.

    Since the receive loop is timed by a 100ms pause, the count will only change by +/-1, across the whole temperature range.

    I think I would add a minimum though. If it only gets a count of 1 or 2 then it's just spurious noise and should be rejected.

    HTH,
    DT

  3. #3
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Thanks Darrel

    Hi Darrel,

    Thanks for clearing that up for me. I'll have to spend more time deciphering the data sheets.

    Thanks Again
    jessey

Similar Threads

  1. 2 PIC, serial communication
    By lightgreen in forum Serial
    Replies: 6
    Last Post: - 21st November 2009, 15:20
  2. USB-FTDI[UM232R] with PIC16f877a
    By bjox in forum USB
    Replies: 1
    Last Post: - 23rd February 2008, 22:40
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. PBP 16F876A 2 Way Communication
    By dmugan in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 31st August 2006, 23:19
  5. PIC 2 PIC communication
    By Mario in forum Forum Requests
    Replies: 16
    Last Post: - 28th April 2006, 01:56

Members who have read this thread : 1

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