AD5933 Arduino Library Functions - WuMRC/drive GitHub Wiki

Note: Unless noted otherwise, the bool type function returns true if the operation succeed, returns false if failed.
Note: Currently, Logging Feature is disabled, and DO NOT USE THIS. (due to the recent bugs)

##### **Note: This documentation is not current, not reflecting recent changes.**

a. getTemperature()
This function just returns temperature measurement. The return type is double.
Note: To update temperature information only, try tempUpdate()

Declaration

double AD5933_Class::getTemperature()

Usage Example

AD5933.getTemperature();
varTemp = AD5933.getTemperature();

b. **getMagOnce()**
The function to get the magnitude of impedance once. This function does not control the chip, so users should control the chip manually to use this function. (See Datasheet to learn how to control the chip by writing control register and using setCtrMode function.) Using other functions is recommended to perform frequency sweep or to get Gain Factor(getGainFactor).

Declaration

double AD5933_Class::getMagOnce()

Usage Example

AD5933.getMagOnce();
varTemp = AD5933.getMagOnce();

c. **setStartFreq(long)**
This function can set the start frequency of frequency sweep. The scale of the frequency is Hz. Internally, the frequency is converted into hexadecimal number with different scale. Thus, actual start frequency is different from the frequency specified. This function should be recalled if the internal/external clock rate is changed.

Declaration

bool AD5933_Class::setStartFreq(long startFreq)

long startFreq - This input takes start frequency for frequency sweep in long integer type.

Usage Example

AD5933.setStartFreq(50000);
varTemp = AD5933.setStartFreq(10000000);

d. **setIncrement()**
Function to set the value of increment frequency. Internally, the frequency is converted into hexadecimal number with different scale. Thus, actual increment frequency is different from the frequency specified. This function should be recalled if the internal/external clock rate is changed.

Declaration

bool AD5933_Class::setIncrement(long increment)

long increment - This input takes increment frequency for frequency sweep in long integer type. The scale is Hz.

Usage Example

AD5933.setIncrement(500);
varFlag = AD5933.setIncrement(10000);

e. **setIncrementinHex()**
Function to set the hexadecimal value of increment frequency. One in hexadecimal magnitude corresponds unique amount of frequency calculated with the clock frequency of AD5933. This function should be recalled if the internal/external clock rate is changed.

Declaration

bool AD5933_Class::setIncrementinHex(long freqHex)

long freqHex - This input takes increment frequency in uniquely scaled hexadecimal value for frequency sweep in long integer type. One in 'freqHex' is not 1Hz.

Usage Example

AD5933.setIncrementinHex(0x1a);
varFlag = AD5933.setIncrementinHex(1);

f. **setNumofIncrement()**
The function to set number of incrementing sweeping frequency. In other words, this function can set how many times the chip increment the frequency during the frequency sweep.

Declaration

bool AD5933_Class::setNumofIncrement(int num)

int num - This input takes the number of increment.

Usage Example

AD5933.setNumofIncrement(10);
varFlag = AD5933.setNumofIncrement(2);

g. **setSettlingCycles(int, byte)**
Function to set settling cycles. User also choose the multiplier of settling cycles. Number of settling cycles multiplied by the multiplier determines the delay before the ADC(Analog-Digital Converter) operates.

Declaration

bool AD5933_Class::setSettlingCycles(int cycles, byte mult)

int cycles - Takes number of cycles to settle.
byte mult - Takes the value of multiplier.

Usage Example

AD5933.setSettlingCycles(100,1);
boolean varBool = AD5933.setSettlingCycles(200,4);

h. **resetAD5933()**
Function to reset AD5933 chip.

Declaration

bool AD5933_Class::resetAD5933()

Usage Example

AD5933.resetAD5933();
boolean varBool = AD5933.resetAD5933();

i. **setExtClock(bool)**
The function to enable/disable external clock.
**Note:** It is recommended to execute this function in setup() to clearify.

Declaration

bool AD5933_Class::setExtClock(bool swt)

bool swt - Boolean type variable to set enable/disable external or internal clock of AD5933.

Value Description
true Set to use external clock.
false Set to use internal clock. (16.776Mhz)

Usage Example

AD5933.setExtClock(true);
boolean varBool = setExtClock(false);

j. **setVolPGA(byte, byte)**
Function to set sweeping voltage and PGA Gain.

Declaration

bool AD5933_Class::setVolPGA(byte voltageNum, byte pgaGain)

byte voltageNum - Takes numbers uniquely assigned to each voltage.

Value Voltage Amplitude
0 2.0 Vpp
1 200 mVpp
2 400 mVpp
3 1.0 mVpp

