Hello mgirdner,
Your readings are correct. Te full scale of the ADC is 5V(1024) -> 30,30mA. You can increment the maximun channel current to 30,30mA. At 20mA the voltage in the adc is Vadc=R * 20mA= 165 *0,02=3V3. This means that at 20mA the ADC reads 3,3/5*1024 = 675,84.
This over current full scale is for 3V3 boards compatibility.
You can improve the precision adjusting the end scale to 20mA in two ways:
1.- Working with an arduino 3V3 board.
2.- Giving an external reference of 3V3 to the arduino AREF pin and merge this line in your code:
Code:
analogReference(EXTERNAL);
and modify the readVoltage() procedure to:
Code:
float currentLoop::readVoltage(uint8_t channel)
{
return (readChannel(channel) * 3.3 /1023);
}
Check this URL:
https://www.arduino.cc/en/Reference/AnalogReferenceRegards.