On 5 Apr 2017 at 10:01, James Wages wrote: > Sat, 01 Apr 2017, Brent Brown > > What was wrong with the idea of turning internal=20 > > pull-ups on only while reading switches and=20 > > setting port lines to output low the rest of the time? > > If reading switches occupied say 0.1% of CPU time > > (seems reasonable) power consumption of pull-ups is=20 > > reduced by a factor of 1000. >=20 > I don't believe anything is wrong with keeping one's "input pins" > set to "Outputs" most of the time (switching them to "Inputs" only > as needed). Since I am using DIP Switches to switch the PIC's > inputs to GROUND, I would just set the PIC's pins to be GROUND > Outputs. There is one caveat to the "let's use internal pull-ups" > approach: quantity of pins with internal pull-ups!=20 Ok, I see. =20 > In my application, I am using the PIC16F1508, which is a 20-pin PIC. > It has PORTS A, B, and C (18 pins), but only PORTS A & B have > internal pullups (10 pins). For some designs, 10 pins is > sufficient, but there are times one may need more than 10 inputs on > the same PIC. =20 >=20 > I suppose that one could use internal pull-ups on 10 pins and then > use 100k-ohm external pull-ups on the PORT-C I/O as needed. But > then we get back to the original question, "is 100K too large or > just right in a noisy automotive environment?" Sure, 1K will solve > your noise problems, but the average current draw when the DIP > Switches are set to GND is a problem.=20 For more than 10 x DIP switches with only 10 x internal pull-ups you may ne= ed to=20 get creative. Like say 20 x DIP switches in an matrix of 10 x rows (the 10 = x PIC=20 inputs with internal pull-ups) and 2 x columns (regular PIC I/O's without i= nternal=20 pull-ups). The downside/drawback/compromise is that you will likely need a = diode=20 for each switch, to avoid shorts from 2 or more switches on at the same tim= e in the=20 same column (unless such a condition prepresents an invalid switch setting = in your=20 application). Select the column you wish to read by making that PIC output = low,=20 configure the non-selected column as an input, read all 10 x inputs. Repeat= for the=20 other column. That's 20 x DIP switches with just 12 x I/O and no external pull-ups (but 2= 0 x diodes,=20 or 10 x dual diodes, or some diode arrays...). Many variations of number of= rows &=20 columns are possible of course. I speculate there may be other cleverer (tm) schemes that avoid the need fo= r=20 some/all of the diodes, maybe by throwing in a resistor or two, but let's n= ot go there=20 if we don't need to. > Sun, 2 Apr 2017, RussellMc apptechnz@gmail.com > > I suggest that it would be a very good idea to=20 > > write out the requirement again and summarise=20 > > the reasons that various key options do not > > meet your needs... >=20 > The concept behind our dialog on this topic is rather simple. There > are basically 2 main points to consider:=20 >=20 > (1) In the application being discussed, there are numerous DIP > switches to be connected to a PIC16F1508 (20-pins total, PORTS A/B/C > comprising 18 of those pins). One side of the DIP SW block is tied > to individual PIC I/O pins, and the opposite side of those DIP > Switches leads to ground. Therefore, we need pull-up resistors, > either internal or external, for handle the case of when the DIP > Switches are OFF (severed connection to Ground, floating). The use > of pull-ups resistors prevents a "floating" state, and they pull the > PIC's input to HI when the DIP is OFF (not GND).=20 >=20 > (2) We want very low average current consumption ("how low can you > go?") with acceptably good noise immunity for 12-volt automotive > use. Since the pull-ups draw most of the current in the said > application when the DIP Switches are closed (connected to GND, > pulling current through the pull-ups), the entire discussion we've > been having to date has been about how to reduce that current > consumption in a reliable way in light of automotive noise. In my > own design, I have been using 100k-ohm pull-ups without problem > (bench testing and testing in one car) in part because the internal > impedance (equivalent resistance) of the PIC16F1508 is very large > due to it being the leg of a FET. On a bench test I was able to > confirm proper operation when even 1M-ohm pull-ups are used, with > almost no voltage drop measured at the PIC input pin side when the > DIP Switch is open/floating. The lack of a significant voltage drop > across the large pull-up resistor indicates that the equivalent > internal resistance of this PIC's Inputs is much greater than that > 1M-ohm pull-up resistor. But while the huge internal resistance of > this PIC's inputs theoretically allow for the use of very large > external pullups, we also must consider the noise inherent to > automobiles and how that will affect use of very large external > pull-ups. Please review TABLE-1 on page-2 of the following PDF for > the types of noise that can be expected:=20 >=20 > http://bit.ly/2n8X5JV >=20 > Will automotive noise accidentally cause one or more PIC inputs to > be pulled to GND due because the external pull-up is too large?=20 > That's really been the question all along, and thus far we've only > had speculation that says: "Probably, and so it's PROBABLY best to > use smaller external pull-ups if indeed external pull-ups need to be > used at all."=20 Probably is a word I (Brent, not Russell) probably used. I almost certainly= used the=20 phrase almost certainly as well. =20 > I agree that using 100k-ohm external pull-ups is PROBABLY safer than > using 1M-ohm pull-ups, that too is more speculation than anything in > that my own tests have not been mass-produces and used in thousands > of different cars. Because no one has presented such hard evidence > on why a given value of a pull-up resistor is bad in a car's noisy > environment, the discussion then turned to "well, why even use > external pull-ups at all?" I think that new question is important, > but I still am curious about the original question: "HOW BIG IS TOO > BIG when it comes to external pull-ups on modern PICs like the > 16F1508 when used in 12-volt automobiles?"=20 Not speculation if you look at it this way: You WILL have a problem with no= ise at=20 some point. It's the point that is un-known. To quantize generally expected "noise" in an environment is nigh on impossi= ble. But=20 your question above can not be answered unless you quantify the noise. Does the device sit next to the ignition coil, or is it located in the boot= /trunk? Does it=20 receive static discharges from the driver whenever they enter/exit the vehi= cle? Is a=20 cell phone likely to be used near-by? I did take a look at the table in the document you refer to the. The typica= l=20 automotive transients are quantized nicely in terms of time and energy, and= that can=20 be of some use, but such figures do not translate nicely into voltages/curr= ents=20 observed at a PIC input (even with a known impedance) if the coupling mecha= nsim=20 is not defined. Still too many un-knowns. Your testing and validation are required. (Re-)create the most realistic bu= t worst=20 possible operating environment, test and establish that your design works=20 acceptably under those conditions. Leave some margin for Murphy and his law= .. Don't forget the power of software techniques to mitigate the effects of no= ise. Apologies if I'm sounding too school-teacher-ish or anything. --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .