Git Product home page Git Product logo

arduino-ad5933's Introduction

AD5933 Arduino Library

This is a simple library for using the AD5933 impedance convert system with an Arduino compatible device.

AD5933

The AD5933 is developed by Analog Devices. From the AD5933 page:

The AD5933 is a high precision impedance converter system solution that combines an on-board frequency generator with a 12-bit, 1 MSPS, analog-to-digital converter (ADC). The frequency generator allows an external complex impedance to be excited with a known frequency. The response signal from the impedance is sampled by the on-board ADC and a discrete Fourier transform (DFT) is processed by an on-board DSP engine. The DFT algorithm returns a real (R) and imaginary (I) data-word at each output frequency.

Once calibrated, the magnitude of the impedance and relative phase of the impedance at each frequency point along the sweep is easily calculated. This is done off chip using the real and imaginary register contents, which can be read from the serial I2C interface.

In other words, the AD5933 lets you measure the complex impedance of something.

Library

Compatibility

This library should be compatible with any Arduino compatible device, albeit perhaps with some changes. It was developed and tested with an RFduino, but I do not see a reason why it would not work with a regular Arduino.

Missing Features

While the library is enough to get impedance readings, I must admit that it is somewhat incomplete. The following features are yet to be implemented (and likely will not be implemented by me):

  • Configure the AD5933 excitation range
  • When performing calibration, calibrate the phase such that the phase of impedance readings can be analyzed

Installation

Simply move the entire folder arduino-ad5933 to your Arduino/libraries folder, usually in your home directory or documents folder.

Usage

Example

Perhaps the easiest way to see how to use the library is to look at the example code in the examples directory. Once you install the library, you can easily open this code in the Arduino editor by going to File > Examples > arduino-ad5933 > ad5933-test.

This example will show you how to initially setup the AD5933 and run frequency sweeps. There are two methods for doing a frequency sweep. The first is by using the frequencySweep() function. This function is very easy to use, but you have to wait until the entire sweep is complete before handling data in bulk and this requires more memory, especially for large sweeps. The other method is by manipulating the AD5933 at the I2C level directly, which is slightly more complex, but allows you to handle data immediately after a reading and has significantly lower memory overhead.

Brief Overview

There are an assortment of functions in AD5933.h that can be used with numerous constants. Each one of the functions are static, so be sure to include AD5933:: in front. Here I cover a few of the main ones.

NOTE: Many of these functions return booleans indicating their success. This may be useful for debugging.

To reset the board: AD5933::reset();

To enable on-board temperature measurement: AD5933::enableTemperature()

To get a temperature reading: double temp = AD5933::getTemperature()

To set the clock source to internal: AD5933::setInternalClock(true) OR AD5933::setClockSource(CTRL_CLOCK_INTERNAL)

To set the clock source to external: AD5933::setClockSource(CTRL_CLOCK_EXTERNAL)

