• 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

Dear JColvin,

As I wrote you I am still unable to run Pseudo differential measurement.

I will be more then happy if you can sent me all the files including libraries  for Ardruino Uno so I will exclude misunderstandings.

Many thanks again

Yacov

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

In this post and the one immediately following you are not using the .ino file that you claimed since you are receiving the "ERROR - Invalid Averaging setting"; the new file would have changed the value provided from 100 to 0x3. (Plus you say that you are using Anne's files, so it's a bit confusing what is actually being done).

Based on the images attached to those two posts (not the one where you switch back to Anne's files) you appear to also be sometimes applying voltages to A3 and A4 rather than a voltage of 0.56V (how are you generating this?) to A6 and another wire to ACOM. What are you providing to ACOM?

I am working on testing this to see if I can get it working since I am otherwise receiving similar data (at least with the register read values and the Channel 6 data measurement). I will let you know if I find something helpful.

Thank you for your patience,
JColvin

Share this post


Link to post
Share on other sites
  • 0
52 minutes ago, JColvin said:

Hi @Yacov Cohen,

In this post and the one immediately following you are not using the .ino file that you claimed since you are receiving the "ERROR - Invalid Averaging setting"; the new file would have changed the value provided from 100 to 0x3. (Plus you say that you are using Anne's files, so it's a bit confusing what is actually being done).

Based on the images attached to those two posts (not the one where you switch back to Anne's files) you appear to also be sometimes applying voltages to A3 and A4 rather than a voltage of 0.56V (how are you generating this?) to A6 and another wire to ACOM. What are you providing to ACOM?

I am working on testing this to see if I can get it working since I am otherwise receiving similar data (at least with the register read values and the Channel 6 data measurement). I will let you know if I find something helpful.

Thank you for your patience,
JColvin

Acom is ground taken from J1. Placed 0.56 Volt between Acom and A6 but may be I played with the voltage. 

In any way I understand that you are still working on it.

I appreciate.

Share this post


Link to post
Share on other sites
  • 0
Just now, Yacov Cohen said:

Acom is ground taken from J1. Placed 0.56 Volt between Acom and A6 but may be I played with the voltage. 

In any way I understand that you are still working on it.

I appreciate.

AS A4 is still grounded so shorted to ACOM  I may connected between A4 and A6 a voltage  of aprox 0.56V

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

This is my most updated code set (the code is currently reading channel 2), though I am still trying to debug an issue. The issue I am experiencing is that upon starting the code the module seems to work correctly; i.e. the calibrate function calibrates the channel of interest and the first sample seems to accurately reflect the provided input (though not with as much accuracy I would expect).

However, any further samples taken do not reflect any changes and so far I have been unable to figure out why this is the case. The immediate thought would be that it's reporting an unchanging variable, but the code is setup so that it's a local variable that gets constructed, updated, reported, and then deconstructed each time through the loop, so that seems unlikely. I'll keep looking on another day when I have a can have a fresh look at the system.

Thanks,
JColvin

AD7193.cpp

AD7193.h

PsuedoDifferential.ino

Share this post


Link to post
Share on other sites
  • 0

Thank you very much for trying to solve the problem.

I would like to consider the use  of 2 Pmod5 cards in differential mode but chip select is set in AD7193.h .

Can you please help how to use 2 Pmod5 cards

Thanks

Yacov

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

The way you would do this would be to change the ReadRegisterValue and SetRegisterValue functions so that the final parameter in each of those functions (a manipulate CS parameter) be set to 0 rather than 1. This would force you to manually toggle the CS pin yourself which you then have more control over.

What I would probably do instead is change the begin function to then accept a parameter that ends up dictating what pin the CS pin is; you'll then be able to keep all of the other functions that use the Read / Set RegisterValue functions as is since it would automatically toggle the CS pin for you.

Generically the adjusted begin function would look like this:

bool AD7193::begin(int newCsPin) {
  SPI.begin();
  SPI.setDataMode(SPI_MODE3);
  SPI.setClockDivider(SPI_CLOCK_DIV16);

  AD7193_CS_PIN = newCsPin;

  pinMode(AD7193_CS_PIN, OUTPUT);
  delay(100);

  Reset();

}

Naturally you'll also need to change the begin function in the .h file to reflect this new parameter.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Dear JColvin,

I hope that you will find the time to take care on the issue we are handling as I need very much that option.

Do you think I can use your latest files?

Thanks very much.

 

Yacov

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

Unfortunately you have the latest files that I do as I have not had the opportunity to work on this further. Hopefully I will get a bit of time to work on it a bit more this week, but I will let you know when I have made some progress on it, though I cannot guarantee that I will have the time to do so.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Dear JColvin,

I am in a phase that I have to start to converge with our project. It is not convenient for me to have two 24 bit A to D Units. It concludes to a big change in price and reduces the total execution time.

Do you think that you can find the time to solve that issue?

Manny thanks

Yacov

 

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

Unfortunately, I have not had the opportunity to debug and solve the issue of getting continually updated data. I will see if I can get a demo that uses multiple inputs enabled and initiated this week, though I do not think I will be able to get the first problem resolved during that time.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Dear JColvin,

I hope that you will find the time to take care on the issue we are handling as I need very much that option.

 

Thanks very much.

 

Yacov

Share this post


Link to post
Share on other sites
  • 0

DearJjcolvin,

I bought a product I can not use as its not coming with a minimum option to use 8 inputs. The question please is if you can find the time to solve this issue. Please let me know if there is a chance  for digilentic to deliver a correct driver?

Thanks , Yacov

 

Share this post


Link to post
Share on other sites
  • 0

Hi @Yacov Cohen,

Unfortunately that is correct. I kept hoping that I would find time to be able to look into and debug this issue and be able to present a clean working project for the Pmod AD5. I did get it setup so that multiple AD5's could be used (by declaring different constructor name) in the same project.

I'm sorry I could not be of more help.

Thank you,
JColvin

AD7193.zip

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