What if.. you forgot to add pullups/pulldowns? - Page 1
Forum section: electronics / general

author: JPortici
author_rank: Super Contributor
timestamp: October 24, 2017, 09:15:09 am
content: This is some kind of academic question, as I just bodged three resistor and connected the other side to GND.Anyway, I am designing this simple board with a 26K22, prototype pcbs arrived and were assembled. In the board there is a 4chan dipswitch that selects different functions. The dipswitch connects to +5V otherwise it will float the input.I didn't add pulldowns because i thought "hey, i can use the internal pulldowns and save board space" but i temporarly forgot i was using a PIC18.. which only have pullups.What would you do in this case, if you couldn't wait for a board respin and/or couldn't bodge resistors?here's what i thought:- In this case i can connect the external DAC to the ADC input, so configure the DAC to output 0V and connect to ADC input.- Switch ADC input to dipswitch inputs (in my case all of these pins are also ADC pins)- Read ADC- If near zero, switch is open, if near VDD switch is closedshould work, right?

author: jaromir
author_rank: Unknown
timestamp: October 24, 2017, 10:05:07 am
content: Quote from: JPortici on October 24, 2017, 09:15:09 amNo.Voltage on floating input can be anything from zero to Vdd. Especially when it's not completely floating, but PCB/switch/whatever leakage can push/pull it up or down, depending on PCB layout, air humidity, dirt on PCB, weather, moon phase and sun activity.You may get lucky on particular prototype, but it may be unpredictable disaster on another board, or another MCU piece, or tomorrow or every time it's raining.

author: daqq
author_rank: Super Contributor
timestamp: October 24, 2017, 10:06:28 am
content: Well, this is a bit of a hack, but when an ADC samples, it tends to use up some of the charge on the input - it's a temporary small load. As such you should be able to 'discharge' the floating pins by sampling them. If you are not able to discharge them (value on ADC stays constant-ish) then you can assume that the input is tied to VCC.Note that I'm not sure that all ADC architectures do this. You should try this. Note though that this is not a proper solution and you should definitely respin the board or do something else with it.

author: JPortici
author_rank: Super Contributor
timestamp: October 24, 2017, 10:15:27 am
content: Quote from: JPortici on October 24, 2017, 09:15:09 amWhat i had in mind was actually exploiting the principle behind capacitive voltage dividers used for touch sensing, at the simplest the ADC sample capacitor is charged to a certain voltage, then the ADC input is switched to the pad's input, the sampling capacitor voltage changes to reflect the capacitance ratio. A lot of noise is to be expected but for a prototype, in the lab, it should work

author: jaromir
author_rank: Unknown
timestamp: October 24, 2017, 10:15:48 am
content: On the other hand, 26K22 has CTMU peripheral; it may be possible to abuse it to this purpose, if the pins in question are available to CTMU.But anyway, you should rework the PCB and include proper pull-down resistors; or move the switches to pull-down position.

author: AndyC_772
author_rank: Super Contributor
timestamp: October 24, 2017, 10:20:34 am
content: The CTMU incorporates a pull-down resistor which you can use to pull an individual pin low. Set IDISSEN to enable it, then read the pin voltage with the ADC.It's not the same as a digital output buffer, and won't draw excessive current if the pin is connected to VCC externally.

author: rstofer
author_rank: Super Contributor
timestamp: October 24, 2017, 01:25:46 pm
content: I would try to cut the Vcc trace to the dipswitches and substitute Gnd. Then I would program the internal pull-ups and invert the sense of the switches.Of course, if you used a via to an internal Vcc plane then this won't work. More often than not, my PCBs are two layer so the plan might actually work.

author: NorthGuy
author_rank: Super Contributor
timestamp: October 24, 2017, 01:38:50 pm
content: Using DAC as a pull-down would certainly work, except I would use some some small voltage on DAC instead of 0.I think you even might be able to use DAC as a pull-down, set ANSEL to zero and read it as a general input, but I'm not 100% sure about this.If I were you, I would rather try to cut the 5V trace from the switch and reconnect it to ground.

author: JPortici
author_rank: Super Contributor
timestamp: October 24, 2017, 02:14:15 pm
content: I'll quote myself again, just for clarityQuote from: JPortici on October 24, 2017, 09:15:09 amso i am not looking for the obvious safe and easy solution, i already did thatReason why I used VDD instead of GND is because one of the switches actually shorts SCK to VDD on a HCS515 to pair with a new remote, so VDD was already there.of course i can just connect the other switches to GND

author: KL27x
author_rank: Super Contributor
timestamp: October 24, 2017, 10:08:06 pm
content: QuoteADC consumes power and takes relatively long time. Maybe I did not think it all the way through, but why not just do digital port read on these pins?I may get poo pooed for this, but I have done this and have no qualms about it: Temporarily set pin to digital lo for a very brief time (just about as fast as you can switch the pin on and off, again) immediately before a digital read. This will technically cause a short circuit between power and ground through the pin when the DIP is actually switched to 5V, but it is very brief.I have done this to read tristate. To reiterate: (If internal pulldowns are not available) briefly set port to digital lo, float, read. Then (if internal pullups are not available) briefly set port to digital hi, float, read. A couple bitmasking operations to return the state of each pin... hi, lo, or hiZ. So each pin can now return 3 states instead of just 2, and they are scanned @ 100 Hz or so. Between reads, internal pullup/down should be applied, if available, to prevent power drain in a noisy environment.Essentially, I have physical 3 way on-off-on switches on these pins that are DIRECTLY tied to Vdd and ground. (This was not even an afterthought; it worked, so I omitted a resistor per pin to save $, lol). The resistance of the pins and brief on time is fine, to me.If you want to get technical about it, you are relying on the capacitance of the pin to hold the state between time you pulse it and you read it, while it is floating. And you are relying on internal resistance of the pin (which is sigificant, but even better when the output FET on the pin is perhaps largely in intermediate state rather than significant time of being fully saturated) to prevent significant glitch/noise on the power rail. It's a good idea to turn off global interrupts while you do the pulse/reads.