Arduino PC8591 Differential Measurement Tutorial

Making a Measurement Without a Ground

Arduino PCF8591 Differential Measurements TutorialWhen we measure a voltage we measure the difference in electrical potential between two points.   Using the Arduino analog input pins, that measurement is made by measuring difference between the ground provided to the Arduino and the Arduino Analog input pin.   This presents a problem.

Specifically you cannot make a direct measurement when neither of the points is at the Arduino ground potential.

One way to overcome this obstacle is to use a PCF8591.

RELATED ARTICLES

Arduino PCF8591 Simple Voltage Measurement shows how to make a basic voltage measurement.

Arduino PCF8591 Digital to Analog Tutorial  Shows how to create a programmable voltage output.

Finding One

Its available at any of the following locations…

eBay     Amazon      Deal Extreme      Bang Good     IC Station

Single Ended vs Differential Measurement

Arduino Single Ended Measurement

Take a look at the illustration below.   Suppose you are interested in measuring a voltage across R2.   This does not represent much of a problem, because the analog measurement on the Arduino measures the difference between the input pin and the ground you supplied to it.

Arduino Single Sided Measurement

Arduino Differential Measurement

Now lets change things up.  Suppose you are interested in the voltage dropped across R1.   You might be tempted to make connections that look something like this ( don’t do it).   If you study the schematic,  you’ll see that what you’ve basically done is put the entire 5 volts supply across R1.

If you manage not to fry something in your circuit or your Arduino, the only thing you will do is measure 5 volts across a resistance in a circuit that is no longer functioning correctly.

Arduino Differential Measurements

Making the Differential Measurement Using PCF8591

PCF8591 Measurement Modes

There are four analog inputs to a PCF8591.  PCF8591 Pin Outs

These four analog inputs can be configured programmatically via your Arduino to provide four measurement modes.  This setup is normally established in your Arduino set up routine.

These measurement modes are as follows:

1) Four Single Ended Inputs.

2) Three Differential Inputs

3) Two Single Ended and One Differential Input

4) Two Differential Inputs

PCF8591 Two Differential Input Mode

Since the focus of this tutorial is to simply make a basic differential measurement,  we will focus on the two differential input mode.  Specifically, we will make a measurement between the AINO and the AIN1 inputs to the PCF8591.

When implemented in an Arduino environment,  the connections will look something like this.

PCF8591 Two Differential Input Mode

The illustration below provides another view that gives a very simplified look at what is going on.   The key thing to understand is that AIN1 ( or pin2 ) has a degree of isolation from ground.

PCF8591 Two Differential Input Mode View 2

Arduino PCF8591 Differential Measurement Tutorial

Create the Tutorial Test Circuit

The circuit we’re going to use is what we’re describing above.  We’re just going to clutter it up a bit with connections that add a little bit more reliability to measurement we wish to make.

Arduino PCF8591 Differential Measurement Tutorial Hook UpCopy, Paste and Upload the Tutorial Sketch

The sketch below sets the control byte in the set up.

// Henry's Bench
// PCF8591 Simple Differential Measurement
// Making Measurement where there is no 'Ground'

#include "Wire.h"
#define PCF8591 (0x90 >> 1) 



int RawValue = 0;
float Voltage = 0.0;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Wire.beginTransmission(PCF8591); // Start your PCF8591
  //Set the Control Byte
  Wire.write(0x11); // Set to two differential input mode 
  Wire.endTransmission(); //
}
void loop()
{
  Wire.requestFrom(PCF8591, 1); // Get the Measured Data from channel 1

 RawValue=Wire.read();
 Voltage = (RawValue * 5.0 )/ 255.0;
 Serial.print("Raw ADC Value = ");
 Serial.print(RawValue);
 Serial.print("\tVoltage = ");
 Serial.println(Voltage,3);
 Serial.println();
 delay(500);


}

Verify the Tutorial Output

Our voltage divider basically halves the 5V output.   That said, don’t expect to get a perfect 2.5 volt indication.  There are a bunch of reasons for this that include the accuracy of the five volt supply, the resolution of the AD converter, its accuracy and even the tolerance of the resistors you select.  However, you will get close.

Arduino PCF8591 Differential Measurement Tutorial Output