| 1 | /***************************************************************************//** |
| 2 | * @file AD5933.h |
| 3 | * @brief Header file of AD5933 Driver. |
| 4 | * @author DBogdan ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2012(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | ******************************************************************************** |
| 40 | * SVN Revision: $WCREV$ |
| 41 | *******************************************************************************/ |
| 42 | #ifndef __AD5933_H__ |
| 43 | #define __AD5933_H__ |
| 44 | |
| 45 | /******************************************************************************/ |
| 46 | /***************************** Include Files **********************************/ |
| 47 | /******************************************************************************/ |
| 48 | #include "Communication.h" |
| 49 | |
| 50 | /******************************************************************************/ |
| 51 | /************************** AD5933 Definitions ********************************/ |
| 52 | /******************************************************************************/ |
| 53 | |
| 54 | /* AD5933 Registers */ |
| 55 | #define AD5933_REG_CONTROL_HB 0x80 // HB of the Control register |
| 56 | #define AD5933_REG_CONTROL_LB 0x81 // LB of the Control register |
| 57 | #define AD5933_REG_FREQ_START 0x82 // Start frequency |
| 58 | #define AD5933_REG_FREQ_INC 0x85 // Frequency increment |
| 59 | #define AD5933_REG_INC_NUM 0x88 // Number of increments |
| 60 | #define AD5933_REG_SETTLING_CYCLES 0x8A // Number of settling time cycles |
| 61 | #define AD5933_REG_STATUS 0x8F // Status |
| 62 | #define AD5933_REG_TEMP_DATA 0x92 // Temperature data |
| 63 | #define AD5933_REG_REAL_DATA 0x94 // Real data |
| 64 | #define AD5933_REG_IMAG_DATA 0x96 // Imaginary data |
| 65 | |
| 66 | /* AD5933_REG_CONTROL_HB Bits */ |
| 67 | #define AD5933_CONTROL_FUNCTION(x) ((x) << 4) |
| 68 | #define AD5933_CONTROL_RANGE(x) ((x) << 1) |
| 69 | #define AD5933_CONTROL_PGA_GAIN(x) ((x) << 0) |
| 70 | |
| 71 | /* AD5933_REG_CONTROL_LB Bits */ |
| 72 | #define AD5933_CONTROL_RESET (0x1 << 4) |
| 73 | #define AD5933_CONTROL_INT_SYSCLK (0x0 << 3) |
| 74 | #define AD5933_CONTROL_EXT_SYSCLK (0x1 << 3) |
| 75 | |
| 76 | /* AD5933_CONTROL_FUNCTION(x) options */ |
| 77 | #define AD5933_FUNCTION_NOP 0x0 |
| 78 | #define AD5933_FUNCTION_INIT_START_FREQ 0x1 |
| 79 | #define AD5933_FUNCTION_START_SWEEP 0x2 |
| 80 | #define AD5933_FUNCTION_INC_FREQ 0x3 |
| 81 | #define AD5933_FUNCTION_REPEAT_FREQ 0x4 |
| 82 | #define AD5933_FUNCTION_MEASURE_TEMP 0x9 |
| 83 | #define AD5933_FUNCTION_POWER_DOWN 0xA |
| 84 | #define AD5933_FUNCTION_STANDBY 0xB |
| 85 | |
| 86 | /* AD5933_CONTROL_RANGE(x) options */ |
| 87 | #define AD5933_RANGE_2000mVpp 0x0 |
| 88 | #define AD5933_RANGE_200mVpp 0x1 |
| 89 | #define AD5933_RANGE_400mVpp 0x2 |
| 90 | #define AD5933_RANGE_1000mVpp 0x3 |
| 91 | |
| 92 | /* AD5933_CONTROL_PGA_GAIN(x) options */ |
| 93 | #define AD5933_GAIN_X5 0 |
| 94 | #define AD5933_GAIN_X1 1 |
| 95 | |
| 96 | /* AD5933_REG_STATUS Bits */ |
| 97 | #define AD5933_STAT_TEMP_VALID (0x1 << 0) |
| 98 | #define AD5933_STAT_DATA_VALID (0x1 << 1) |
| 99 | #define AD5933_STAT_SWEEP_DONE (0x1 << 2) |
| 100 | |
| 101 | /* AD5933 Address */ |
| 102 | #define AD5933_ADDRESS 0x0D |
| 103 | |
| 104 | /* AD5933 Block Commands */ |
| 105 | #define AD5933_BLOCK_WRITE 0xA0 |
| 106 | #define AD5933_BLOCK_READ 0xA1 |
| 107 | #define AD5933_ADDR_POINTER 0xB0 |
| 108 | |
| 109 | /* AD5933 Specifications */ |
| 110 | #define AD5933_INTERNAL_SYS_CLK 16000000ul // 16MHz |
| 111 | #define AD5933_MAX_INC_NUM 511 // Maximum increment number |
| 112 | |
| 113 | /******************************************************************************/ |
| 114 | /************************ Functions Declarations ******************************/ |
| 115 | /******************************************************************************/ |
| 116 | |
| 117 | /*! Initializes the communication peripheral. */ |
| 118 | char AD5933_Init(void); |
| 119 | |
| 120 | /*! Writes data into a register. */ |
| 121 | void AD5933_SetRegisterValue(unsigned char registerAddress, |
| 122 | unsigned long registerValue, |
| 123 | unsigned char bytesNumber); |
| 124 | |
| 125 | /*! Reads the value of a register. */ |
| 126 | unsigned long AD5933_GetRegisterValue(unsigned char registerAddress, |
| 127 | unsigned char bytesNumber); |
| 128 | |
| 129 | /*! Resets the device. */ |
| 130 | void AD5933_Reset(void); |
| 131 | |
| 132 | /*! Selects the source of the system clock. */ |
| 133 | void AD5933_SetSystemClk(char clkSource, unsigned long extClkFreq); |
| 134 | |
| 135 | /*! Selects the range and gain of the device. */ |
| 136 | void AD5933_SetRangeAndGain(char range, char gain); |
| 137 | |
| 138 | /*! Reads the temp. from the part and returns the data in degrees Celsius. */ |
| 139 | float AD5933_GetTemperature(void); |
| 140 | |
| 141 | /*! Configures the sweep parameters. */ |
| 142 | void AD5933_ConfigSweep(unsigned long startFreq, |
| 143 | unsigned long incFreq, |
| 144 | unsigned short incNum); |
| 145 | |
| 146 | /*! Starts the sweep operation. */ |
| 147 | void AD5933_StartSweep(void); |
| 148 | |
| 149 | /*! Reads the real and the imaginary data and calculates the Gain Factor. */ |
| 150 | double AD5933_CalculateGainFactor(unsigned long calibrationImpedance, |
| 151 | unsigned char freqFunction); |
| 152 | |
| 153 | /*! Reads the real and the imaginary data and calculates the Impedance. */ |
| 154 | double AD5933_CalculateImpedance(double gainFactor, |
| 155 | unsigned char freqFunction); |
| 156 | |
| 157 | #endif /* __AD5933_H__ */ |