To set the frequency sweep start frequency: AD5933::setStartFrequency(#)

To set the frequency sweep increment frequency: AD5933::setIncrementFrequency(#)

To set the frequency sweep number of increments: AD5933::setNumberIncrements(#)

To set the PGA gain: AD5933::setPGAGain(PGA_GAIN_X1/PGA_GAIN_X5)

To set the power mode: AD5933:setPowerMode(POWER_ON/POWER_DOWN/POWER_STANDBY)

To perform a calibration sweep, which computes gain factor for each frequency step based on a known reference resistance (the results are stored in the gainFactor array, so make sure this is large enough): AD5933::calibration(double[] gainFactor, double[] phase, int referenceResistor, int numIncrements)

To perform an entire frequency sweep (the results are stored in the real and imaginary arrays): AD5933::frequencySweep(int[] real, int[] imag, int numIncrements)

To read a register: byte res = AD5933::readRegister(/* register address */)

That is sufficient for most things. Check out the header file for more functions and constants. Also check out the example code for better illustrations of usage.

Reference

A lot of code was reference from this GitHub repo. I made a fair amount of modifications, but the repo can also probably be used for additional sample code if needed.

arduino-ad5933's People

Contributors

ankitemb avatar jhschwartz avatar mjmeli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-ad5933's Issues

Any chance of an open-source license?

Any chance of posting a clear open-source license for this code? (Please point me to it if I somehow missed it.)

I know that the default of GetGub allows for forking projects, the GetHub ToS could be taken as an implicit license for any posted code, and that most people would rather not deal with this sort of thing. However, I would like to use a modified version of this code in my masters thesis. And, in short, if I modify it, I have to include it in the published thesis, and I have to receive copyright permission both to use it in the thesis, modify it, and to republish it. Worst case, I could just rewrite the thing, but I would rather not waste time rewriting it from the datasheet. An open-source licence tied to the project is an easy way to go, though I am open to discussing other options. Also, if you want a copy of the modified code, I am happy to send it over once it is finished. I will be publishing it, after all....

Thank you!

WolvesOfTheNight

Excitation Voltage Output

How to define macros for excitation voltage output. I am using AD5933 for impedance measurement .But i did not known how to set the excitation voltage value .
arduino-ad5933-master.zip
This is code i upload.Please tell me the correct place to include excitation voltage macro and its functions.

Possible to program entire control register in one go?

Wondering if there is something I am missing with regards to programming the control register. This implementation seems to separate each control register function which may be useful for readability, but requires multiple exchanges to be made between the AD5933 and uController. Wouldn't it be more efficient to set everything up first, then write a single time to the device control registers? I.e.:

bool AD5933::setControlRegisters(byte reg1, byte reg2){ if(!sendByte(CTRL_REG1,reg1)) return false; else return sendByte(CTRL_REG2,reg2); }

Where you first ensure reg1 and reg2 are properly set?

Arduino Due Compatability

Hello,

I'm running an arduino due on the AD5933 dev board. It seems that i2c communication doesn't quite transmit, would there happen to be a fix for this?

Power Standby failed

Hello,

My code is printing that it cannot do the frequency sweep because it failed the power standby. I have split out where the error codes are in the test files and it fails in initialization. Some insight on this issue would be much appreciated!

AD5933 to measure change in impedance

Dear Experts,

I am trying to measure change in dielectric property (degradation of vegetable oil) by measuring the impedance using a simple parallel plate capacitor. The expectation is that the real and imaginarychange as the the oil degrades with temperature. This is continuously monitored over time.

I first need to find an optimum frequency (which i kinda know based on earlier literature) and continuously monitor the changes in complex impedance at that optimum frequency and display real and imaginary values (intend to use arduino with AD5933). How can i modify this code to achieve that?

If i understand correctly, i need to use frequencySweepEasy(); or frequencySweepRaw(); and not both- is that right?

What if i dont want to perform a sweep everytime and rather find img and real values at a fixed frequency? Is this possible? or do i need to perform a frequency sweep everytime?

Being a mechanical engineer, I'm not much of an expert in this regard.

Any help would be much appreciated.

Regards,

AdzTheDemon.

impedance measurement is not accurate

Hello sir
Thank you for your work sir, I have used your code sample sir.
I carried out impedance measurements with Rcal 10kohm and the results showed an accurate 10kohm, but when I took measurements on different resistors the results were far from accurate.
my example measured a 200kohm resistor but the results showed around 20kohm.
so how to solve this sir?

Calibrate function Problem

Dear Experts,
Thank you for you work. This library works very reliably for us.
We would like to make a small change though to the function to adapt it to our needs. We want to link the calibration to one button and the measurement to another.
So we entered the calibration code in the loop (using an “if loop“ ) linked to the state of the first button.
To carry out the measurement with the functions FrequencySweepEasy and FrequancySweepRaw, we used another “if loop” in the loop (sorry for this play on words) connected to the state of the second button. Up to here everything works!!
Since we need to display an average of the measurements of impedance we make, we tried to modify one of the two functions (FrequencySweepEasy) by making it return a value.
The code compiles but stops at the calibration step! Someone could tell me why?
Any help would be much appreciated.
Regards,
Stefania

FAILED initialization

After uploading the code to an Arduino UNO, Started appears in the serial monitor shortly after which FAILED Initialization appears. I can't understand where the error is.

Has anyone implemented a phase measurement yet?

First of all, thank the author for sharing.
Has anyone figured out the phase? The true resistance and reactance values cannot be calculated without calculating the phase.
I tried several methods, but none of them worked out the phase.

cant run the code

dear experts,
i have connected and ran the code. in the serial plotter, it showed "AD5933 test start!" and nothing else shown in the serial plotter. is that anything wrong?
thanks.
i am so sorry, i am quite new with arduino and AD5933 in general. thanks.

Can not find Math.h

While trying to verify the ad5933-test, having the following error message.

AD5933.cpp:12:18: error: Math.h: No such file or directory
Multiple libraries were found for "Wire.h"
 #include <Math.h>
 Used: /root/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire
                  ^
compilation terminated.
exit status 1
Math.h: No such file or directory

Ubuntu 18.04
Arduino 1.8.10

Similar issue

Suggest to change #include <Math.h> to #include <math.h>

Connecting external clock

Hi, is there any code modification required to connect external clock from function generator?
In terms of code, I have change to AD5933::setInternalClock(false).
In terms of hardware, I removed the LK3 connection and connect LK4.
With these changes, the code doesnt run, please advise what is the correct steps to connect external clock.
Thank you.

The sweep frequency is not correct

I think you did everything right based on the datasheet but when I tried to send 1kHz to the Vout it is actually not 1kHz. I am not sure whether it is a problem with my setup or something is wrong in the datasheet. I changed the start frequency code equation and now it works.

"getComplexData" needs a time-out safety

Dear author:

Thank you for you work. This library works very reliably for us. We did have to make a small change though to the function "getComplexData". The while-loop in there may hang and the function may run indefinitely.

We changed the code around the while loop waiting for the STATUS_DATA_VALID as follows:

bool AD5933::getComplexData(int *real, int *imag) {
// ako, 2021-02-09: this while loop may hang! --> return if max requests exceeded
// Wait for a measurement to be available
int maxLoops = 1000;
while ((readStatusRegister() & STATUS_DATA_VALID) != STATUS_DATA_VALID) {
if(maxLoops > 0){
maxLoops--;
delay(1);
}
else
{
// timeout
*real = -1;
*imag = -1;
return false;
}
}
...

Would you consider incorporating this into the official release?
Best regards,
Adrian

SWEEP_DELAY

I'm trying to get the AD5933 working with an external clock to measure impedance with frequencies from 10Hz to 1kHz, how can I use the SWEEP_DELAY constant?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.