ATmega microcontroller, detect floating or non connected ADC channel in C.

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

Hello everyone,

I am using all the 8 ADC channels of ATmega32 controller and sending the channel values to PC through USB. This is basically an analog input card. When I disconnect some channels, it starts sending random values to PC. I want to detect these channels initially and exclude them from the reading list. I am using a method, where I am pulling all the channel pins up and reading them for 30 times at the initial program, if the ADC values still more than 1020, then I am marking them as floating channels. But this approach is not giving me a successful result.

If you have any better idea of detecting the floating or non-connected ADC channel please help me.

This topic has a solution.
Last Edited: Wed. Feb 19, 2020 - 07:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rumanshu Nath wrote:
But this approach is not giving me a successful result.

 

what result is it giving you? My guess is there may be some capacitance in your circuit and/or wiring that might affect your result. Identify the root cause and then you can ponder how to mitigate it.

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

Thanks Kartman for your comment.

 

The problem is not about ant kind of capacitance. I am trying to detect floating or non-connected ADC channels. When I remove the analog device from the controller, it should detect that channels as floating. I will send a constant value for that floating channel instead of randomly changing data.

 

FYI, this is a joystick device. If I let that random values go to the PC, my PC application will not work properly.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Put weak pulldowns on the inputs, whatever value has no measurable effect- 470k/680k/1meg, don't know. With nothing connected you should get a value of 0. With the internal pullup enabled, you can probably get a small range where the adc will end up with the internal external combo pullup/pulldown, in the upper range of values. If something was connected to the adc, it should have more strength to override the pullup/pulldown so will not see a much of a change in the adc value. You then rule out the possibility that an input is sitting at one of the two values you are initially checking.

 

 

code something like the following, where the 0 values are validated. Valid values 0-1023, inactive is -1.

//-1 = inactive, 0-1023 = valid value
int16_t adc_channel(channel_t ch){
    int16_t v = adc(ch);
    //if is 0- disconnected or signal is at 0v, so check
    if( v == 0 ){       
        //if can change adc reading by x, is disconnected
        pullup_on(ch);
        if( adc(ch) > 800 ) v = -1; //disconnected (pullup is working)
        pullup_off(ch);
    }
    return v;
}

Last Edited: Wed. Feb 19, 2020 - 07:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what is normally connected tot he ADC pin?

what normal ADC range does that have ( if it is full scale, they it will be difficult )

 

If you can change the pin back to digital every now and then put some sort of pattern on the line and see if the reaction either meets a connected or a floating pin.

you could even connect the ADC pins to another IO line( with perhaps some glue logic/electronics ) and every now and then toggle that to get a response on the ADC that will tell you if there still is something connected or not.

But that all depends on what things are actually connected to the ADC lines.