Wrong value reading ADC

Go To Last Post
76 posts / 0 new

Pages

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

Bobgardner,

I did this change in the code and the result didn't change. It continues to read above 0.030V.

 uint16_t Read_ADC(uint8_t adc_adr)
{
		uint16_t adc_value =0;
	
		ADMUX =(adc_adr)|(1<<REFS0);
		asm("nop");
		asm("nop");
	
		ADCSRA |=(1<<ADSC);

			while(ADCSRA & (1<<ADSC)); {}
	
				adc_value=ADCW;
		
    			while (!(UCSR1A & (1<<UDRE1)));
				           					
				UDR1= (uint8_t)(adc_value>>8);
				

				while (!(UCSR1A & (1<<UDRE1)));
				
				UDR1=(uint8_t)(adc_value);


				return adc_value;
			 
}		

I read only one ADC channel and print it.

Attached please find the schematic

Manuel

Attachment(s): 

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

Looks to me like the 5V and gnd should be on pins 1 and 3 of the pots. The wiper (to the a/d) is pin 2 in the middle?

Imagecraft compiler user

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

Bobgardner,

This pins are pin headers. Pin 1 has the information, 2 is the +5V and pin 3 ground. I use this order because it is the standard in aeromodels like servos, receivers,etc.
Do you see any problem with this order?

Manuel

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

Can you tell us more about the pots, like their size (in ohms). Is the wiper (middle pin normally) connected to pin 1?
Also tell us how & where you are monitoring the voltage. Apologies if this was covered earlier.

Also, the code you posted suggested that you are using adc channel 1 and the schematic shows a 91K resistor in series with the input and a 22K going to ground. Can you explain the purpose of these?

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

Maximax,

The JP15, JP3, JP4 and JP6 aren't pots. They are pin headers to connect female type of plugs used in aeromodels.

Between JP15 and JP3 and the MCU ADC0 and 1 respectively, there is voltage divider 91K and 22K to allow measure voltages till 25,6V (6 elements of LiOn battery) The pin 1 goes to the positive and pin 3 goes to the ground of battery.

To the JP4 is connected a temperature sensor LM35. the pins 2and 3 are power to the sensor, pin 1 is the output of the sensor 10mV/deg.C.

To JP6 is connected a current sensor made with a INA139 with a 0.1V/ampere.

I use channels 0,1,2 and 3. for the above proposes.

I think I gave an idea of what is connected to the ADC inputs.

I notice the ADC problem when was calibrating the current sensor. I was measuring the voltage at the output of the sensor and looking to the ADC value and it didn't look right.

After that I used a 5K pot connecting one side to +5V and the other to the ground, the center pin connected to the ADC input and observed that till the 0.030V the ADC doesn't respond, always reading zero. this happens in all the channels. I suspected of the PCB because the MCU was on a header board, so, I decided to make a new PCB eliminating the header, but the result was exactly the same.

I changed the MCU, same result. I have a simple PCB with a Atmega644P to experiment same code and the result is the same.

Another observation is that the reading is very stable, so, if it was noise it should vary a lot. Another thing is it only responds at voltages above 30mV.
This is very strange because I used 3 different PCB's, more than one MCU, several types of components connected to the ADC, etc.

Thanks,
Manuel

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

You were asked to post your code and you showed an adc setup reading channel 1. You were then asked to show a schematic and this depicts a resistive divider on adc channel 1.
Are you now saying that this is not the actual circuit currently under test? The reason I ask is that the results you are getting are fairly consistent with those I'd expect from connecting another resistor in parallel with the wiper to ground resistance through a much bigger series resistance. :?

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

Maximax,

The schematic I sent is the circuit I use, but, as I already told, I used a 5k multiturn pot just to make a test.

If you look for the schematic the ADC2 there isn't voltage divider. If you use the 5K pot with the middle point connected to pin 1 and one side to ground and the other to +5V, and connect a voltemeter between the pin 1 (ADC2 input), when we increase the voltage from Zero the ADC only starts work at 30mV. this means, from zero volts till 30mv the output of the ADC is zero.

This has nothing to do with another resistor in parallel. We are measuring the real voltage at the ADC input pin. This is my problem.

Is there any one that has a Atmega644P to make a ADC test?

I did the same test using a Atmega328P (Arduino) and it responds correctly (5K pot) 1 bit~= 5 mili Volts.

thanks,
Manuel

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

Instead of 'inlining' the body of the putchar subroutine twice in the a/d routine, why not just write the putchar routine then call it? What if the a/d value is 0x12? You can't print out a binary 1 or a binary 2... they come out as happy face and clubs or something. At least add 0x30 to the binary number to get ascii decimal... 1 becomes 0x31... a '1' in ascii. THAT will print.

Imagecraft compiler user

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

Bobgardner,

Thanks again for your interest. I didn't understand what you mean, but, the data sent out is binary data as read from the ADC register. I am reading the data using the Br@y++ terminal as Hex value. There isn't possibility of being ASCII.

As I do not understand very well your comment I do not know if it answer to it.

Regards,
Manuel

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

OK, when the pot is all the way down, do you see 0x00 0x00 on brays Terminal? Now turn it up till it says 0x00 0x01. Measure the wiper. Should read 5mv. Repeat this test at 0x01 0xff and 0x03 0xff. Should get 2.5V and 5.0V.

Imagecraft compiler user

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

Bobgardner,

Here is the results:

0x000 -------- 0.000V
0x001 -------- 0.035V
0x1FA -------- 2.501V
0x1FF -------- 2.526V
0x3FF -------- 5.04V

