How to detect when an input has been unplugged?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have an input device that is wired into an ADC on the AtMega644 that I would like to be able to detect when it has been unplugged. I have the ADC port set as an input & the pullup is disabled so that the signal can be sampled by the ADC. If this input is unplugged, how can I detect this condition as the input line will now just be floating? (i.e. with no pullup enabled to sample the signal properly)

Thanks,
James

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps a counter that is always counting upwards but is reset to zero each time an ADC reading is different than the last reading? Once the counter reaches its max, your code assumes there is no more connection to the ADC.

Brad

I Like to Build Stuff : http://www.AtomicZombie.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can enable the pullup periodically, and disable it when you actually make the measurement.

Anyway, I do not recommend to leave the ADC input floating.
When you plug and unplug your input device, you have to make sure you connect first the ground and then the active line and not in the reverse order. Wen you disconnect the input device, you disconnect first the active line and then the ground. Such plugs the ground connections are longer than the active lines (USB).
You can add a small capacitor between the ADC pin and the ground.

George.

George.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is nothing wrong with letting analog inputs float. It's digital inputs that should not be allowed to float. So one should make sure that the DIDR bits for your analog inputs are set.

We will need to know more detail about the analog connection to provide better solutions, but the suggestion of enabling/disabling the internal pull-up might work for you. Doing so will cause the input to float to full scale when nothing is connected.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the responses... I have a couple different applications where I wanted to know this... In each case, though, there are sensor outputs being connected to the ADC's and I would simply like to detect if the sensor has become unplugged from the ADC so that the code could then take different action. I was worried that using a stale data check would not work since the value might still be moving around... and I'd hate to use some type of sample to sample delta criteria either in case the real signal really was jumping around... so I was looking for a more definitive way of detecting that the sensor has become unplugged. It sounds like the method of periodically enabling the pull-up & testing will be a way of doing this. I guess you're saying that by enabling the pull-up momentarily & reading the ADC, the value would read 1024 only if there was nothing plugged in.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Change your sensor cable plugs to ones with an extra pair of isolated pins that short together in the plug and test for a digital absence of the short on the board receptacle side. It will not catch a loose cable, but a completely unplugged cable should be reliably detected.

If your sensor can stand being driven to the power rails, use a plug with two pins connected to each active sensor lead. Then the micro can force the second pin into known high and low states (first one then the other) and measure both states on the first pin. An unplugged or loose plug could be identified this way. It would probably require some external circuitry, high impedance during idle, power rail drivers. This probably could not be mimicked by the sensor signal and should be better at detecting a loose cable.

There are other detection solutions with smarter sensors that return already digitized data, etc. Known data streams are easier to identify when unplugged or even if the cable fatigues and breaks inside.

Use a roll of duct tape to keep the sensor plugged in :)?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have NTC sensors connected to ADC pins.
There is a strong pull-up (3K3) to make up a voltage divider together with NTC resistance.

If sensor is unplugged or cable/sensor are damaged and left open ADC input will read 1024.
If sensor/cable is shorted to GND input will read almost 0 (which is unreasonable low value for NTC).
It is therefore possible to both detect shorted or missing sensor.

Don't know if this is of any use for you since you don't have a pull-up. Maybe you can offset your sensor readings with a weak pull-up and compensate for that in software.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Don't know if this is of any use for you since you don't have a pull-up. Maybe you can offset your sensor readings with a weak pull-up and compensate for that in software.

If the plugged-in device rarely/never gives "max" ADC counts, then you can use the internal pull-up as the "bias" resistor when checking for connectivity.

IIRC the pullup works even with DIDR bit set, but check that.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Assuming I enabled the internal pull-up at regular intervals to test that the sensors were still present... how long would I have to wait for the voltage to stabilize before sampling with the ADC in either case, i.e. just after enabling pull-up, or just after disabling?

I'll also look into the continuous pull-up method with a biased sensor value as well...

Thanks,
James