Author Topic: What if.. you forgot to add pullups/pulldowns?  (Read 2240 times)

0 Members and 1 Guest are viewing this topic.

Offline JPorticiTopic starter

  • Super Contributor
  • ***
  • Posts: 3574
  • Country: it
What if.. you forgot to add pullups/pulldowns?
« on: October 24, 2017, 09:15:09 am »
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 closed
should work, right?
 

Offline jaromir

  • Supporter
  • ****
  • Posts: 344
  • Country: sk
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #1 on: October 24, 2017, 10:05:07 am »
- If near zero, switch is open, if near VDD switch is closed
should work, right?

No.
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.
 

Offline daqq

  • Super Contributor
  • ***
  • Posts: 2321
  • Country: sk
    • My site
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #2 on: October 24, 2017, 10:06:28 am »
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.
Believe it or not, pointy haired people do exist!
+++Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
 

Offline JPorticiTopic starter

  • Super Contributor
  • ***
  • Posts: 3574
  • Country: it
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #3 on: October 24, 2017, 10:15:27 am »
This is some kind of academic question, as I just bodged three resistor

:)

What 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
 

Offline jaromir

  • Supporter
  • ****
  • Posts: 344
  • Country: sk
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #4 on: October 24, 2017, 10:15:48 am »
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.
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4319
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #5 on: October 24, 2017, 10:20:34 am »
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.

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9964
  • Country: us
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #6 on: October 24, 2017, 01:25:46 pm »
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.
 
The following users thanked this post: Someone

Online NorthGuy

  • Super Contributor
  • ***
  • Posts: 3287
  • Country: ca
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #7 on: October 24, 2017, 01:38:50 pm »
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.
 

Offline JPorticiTopic starter

  • Super Contributor
  • ***
  • Posts: 3574
  • Country: it
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #8 on: October 24, 2017, 02:14:15 pm »
I'll quote myself again, just for clarity

This is some kind of academic question, as I just bodged three resistor [...]

[...]prototype pcbs [...]

[...] What would you do in this case, if you couldn't wait for a board respin and/or couldn't bodge resistors?

so i am not looking for the obvious safe and easy solution, i already did that :)

Reason 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
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: What if.. you forgot to add pullups/pulldowns?
« Reply #9 on: October 24, 2017, 10:08:06 pm »
Quote
- 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 closed

ADC 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.



« Last Edit: October 24, 2017, 11:40:19 pm by KL27x »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf