• 0
Yacov Cohen

AD7193_VoltageMeasurePsuedoDifferential_Example published to work with PmodAd5

Question

The AD7193_VoltageMeasurePsuedoDifferential_Example Created 4 Oct 2016
by Anne Mahaffey and published as example for PmodAD5 has bugs. Unfortunately tried to set the bugs but got incorrect measurements.

Can you please help?

 

This is the script from the example from GitHub  :

/*

AD7193_VoltageMeasurePsuedoDifferential_Example

Configures and calibrates the AD7193 to measure psuedo-differential voltage on channel 6

Tutorial can be found at <TBD>, and uses the PmodAD5 from Digilent.

Signal Connections:
-----------------------------------------------------
 Signal Name |  PmodAD Pin  |  Arduino Pin
-----------------------------------------------------
  ~CS        |  J1, Pin 1   |  10
  MOSI       |  J1, Pin 2   |  MOSI or 11 or ICSP-4
  MISO       |  J1, Pin 3   |  MISO or 12 or ICSP-1
  SCLK       |  J1, Pin 4   |  SCLK or 13 or ICSP-3
  GND        |  J1, Pin 5   |  GND
  VCC (3.3V) |  J1, Pin 6   |  3.3V
-----------------------------------------------------

-----------------------------------
 Signal Name       |  PmodAD5 Pin   
-----------------------------------
 Channel 6 Pos     |  J2, Pin 7
 AINCOM            |  J2, Pin 9
-----------------------------------
See Table 24 of AD7193 datasheet for more information


Refer to:
https://reference.digilentinc.com/reference/pmod/pmodad5/start
https://www.arduino.cc/en/Reference/SPI

Created 4 Oct 2016
by Anne Mahaffey

This example code is in the public domain
*/

 

 

 

#include <SPI.h>
#include <AD7193.h>


AD7193 AD7193;

void setup() {
 
  ///////////////////////////
  // setup Serial and SPI
  ///////////////////////////
 
  Serial.begin(9600);
  delay(1000);
 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 
  AD7193.begin();

  ///////////////////////////////////
  // Device setup
  ///////////////////////////////////
 
  AD7193.AppendStatusValuetoData();  //This might be a requirement - functions will be simpler if I can assume this is true 
 
  AD7193.SetPGAGain(1);

  AD7193.SetAveraging(100);

  // sets input to measure across channel input and AINCOM pin
  AD7193.SetPsuedoDifferentialInputs();

  /////////////////////////////////////
  // Calibrate with given PGA settings - need to recalibrate if PGA setting is changed
  /////////////////////////////////////
 
  AD7193.Calibrate();

  // Debug - Check register map values
  AD7193.ReadRegisterMap();
 

  //////////////////////////////////////
 
  Serial.println("\nBegin AD7193 conversion - single conversion (pg 35 of datasheet, figure 25)");
}


void loop() {

  unsigned long ch6Data;
  float ch6Voltage;
 
  // Read channel measurement data
  ch6Data = (AD7193.ReadADCChannel(6) >> 8);

  Serial.print("  CH6 data: ");
  Serial.print(ch1Data, HEX);

  // Convert to voltage
  ch1Voltage = AD7193.DataToVoltage(ch6Data);
 
  Serial.print("\n\t\tChannel 1 Voltage Measurement: ");
  Serial.println(ch1Voltage, 3); 
  
  delay(100);
}

 

 

 

 

  

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0

Hi @Yacov Cohen,

