| 1 | /***************************************************************************//** |
| 2 | * @file AD5933.h |
| 3 | * @brief Header File for AD5933 Driver. |
| 4 | * @author ATofan ([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 | |
| 43 | #ifndef _AD5933_H_ |
| 44 | #define _AD5933_H_ |
| 45 | |
| 46 | /*****************************************************************************/ |
| 47 | /***************************** Include Files *********************************/ |
| 48 | /*****************************************************************************/ |
| 49 | #include "xil_types.h" |
| 50 | #include "xparameters.h" |
| 51 | |
| 52 | /*****************************************************************************/ |
| 53 | /******************* ADP5589 Registers Definitions ***************************/ |
| 54 | /*****************************************************************************/ |
| 55 | // AD5933 IIC Address |
| 56 | #define I2C_BASEADDR XPAR_AXI_IIC_1_BASEADDR |
| 57 | #define AD5933_I2C_ADDR 0x0D |
| 58 | // Registers Address |
| 59 | #define AD5933_CONTROL_REG_HB 0x80 |
| 60 | #define AD5933_CONTROL_REG_LB 0x81 |
| 61 | #define AD5933_START_FREQ_REG_HB 0x82 |
| 62 | #define AD5933_START_FREQ_REG_MB 0x83 |
| 63 | #define AD5933_START_FREQ_REG_LB 0x84 |
| 64 | #define AD5933_FREQ_INCR_REG_HB 0x85 |
| 65 | #define AD5933_FREQ_INCR_REG_MB 0x86 |
| 66 | #define AD5933_FREQ_INCR_REG_LB 0x87 |
| 67 | #define AD5933_NR_INCR_REG_HB 0x88 |
| 68 | #define AD5933_NR_INCR_REG_LB 0x89 |
| 69 | #define AD5933_NR_SETTLE_REG_HB 0x8A |
| 70 | #define AD5933_NR_SETTLE_REG_LB 0x8B |
| 71 | #define AD5933_STATUS_REG 0x8F |
| 72 | #define AD5933_TEMP_REG_HB 0x92 |
| 73 | #define AD5933_TEMP_REG_LB 0x93 |
| 74 | #define AD5933_REAL_REG_HB 0x94 |
| 75 | #define AD5933_REAL_REG_LB 0x95 |
| 76 | #define AD5933_IMG_REG_HB 0x96 |
| 77 | #define AD5933_IMG_REG_LB 0x97 |
| 78 | |
| 79 | /*****************************************************************************/ |
| 80 | /******************* ADP5589 Registers Bits **********************************/ |
| 81 | /*****************************************************************************/ |
| 82 | // Control Register High Bits 0x80 |
| 83 | #define AD5933_CONTROL_FUNCTION(x) ((x) << 4) |
| 84 | // AD5933_CONTROL_FUNCTION(x) options |
| 85 | #define AD5933_INIT_START_FREQ 0x01 |
| 86 | #define AD5933_START_FREQ_SWEEP 0x02 |
| 87 | #define AD5933_INCR_FREQ 0x03 |
| 88 | #define AD5933_REPEAT_FREQ 0x04 |
| 89 | #define AD5933_MEAS_TEMP 0x09 |
| 90 | #define AD5933_POWER_DOWN 0x0A |
| 91 | #define AD5933_STANDBY 0x0B |
| 92 | |
| 93 | #define AD5933_CONTROL_RANGE(x) ((x) << 1) |
| 94 | // AD5933_CONTROL_RANGE(x) options |
| 95 | #define AD5933_2Vpp_RANGE 0x00 |
| 96 | #define AD5933_200mVpp_RANGE 0x01 |
| 97 | #define AD5933_400mVpp_RANGE 0x02 |
| 98 | #define AD5933_1Vpp_RANGE 0x03 |
| 99 | |
| 100 | #define AD5933_PGA_GAIN(x) ((x) << 0) |
| 101 | // AD5933_PGA_GAIN(x) options |
| 102 | #define AD5933_PGA_GAIN_X5 0x00 |
| 103 | #define AD5933_PGA_GAIN_X1 0x01 |
| 104 | |
| 105 | // Control Register Low Bits 0x81 |
| 106 | #define AD5933_RESET (1 << 4) |
| 107 | #define AD5933_INT_CLK (0 << 3) |
| 108 | #define AD5933_EXT_CLK (1 << 3) |
| 109 | |
| 110 | // Status Register 0x8F |
| 111 | #define AD5933_STATUS_TEMP_VALID 1 |
| 112 | #define AD5933_STATUS_DATA_VALID (1 << 1) |
| 113 | #define AD5933_STATUS_SWEEP_DONE (1 << 2) |
| 114 | |
| 115 | /*****************************************************************************/ |
| 116 | /**************************** Command Codes **********************************/ |
| 117 | /*****************************************************************************/ |
| 118 | #define AD5933_BLOCK_WRITE 0xA0 |
| 119 | #define AD5933_BLOCK_READ 0xA1 |
| 120 | #define AD5933_ADDR_POINTER 0xB0 |
| 121 | |
| 122 | /*****************************************************************************/ |
| 123 | /************************ Functions Declarations *****************************/ |
| 124 | /*****************************************************************************/ |
| 125 | void AD5933_SetRegisterValue(int registerAddress, |
| 126 | int registerValue, |
| 127 | char numberOfBytes); |
| 128 | int AD5933_GetRegisterValue(int registerAddress, |
| 129 | char numberOfBytes); |
| 130 | int AD5933_GetTemperature(void); |
| 131 | void AD5933_ConfigSweep(int startFreq, |
| 132 | int incSteps, |
| 133 | int incFreq); |
| 134 | void AD5933_StartSweep(void); |
| 135 | double AD5933_CalculateGainFactor(unsigned long calibrationImpedance, |
| 136 | char freqFunction); |
| 137 | double AD5933_CalculateImpedance(double gainFactor, |
| 138 | char freqFunction); |
| 139 | #endif // _AD5933_H_ |
| 140 |