Toggle line between two PIC's


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    219

    Default Toggle line between two PIC's

    Hi all,
    I want to set up a toggle line between two PIC’s to establish timing parameters for like routines on each PIC. I thought about a pull up resistor on the toggle line then pull it low to set timing. Question: If I have a port pin tied to the Toggle line should I pull the toggle line low with INPUT or TRISx.x then return the port to HIGH when finished?

    I thought this would be a no brainer but it’s not working out so well. I’m not sure of the best way to control the toggle line. On the receiving end I am testing line condition with IF ToggleLine =0 then WhatEver. Would someone please give me an opinion on how they would set up a toggle line between two PIC’s?

    Thanks,
    Wayne

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Toggle line between two PIC's

    To detect the pin state you should use the input state, to pull down the line you should use output state.

    So when you decide that one side should pulldown you use the trisx.x = 0. This will convert the input pin into an output pin, hence you set the pin to low with portx.x = 0. When you have finished you turn the pin into an input again with the tris instruction.

    Cheers

    Al.
    Last edited by aratti; - 19th January 2014 at 00:40.
    All progress began with an idea

  3. #3
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Toggle line between two PIC's

    Al, thanks for the advice, but I just don’t get it. I thought I would need an input to sink the current and pull the line low. How would an out put on the Tris sink current? I’m sure it has to do with the port Tristate hardware but it has been too many years since I could follow the data flow in that hardware. From what you’ve said it would look like this?

    Code:
    Toggle line w/pullup          
    PIC1                        5VDC                  PIC2
    TrisC.1=1…………………………..……………………!……………………………………………………TrisC.1=1
    PortC.1=1                                         PortC.1=1
    
    
    PIC1 -             PIC1 pulls line low             PIC2
    TrisC.1=0….	                                 TrisC.1=1
    PortC.1=0 !……………………………………………………………………………………………………PortC.1=1
    
    
    PIC1 -               PIC2 test line                PIC2
    TrisC.1=0                                        TrisC.1=1
    PortC.1=0…………………………………………………………………………………………………………PortC.1=0
                                                IF PortC.1=0 THEN Whatever
    Thanks,
    Wayne

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Toggle line between two PIC's

    Hi Wayne, from your example here my comment:

    Code:
    Toggle line w/pullup          
    PIC1                        5VDC                  PIC2
    TrisC.1=1…………………………..……………………!……………………………………………………TrisC.1=1
    PortC.1=1                                         PortC.1=1
    Here you have the two pins floating, since both ends are set as input. To have this approach working you need to add a 10K resistor from Vdd to the pins in order to pullup the system via hardware. (Recommended)

    Once you place a pin as an input via tris register you do not need any extra command, since the pin is an input and will stay an input till the following tris setting.

    Now let assume you have your 10K resistor pulling up the line and both pics pins as an input, if you check the line state both pics will report portC.1 = 1 (state high)

    Now let assume you want pic 1 pulldown the line then you have to use the tris register to change the pin of pic 1 from an input to an output.

    TrisC.1 = 0

    Now the pin on portC.1 of pic 1 is an output, but you want to drain all the current via this pin in order to be able to detect the change of state. To do that you must place the output to 0 (ground)

    PortC.1 = 0

    With this instruction you have surely grounded the pin of pic 1 and the reading in the input pin of pic 2 now is 0, since all the current the 10K resistor can supply is drained by the pin of pic 1.

    Now if you want to put high again the line all you need to do is to remove the short generated by the pic 1, and the best way is to turn it again into an input.

    TrisC.1 = 1

    Now pin on portC.1 of pic 1 is an input and cannot drain the current of the 10K so the line return to Vdd value and you could check it with both pics (1 and 2)

    Naturaly you have to Repeat the commands for pic 2 if you want to pulldown from that side.

    Hope this will help


    Cheers

    Al.
    All progress began with an idea

  5. #5
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Toggle line between two PIC's

    Al, thank you very much for your assistance. I’m sure I can take it from here!
    Thanks,
    Wayne

  6. #6
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Toggle line between two PIC's

    Working great. Thanks again Al for that detailed explanation.

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Toggle line between two PIC's

    Happy to know you have your project working.

    Cheers

    Al.
    All progress began with an idea

Similar Threads

  1. TOGGLE will not go LOW
    By SUNFLOWER in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 10th August 2014, 16:53
  2. Toggle command
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2011, 02:07
  3. PIC's in space
    By ScaleRobotics in forum Off Topic
    Replies: 25
    Last Post: - 19th August 2011, 08:46
  4. toggle or count?
    By earltyso in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th May 2008, 08:54
  5. 2 Line Chars on a 2 Line LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th November 2003, 00:44

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