I am not certain what the issue might be; I recall some of the libraries for the AD7193 having some bugs with regards to manipulating the registers correctly (and more importantly not having a way to adjust the polarity between unipolar and bipolar and a calculation error with regards to getting the data out of two's complement), so I think the libraries I have attached should address these issues based on some of the comments. Please note that these are unofficial libraries with no formal header or testing; when I tried it earlier the calibration didn't seem to work quite right, though admittedly I didn't have anything hooked up to the AD7193.

If I recall correctly, the code you posted above should all be compatible function name wise with these two files.

Let me know how this goes.

Thanks,
JColvin

 

AD7193.h

AD7193.cpp

Edited by JColvin

Share this post


Link to post
Share on other sites
  • 0

Dear JColvin

Used the files I got from U and the AD7193_VoltageMeasurePsuedoDifferential_Example Created 4 Oct 2016 by Anne (modified to exclude obvious bugs.

Still bad results. 
Till now I bought 5 units and can not use them in this mode.

Differential mode works good.

Many thanks for your efforts. Please advice

AD7193_VoltageMeasurePsuedoDifferential_Example.ino

AD7193.cpp

AD7193.h

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

I finally figured out the issue. The problem is that every function that sets a register value, including the calibrate function, pulls from the array of register map values that are globally declared at the top of the AD7193.cpp file, adjusts only the bits that the function needs to, and then applies the changes. The problem is that none of these functions read what the current state of the registers are (they all assume it is the default state), so each Calibrate, SetPsuedoDifferentialInputs, SetAveraging, etc., overwrite any and all previous changes.

What each function needs to do instead is to read the appropriate register directly from the chip, make changes to the bits of interest, then reapply the changes. This can be done with the GetRegisterValue function; I'll see if I can get that fixed tomorrow.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Hi  JColvin,

I wish you a new happy year.

I am curious (and I really need a solution for measuring more then 4 inputs) how is it going.

Thanks for working on it.

Yacov 

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Hi @Yacov Cohen,

I have attached the new files that I worked on; I believe the registers are all correctly manipulated now, though I changed a couple of functions to have them make more sense (like adding a boolean parameter for whether or not the pseudo bit is enabled. Let me know how it goes.

Thanks,
JColvin

AD7193_VoltageMeasurePsuedoDifferential_Example.ino

 

AD7193.h

AD7193.cpp

Edited by JColvin

Share this post


Link to post
Share on other sites
  • 0
Quote

In my first test I run it under a Mega card then I realized that I had to replace to Uno as you wrote it using CS 10. Unfortunately all the measurements are showing -2.5 V

Thank for taking care

  

 

Capture.PNG

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

Apparently I can't even select the correct library files; after double checking, these are the correct library files (as opposed to previous ones). I'll update the previous post as well to help prevent confusion.

I when I ran it on an Arduino Uno (rather than a Digilent uC32), I didn't get the registers to read back as expected, so I'll need to double check the SPI functions used since I remember some of them use manual CS line manipulation and others do it via the library functions.

Thanks,
JColvin

AD7193.cpp

AD7193.h

Share this post


Link to post
Share on other sites
  • 0

Hi JColvin,

Again thank you for working on this issue.

Tried to use the latest files you sent on Arduino Uno /Mega  without success.

Yacov

Capture34.PNG

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

Did you use the new .ino file that I had posted earlier? It adjusts the appropriate functions to match the new style of function (which requires a boolean parameter in the interest of making it so that you can enable or disable a bit in the device); I've adjusted the .h file so that it presumes a default parameter of true (which is what you would presumably do when calling the function anyway.

Thanks,
JColvin

AD7193.h

Share this post


Link to post
Share on other sites
  • 0

Hi,

Tried the new AD7193.h file on Arduino Uno.

Now the Differential Voltage and the Pseudo differential files are not Running.

Can you help?

Thanks

Yacov

 

 

Capture35.PNG

Capture36.PNG

Share this post


Link to post
Share on other sites
  • 0

Hi and thanks

In this run using : AD7193_VoltageMeasurePsuedoDifferential_Example.ino   Posted Friday at 08:21 PM (edited)

                               AD7193.cpp          Posted Tuesday at 01:00 AM

                               AD7193.h              Posted Tuesday at 10:10 PM

Now I am running the differential measurement placed by AnneCapture31.thumb.PNG.03448b673ec20bdca3458ee250a11bea.PNG

The input voltage is 0.56 Volt and it shows constant incorrect value

 

Capture30.PNG

Capture31.PNG

Capture30.PNG

Share this post


Link to post
Share on other sites
  • 0

In this run using : AD7193_VoltageMeasurePsuedoDifferential_Example.ino   Posted Friday at 08:21 PM (edited)

                               AD7193.cpp          Posted Tuesday at 01:00 AM

                               AD7193.h              Posted Tuesday at 10:10 PM

 

Capture32.PNG

Capture33.PNG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now