Regards,
Manuel

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

As I said earlier, it is hard to measure things in the mud (at very low signal levels). As things appear pretty well spot-on at the higher signal levels, I'd wager that examination with a good 'scope at low V/division will show like 30mV of ripple somewhere--signal, reference, supply, ground. That has always been the result of these threads in the past.

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

It does look like the AVR is sitting in a 32mv deep hole. 32mv of IR drop from the AVR gnds back to the power supply?? Try a Big Fat Ground Wire from AVR gnd to power supply gnd? (all other VCC and GND pins connected, including AVCC?). Try another pot. Maybe that pot you have just has a big jump at zero volts? Is it wire wound?

Imagecraft compiler user

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

Hello all,

Just for your knowledge, I did another PCB, with the following changes:

- Below the MCU I left a square of copper track connected to the grand.

- The bottom copper layer I left an area according to the Atmega644P data sheet and connected it directly to the analog ground pin.

- All the bottom PCB layer is connected to the ground.

- All the ground pin of MCU are directly connected to the same ground point (wires).

- All VCC pins are decoupled as close as possible of the MCU pins.

- Measure the different ground points including the analog ground with the multimeter in uV scale I have 00.00uV.

- I do not have visible noise in the VCC, AVCC, analog lines and ground

In spite of all that I continue to have a 5 bits difference. only at 0.035V the output of the ADC is 0x001.

I am going to give up and chose another MCU.

Thanks for being patient with me.

Regards,
Manuel

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

Quote:

I am going to give up and chose another MCU.


If it's ripple on the PSU how does this help?

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

Run from a battery. No ripple

Imagecraft compiler user

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

Quote:

Just for your knowledge, I did another PCB, with the following changes:
...

From above https://www.avrfreaks.net/index.p...

Quote:

I get 12 counts at 0.0543V with the aforementioned 4.095x reference. At ~4.1mV/count that is fairly close. That's as low as my pot would go. Using a clip lead to Gnd I get 1 A/D count at 4+mV so the low end that OP is fighting looks OK to me.

It sounds like you have covered all the bases with your changes and testing. I've lost track: Have you used more than one piece of AVR and the results are the same? Are the same results repeatable from channel to channel?

As I posted earlier, I saw no problems at the low end with one of my production app boards, and the conditions were less than ideal: flying leads to a trim pot, for example.

Typically a situation like this involves ripple and other signal bounces. How about the measurement itself? Are you sure that your meter is happy reading a few millivolts?

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

Hello all,

Just for your knowledge, I did another PCB, with the following changes:

- Below the MCU I left a square of copper track connected to the grand.

- The bottom copper layer I left an area according to the Atmega644P data sheet and connected it directly to the analog ground pin.

- All the bottom PCB layer is connected to the ground.

- All the ground pin of MCU are directly connected to the same ground point (wires).

- All VCC pins are decoupled as close as possible of the MCU pins.

- Measure the different ground points including the analog ground with the multimeter in mV scale I have 00.00mV.

- I do not have visible noise in the VCC, AVCC, analog lines and ground

In spite of all that I continue to have a 5 bits difference. only at 0.035V the output of the ADC is 0x001.

I am going to give up and chose another MCU.

Thanks for being patient with me.

Regards,
Manuel

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

I'm getting an extremely strong sense of deja-vu!?!

BTW did I say that I'm getting an extremely strong sense of deja-vu?

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

My multimeter is a Fluke, and I use the 300mV scale.

I have 2 Atmega644P and already tried both, the same result.

Do you already look to the code I use? Can the code do some thing like this?

How can I use the "ADC noise canceler function to reduce induced noise from the CPU".

I have a .1uF capacitor on the AREF Pin. Is this OK?

Thanks,
Manuel

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

Hello all,

I used a Arduino Nano on a bread board and run the same ADC code and it gives about 0.005V by bit (long wires etc. and the reading is ok.).

I changed the Crystal in the original board from 18432000Hz to 16000000Hz and at 0,035V i get 0x003 instead of 0x001.

These observations give you some clues?

Thanks,
Manuel

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

Quote:

BTW did I say that I'm getting an extremely strong sense of deja-vu?

I think the repeat was due to my requote(s).

Quote:

These observations give you some clues?

On the original board, do you get the same result on all ADC channels, or just the one?

I've lost track---what prescaler are you using on the original board?

(It certainly is possible that one ADC channel got damaged, or even all of them. For example, a reference voltage error could have been made at some point in ADMUX setting.)

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

Maybe you were running the prescaler too fast for the crystal you were using?

Imagecraft compiler user

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

Quote:
Maybe you were running the prescaler too fast for the crystal you were using?

If you also observe 'bleeding-through' from another ADC channel this is the first thing you should check. Consult the datasheet for the maximum clock of the ADC on the Mega644.
Quote:
I have a .1uF capacitor on the AREF Pin. Is this OK?
It should be ok. In a former post you staed that all your voltages are clean , so 0.1 uF should be fine.

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

Hello all,

After all the problems I decided go to the Atmega328P, as I need 2 UARTS I made a switch with a 74hct08 and its working. I just made a PCB to connect an Arduino pro, http://arduino.cc/en/Main/Arduin... connect it to the PCB with jumper pins, and its working. the ADC reading its OK, 0,035V = 0X005 (five bits). I didn't care about grounds, noise etc. and as I said it is working. I suspect it is a MCU problem.

Thanks to you all to try help me.

Regards,
Manuel

Pages