NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Sensors, Actuators, and Robotics » ADC ignores Pin DC5 and all pins pull high/low together

June 07, 2011
by KilbySeale
KilbySeale's Avatar

Hi All,

I am trying to use pins DC5-DC2 to do analog to digital conversions. However, I am getting extremely strange behavior. I am using the following piece of code to read from each pin, but pulling one pin high causes all of them to go high (generally speaking, to varying degrees), and pulling one pin low causes all of them to go low. Additionally, pin DC5 seems to be responding to ADMUX=4, which is puzzling to me.

Am I doing it wrong?

+>J

while(1) {

// Read pin PC5
ADMUX=5;
sensor1=adc_read();

// Read pin PC4
ADMUX=4;
sensor2=adc_read();

// Read pin PC3
ADMUX=3;
sensor3=adc_read();

// Read pin PC2
ADMUX=2;
sensor4=adc_read();

  // translate sensors
  status_one=0;
  status_two=0;
  status_three=0;
  status_four=0;

  status_one=sensor1>120;
  status_two=sensor2>120;
  status_three=sensor3>120;
  status_four=sensor4>120;

  // Write test output       
  lcd_line_two();
  lcd_write_string(PSTR("Sensors 1-4 on: "));

  lcd_line_three();

  // Sensor 1
  lcd_write_int16(sensor1);
  lcd_write_string(PSTR("  "));
  lcd_write_int16(status_one);
  lcd_write_string(PSTR("  "));

  // Sensor 2
  lcd_write_int16(sensor2);
  lcd_write_string(PSTR("  "));
  lcd_write_int16(status_two);
  lcd_write_string(PSTR("  "));

  //Sensor 3
  lcd_line_four();
  lcd_write_int16(sensor3);
  lcd_write_string(PSTR("  "));
  lcd_write_int16(status_three);
  lcd_write_string(PSTR("  "));

  //Sensor 4
  lcd_write_int16(sensor4);
  lcd_write_string(PSTR("  "));
  lcd_write_int16(status_four);
  lcd_write_string(PSTR("  "));

  //delay_ms(500);

} return 0; }

June 08, 2011
by Rick_S
Rick_S's Avatar

How are you pulling them high? Is there a pulldown on each port to ensure it's low when not high or are you trying to read a true analog signal?

Rick

June 08, 2011
by bretm
bretm's Avatar

Is your adc_read starting a new conversion after you change admux, or is it reporting the result of the previous conversion already started with the old admux and then starting a new conversion? The adc_read in the temp sensor sample project does the latter, so it doesn't work if you're changing admux.

June 08, 2011
by KilbySeale
KilbySeale's Avatar

At this point I am debugging, so I am manually pulling them high or low by connecting them to the rails. I have the code set up to show on the LCD the signal it is getting for each pin.

Fixing the adc_read() fixed the initial problem with DC5, etc. Thanks Bret!!!

Now... for actual signal. How do I go about pulling them down? Do I have to use NPNs or is there an internal way? (Would it be NPNs or PNPs?)

+>Josiah

June 08, 2011
by Rick_S
Rick_S's Avatar

Do you have a wire to ground on all of the adc inputs except the one you are connecting to 5v or are you leaving them floating? If you are leaving them floating, you will get odd results. To pull them down, just connect a 10k resistor between each input and ground that way when they are not being forced high, the resistor will keep them low.

Rick

June 08, 2011
by KilbySeale
KilbySeale's Avatar

That did it. Thanks!!!

Post a Reply

Please log in to post a reply.

Did you know that first-order systems have a exponentially decaying response to step inputs? Learn more...