vcc corrected max471

I’ve a max471 based voltage/current measurement module from ebay.

It’s very straightforward to use it…snap in, measure the 2 AD outputs.

But on my desk I power the arduino appliances driectly from usb. And for some reason, I only got 4.6 or 4.7 volts(i’m using some cheap hub). But having lower voltage does matter in this case, because the max471 communicates in analog form.

I’ve tried this module earlier and I concluded that the max471 is precise; and works up to specs returning analog values - but I’m not really able to read the correct value; because of the lower VCC voltage.

I’ve found some site containing info about measuring the chip’s own VCC(builtin voltmeter works on atmega328p]

And i’ve said…okay..then I may be able to correct the mistake by correcting the measurement with the vcc level.

I’ve taken a simple sample code for max471 from site

…and brewed my vcc corrected version:

#include "Arduino.h"

#define VT_PIN A1
#define AT_PIN A0

void setup() {

 * 	returns	vcc estimation
float readVCC() {
	long result; // Read 1.1V reference against AVcc
	ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
	delay(2); // Wait for Vref to settle
	ADCSRA |= _BV(ADSC); // Convert
	while (bit_is_set(ADCSRA,ADSC));
	result = ADCL;
	result |= ADCH<<8;
//	result = 1125300L / result; // Back-calculate AVcc in mV 1.1*1023*1000
	return 1.1*1023/result;

void loop() {
	int vt_read = analogRead(VT_PIN);
	int at_read = analogRead(AT_PIN);
	float	vcc = readVCC();

	float voltage = vt_read * (vcc / 1023.0) * 5.0;
	float current = at_read * (vcc / 1023.0);

	float watts = voltage * current;

	Serial.print("VCC: ");
	Serial.print("\tVolts: ");
	Serial.print(voltage, 3);
	Serial.print("\tAmps: ");
	Serial.print(current, 3);
	Serial.print("\tWatts: ");
	Serial.println(watts, 3);


Turns out this little hack can improve the accuracy of the measurement…but it doesn’t measure VCC correctly… it reads 4.75 volts, when VCC is about 4.65..that’s a 2% error…this error is directly reflected on the max471 measurements 12.621 instead 12.41…but it’s a bit better than before.

At least now I know, that for reliable AD measurements i should use linear regulators ;)

Another intresting feature of the 328P series: a builtin thermal sensor

comments powered by Disqus