The main problem with the following test code (readVoltage()) that I have is that it only diplays the factional part of voltage reading. For example the voltage reading should be xx.yy. But it only displays yy part and not the xx part. It actually display xx part but always zero which can not be. Where is the problem. Thanks
The problem with the function is solved, at least partially. There was a mistake in using the function itoa(). Now I get the reading the I expect. However there are two problems.
Problem 1:
I took several repeated readings at different positions of pots. For the most part the readings are consistent but there are some variations. What causes those variations and how to prevent them? See below for the reading result which appear of Brays++ terminal on PC
Problem 2:
I wanted to make sure that the values that I read using mcu is correct. So I compared each reading with the actual readings that I took using multimeters. As you can see below, the reading by mcu is not that accurate speacially the fractional part of it. How to get a matching reading? I tried to read the other part of the array like array[1], array[2] but I could not increase the number of digits either for integer part or factional part. How to do that? I mean how to display this for example 5.23 ? Thanks
related to problem 1 above:
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.9 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 1.4 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.1 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.1 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.3 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 5.0 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 5.0 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 5.3 volts
The reading is 5.3 volts
The reading is 5.0 volts
The reading is 5.4 volts
The reading is 5.4 volts
The reading is 5.3 volts
The reading is 5.1 volts
The reading is 5.3 volts
The reading is 5.0 volts
The reading is 5.3 volts
The reading is 5.4 volts
The reading is 5.4 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.4 volts
The reading is 4.4 volts
The reading is 5.3 volts
The reading is 5.4 volts
The reading is 5.3 volts
The reading is 5.3 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.1 volts
The reading is 5.3 volts
The reading is 5.1 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.4 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.4 volts
The reading is 5.3 volts
The reading is 5.4 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.2 volts
The reading is 5.4 volts
The reading is 5.5 volts
The reading is 5.3 volts
The reading is 5.3 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 5.0 volts
The reading is 5.3 volts
The reading is 5.4 volts
The reading is 5.3 volts
The reading is 5.2 volts
The reading is 5.2 volts
The reading is 5.2 volts
The reading is 5.3 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.4 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 4.2 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 4.0 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 4.0 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 3.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 2.4 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.3 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.9 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
The reading is 0.1 volts
Good analog grounding, low noise power supplies, a good voltage reference. Pots also can be especially noisy.
Your decimal conversion system is very suspect. An input of 255 (pegged analog input) will return 5.5. Is your Vref/Vadc maxing out at 5.5? Further more, 240 % 50 = 40, and 240 / 50 = 4, leading to you printing 4.4. The correct result assuming max voltage at 5.0 and 0.0196 volts per ADC count is 4.704V.
You could bandaid it by making the modulus with a leading 0 and always two digits. It would then be a vague approximation of the true math.
Good analog grounding, low noise power supplies, a good voltage reference. Pots also can be especially noisy.
So that means I am not the problem. I can live with that for now
Your decimal conversion system is very suspect. An input of 255 (pegged analog input) will return 5.5. Is your Vref/Vadc maxing out at 5.5? Further more, 240 % 50 = 40, and 240 / 50 = 4, leading to you printing 4.4. The correct result assuming max voltage at 5.0 and 0.0196 volts per ADC count is 4.704V.
I use STK 500 and my power supply to pot is a desk top PC power supply. It provide a very stable 5 V, actually 5.04 V as measured by multimeter.
You could bandaid it by making the modulus with a leading 0 and always two digits. It would then be a vague approximation of the true math.
I would implement that just for learning but my aim is accuracy and precision. Thanks
As was suggested, I tried to take several readings and then averged them. Wow!! the results as you see below vary wildly. I am not sure what is wrong or what am I doing wrong. Is the averaging method correct?
int ReadADC(void)
{
int i;
int tempADC = 0;
int tempADCH = 0;
ADCSRA |= (1 << ADSC); // Start A2D conversions
while(!(ADCSRA & (1<<ADIF))); // wait for conversion to complete
for (i=0;i<8; i++)
{
ADCSRA |= (1 << ADSC); // Start A2D conversions
while(!(ADCSRA & (1<<ADIF))); // wait for conversion to complete
//ADCSRA |= (1 << ADIF); // necessary ?
tempADC +=(ADCH << 8); // read ADCH register
// accumulate result, 8 readings for averaging
tempADCH += tempADC;
//ADCr = ADCr + ADC_temp;
}
tempADCH = tempADCH >> 3; // average the 8 readings
return(tempADCH);
}
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is 0.0 volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is 9.3 volts
The reading is 1.4 volts
The reading is 2.4 volts
The reading is -.- volts
The reading is 7.2 volts
The reading is 2.3 volts
The reading is 2.2 volts
The reading is 2.8 volts
The reading is 2.2 volts
The reading is 3.1 volts
The reading is 6.4 volts
The reading is 6.0 volts
The reading is 7.1 volts
The reading is 6.6 volts
The reading is 5.3 volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is 1.1 volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is 5.3 volts
The reading is 7.2 volts
The reading is -.- volts
The reading is 7.2 volts
The reading is -.- volts
The reading is 7.2 volts
The reading is -.- volts
The reading is -.- volts
The reading is -.- volts
The reading is 7.8 volts
The reading is -.- volts
The reading is 7.3 volts
The reading is 7.1 volts
The reading is 7.1 volts
The reading is -.0 volts
The reading is 7.1 volts