Note1: They are typical values with 3.3V power supply. See Figure 4-10 in datasheet.

Note2: Vpp means 'Volt Peak to Peak'.

Note3: It print out error and return false if other number is on the input.

byte pgaGain - Takes PGA Gain multiplier.

Value Multiplier
1 x1
5 x5


Note3: It print out error and return false if other number is on the input.

Usage Example

AD5933.setVolPGA(1,5);
boolean varBool = setVolPGA(4,1);

k. **setCtrMode()**
It has two forms of input. Programmers can use first form mostly, but you can use second form if you want to reduce communication workload and have up-to-date register value of control register.
**Caution!** Improper sequence of modifying control mode result in malfunction or bug. Please read the datasheet carefully! (Fig 28, Page 22/40)

Declaration

bool AD5933_Class::setCtrMode(byte modetoSet)
bool AD5933_Class::setCtrMode(byte modetoSet, int ctrReg)

byte modetoSet - To set the mode to operate AD5933. You can choose one of those below to type in.

Flags Function
INIT_START_FREQ Initialize with Start Frequency
START_FREQ_SWEEP Start Frequency Sweep
INCR_FREQ Increment Frequency to measure
REPEAT_FREQ Repeat measurement in same frequency
POWER_DOWN into Power-Down Mode
STAND_BY into Stand-By Mode
TEMP_MEASURE Measure Temperature (whether the power is on or not)
For detailed instruction, please refer to the datasheet.

int ctrReg (optional) - To minimize I2C transmission workload, programmer can input the current status of control register (0x80). The control register value with up-to-date status must be allowed!

Use Example

AD5933.setCtrMode(INIT_START_FREQ);
AD5933.setCtrMode(TEMP_MEASURE, controlReg);  

l. **getGainFactor()**
Function to get Gain Factor by measuring the magnitude once. It has two forms of inputs.
**Note1:** The gain factor in this library is a inverse value (reciprocal value)
**Note2:** This function internally set the status into "Standby" Mode after the execution. Modifying the mode to perform any measurement should be done in sequence as described in datasheet.(Refer Fig 28, Page 22/40)

Declaration

double AD5933_Class::getGainFactor(double cResistance)
double AD5933_Class::getGainFactor(double cResistance, int avgNum)
double AD5933_Class::getGainFactor(double cResistance, int avgNum, bool retStandBy)

double cResistance - Takes the calibration resistance. There is a special equation to calculate optimal amount of calibration resistance in AN-1252 from Analog Inc.
int avgNum (optional) - Takes the number for averaging. The function averages measurement of specified times from this variable. Default value is 1.
bool retStandBy (optional) - Takes the boolean value whether this function turn the mode into Stand_By and reset the AD5933 chip.

Usage Example

gainFactor1 = AD5933.getGainFactor(2000,4);
gainFactor2 = AD5933.getGainFactor(4700);
gainFactor3 = AD5933.getGainFactor(4700,10,false);

m. **performFreqSweep(double, double *)**
Function to perform frequency sweep.

Declaration

bool AD5933_Class::performFreqSweep(double gainFactor, double *arrSave)

double gainFactor - Insert the variable returned from getGainFactor(). Putting arbitrary value defined by user is not recommended.
*double arrSave - Put the name of double-typed array for saving impedance magnitudes. The size should match the number of increment value.

Usage Example

...
double gainFactor, saveImp[10];
...
AD5933.performFreqSweep(gainFactor,saveImp);
boolean flag1 = AD5933.performFreqSweep(gainFactor,saveImp); 

n. **getByte(int)**
Function to get the value of register.

Declaration

int AD5933_Class::getByte(int address)

int address - Takes the address of register to read.

Usage Example

int regVal = getByte(0x80);
int regVal2 = getByte(0x8F);

o. **setByte(int, int)**
Function to set the value of register.
**Note:** Please be careful to use this function. This function access the register directly. Improper register value results in bug or malfunction of the AD5933 chip. **Read the datasheet carefully to use this funtion.**

Declaration

bool AD5933_Class::setByte(int address, int value)

int address - Takes the address of register to read.
int value - Takes the value to set.

Usage Example

boolean val = AD5933.setByte(0x80, ctrRegVal);
boolean val2 = AD5933.setByte(0x81, 0x00);

p. **tempUpdate()**
Function to update temperature information inside the AD5933 chip without reading temperature information.
**Note: It is recommended to update the temperature information frequently to measure accurately.**

Declaration

bool AD5933_Class::tempUpdate()

Usage Example

boolean val = AD5933.tempUpdate();
AD5933.tempUpdate();

⚠️ **GitHub.com Fallback** ⚠️