PDA

View Full Version : Toggle line between two PIC's



MOUNTAIN747
- 18th January 2014, 23:37
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

aratti
- 19th January 2014, 00:34
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.

MOUNTAIN747
- 19th January 2014, 18:00
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?



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…………………………………………………………………………………………………………P ortC.1=0
IF PortC.1=0 THEN Whatever


Thanks,
Wayne

aratti
- 19th January 2014, 20:13
Hi Wayne, from your example here my comment:



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.

MOUNTAIN747
- 19th January 2014, 21:17
Al, thank you very much for your assistance. I’m sure I can take it from here!
Thanks,
Wayne

MOUNTAIN747
- 20th January 2014, 00:14
Working great. Thanks again Al for that detailed explanation.

aratti
- 26th January 2014, 22:57
Happy to know you have your project working.

Cheers

Al.