PIC processor pin contention

If I short two I/O pins of a PIC processor together and repeatedly reverse the states so that one is an input and the other an output and visa versa, will there be any contention?

I'm not sure which happens first when the state of the I/O is changed. If you reverse the state of 2 pins of the same port so that one is an input and the other an output, what happens first? Does the output become an input before the input becomes an output, or does it all happen at the same time?

Or, does it really matter since the possible contention time will be very short?

Thanks,

-Bill

Reply to
wrongaddress
Loading thread data ...

If the control bits are reversed in a single instruction, I think the outputs switch with only propagation differences, from the same clock edge (probably on the rising edge of Q4, the last edge of the 4 cycle instruction clock). At worst, I suspect there will be a few nanoseconds of higher than normal load across the supply terminals. Good bypass practice should handle it.

You could set up an experiment and make some measurements, with the outputs connected through a series pair of resistors. Watch the mid point with a scope. Set one output state to 1 and the other to 0. If there is any overlap, there will be a period of time when the divider will produce a voltage half way between the rails, instead of just swinging cleanly between logic states.

Then switch the 2 output states and check again.

Reply to
John Popelish

Surely the simple solution is to preceed the instruction that changes the pin direction by one that programs both as an input. That way no contention will occur because, for the duration of a couple of instructions, both pins will be floating (i.e. input). A pull-up or pull-down resistor could be used to ensure a definite logic level on the pins if this is a concern.

TRISB=0b11; // both input ** TRISB=0b10; // Bit 0 output : : TRISB=0b11; // both input ** TRISB=0b01; // Bit 1 output

Reply to
Andrew

Hi,

I do a lot of work with PIC's, inculing some unconventional designs. I would like to know why you need to short two pins together. Something I could use?

Luhan

Reply to
Luhan

Exactly the arrangement I would use.

Reply to
budgie

Personally, I'd not connect two bidirectional PIC pins together regardless of the firmware. Treat your PIC to a $0.001 resistor and be sure in all possible states (including the billions of b*gg*r*d-up ones).

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

There are output buffer chips like MAX4427 which are rated for this transition and even specify limits on it.

--
Ben Jackson

http://www.ben.com/
Reply to
Ben Jackson

John,

I connected a couple 1.5K resistors between the pins and the signal looks clean on a low bandwidth scope at the resistors junction.

But, just to make sure there are no problems, I think I'll use the sugestion of setting both pins to input, and then changing one to an output with the next instruction. One more line will only waste one more microsecond.

Thanks,

-Bill

Reply to
wrongaddress

Yes, good idea.

-Bill

Reply to
wrongaddress

I'm using one I/O line to drive a common line to several toggle switches. The other side of the switches are connected to other I/O lines with pullup resistors. This way I can read the state of several switches without any dedicated I/O lines. The I/O pins can be used to monitor the switches and also operate as I/O, but not at the same time.

-Bill

Reply to
wrongaddress

I'll file that factoid away for future reference.

Thanks for reporting the trial.

Reply to
John Popelish

Bill snipped-for-privacy@att.net wrote: [Luhan wrote]

I think you didn't say which PIC you're using, but it seems likely to me that you can get rid of the pullup resistors. For example, the 16F873A has built-in weak pullups on ports B and C lines (but not on ports A, D, E). With software control of whether weak pullups are on or off, you might be able to share a few more lines between switch reading and other I/O, as well as lowering the time and cost of board building.

Also, I agree with Spehro Pefhany's earlier remark about putting some resistors in series with your output lines, say around 1K. (On an AVR board where I use some lines for both i/o and switch reading, by looking at min/max specs for weak pullup resistances, high and low thresholds of LCD i/o and mcu i/o, etc, I calculated I could have up to about 3K in series with those lines. I used

1K x 4 resistor networks about the same size as an 0805 SMD but with 8 pins.)

-jiw

Reply to
James Waldby

I believe that only port B has programmable pull-up resistors on the

16F873A.
Reply to
Andrew

Then what you need to do is drive the common line low when reading the switches, and float (input) the common line when using the other lines as outputs. There will then be no contention for outputs tied together at any time.

Luhan

Reply to
Luhan

Andrew wrote: [James Waldby wrote]

You are right - I thought the port C structures on p. 46 of DS39582A (16F873A.pdf) were like the port B ones on p. 44, but now see that the P device is an output driver in one case and a pullup in the other.

-jiw

Reply to
James Waldby

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.