> Bob Ammerman wrote: > > > > > Barry, > > > > > > I am trying to avoing the adding of a pull-up. Till now, the pin had no > > > purpose. It is not connected to any circuitry except for a header. Now I > > > want to use that pin as an input to allow the user to select a setting (by > > > shorting or not shorting the header to power or ground. > > > > Ah, the light goes on. > > > > Ok, so the pin is connected to either ground, high or nothing. > > > > I am assuming that the pin's connection does _not_ change while the program > > is running. > > > > Here is how I would handle it at initialization. > > > > Set pin high > > Read pin > > if pin is low then > > it is grounded externally > > leave it an input > > goto done. > > end if > > > > Set pin low > > Read pin > > if pin is high then > > it is tied high externally > > leave it an input > > goto done. > > endif > > > > if we get here the pin is floating. configure it as an output so it doesn't > > float. > > > > done: > > > > Note that this tecnhique lets you detect you three possible states for the > > pin (high, low, float). > > > > At worst, you are only driving it for an instruction time or two against the > > opposite value. > > > I'm surprised at this! With all the professionals > on this list, I have become used to the "never go > outside the spec" attitude, like never exceeding > clock frequency etc. I really don't like the idea > of driving a pin against a voltage source or sink, > at 5v or 0v, this is as bad as driving a pin into > a short circuit - which I wouldn't do either! > > Doing it only for "an instruction or two" doesn't > seem to make it any better, it is still so far > out of spec to be scary. I would much prefer to > overclock a PIC at 1.5x its clock freqency than to > do something like this! > -Roman Roman, I agree that this is _not_ a really good idea, but it isn't as awful as not being able to perform a required function at all. The original post indicated that no changes to the board were permitted. Also, we have to think about the consequences of driving into a short. There are three that I can think of: 1: Meeting Voh / Vol specs. This isn't an issue here, or course. 2: Idd spike with attendent Vdd glitch with all kinds of possible trouble - that's why I mentioned checking for this. 3: Chip damage. This is a thermal issue. The first question you have to ask: what is the short circuit current. Looking at a 16F84A as an example (I don't recall what the original poster was using): Max output current (low) = 25ma Max output current (high) = 20ma Vol @ 8ma = 0.6V (max) Voh @ 3ma = Vdd - 0.7V (min) Ok, from the latter two values we can compute a max value for Rdson of the output FETs of: 0.6V/8ma == 75 ohms (low side) 0.7V/3ma == 233 ohms (high side) Given that Microchip isn't in the business of giving away silicon, and that they probably have a pretty good handle on their process, I'm going to go out on a limb and assume that the minimum Rdson is at least 33% of the max Rsdon. Thus: Rdson (min, low side) = 25 ohms Rdson (min, high side) = about 80 ohms Lets take the worst case, the low side. 5V / 25 ohm = 200 ma Assume we use this code (to minimize the drive time): movlw TRISB,FSR ; Point at TRIS register bcf PORTB,x ; Get ready to drive a low bcf INDF,x ; Start the short in this instruction movf PORTB,W ; Get the value bsf INDF,x ; Clear the short in this instruction Thus, we are in the shorted condition for only 2 instructions, or 2 microseconds at 4Mhz (the clock rate is another assumption, of course). So, we are drawing 200ma for 2 microseconds. Thermally this is the same as 20ma for 20microseconds. But, we are allowed to draw 20ma indefinitely. So, unless the thermal time constant of the output driver is less than about 20microseconds, we are not going to thermally damage the output. Now, I admit that some of the above analysis is not 'worst case', but it is reasoned, not just a 'try it and see if it works' attitude. And no, I didn't do this analysis before posting my orignal response, my answer was based on a 'seat of the pants' engineering judgement (ie: I've been here before). Bob Ammerman RAm Systems (contract development of high performance, high function, low-level software) -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.