Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
AD7190.h
00001 00002 /***************************************************************************//** 00003 * @file AD7190.h 00004 * @brief Header file of AD7190 Driver. 00005 * @author DNechita (Dan.Nechita@analog.com) 00006 ******************************************************************************** 00007 * Copyright 2012(c) Analog Devices, Inc. 00008 * 00009 * All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are met: 00013 * - Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * - Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * - Neither the name of Analog Devices, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * - The use of this software may or may not infringe the patent rights 00023 * of one or more patent holders. This license does not release you 00024 * from the requirement that you obtain separate licenses from these 00025 * patent holders to use this software. 00026 * - Use of the software either in source or binary form, must be run 00027 * on or directly connected to an Analog Devices Inc. component. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00030 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00031 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00032 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00033 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00034 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00035 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00036 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00037 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00038 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 * 00040 ******************************************************************************** 00041 * SVN Revision: 903 00042 *******************************************************************************/ 00043 00044 #ifndef __AD7190_H__ 00045 #define __AD7190_H__ 00046 00047 /******************************************************************************/ 00048 /***************************** Include Files **********************************/ 00049 /******************************************************************************/ 00050 00051 00052 00053 #include "Communication.h" 00054 #include "mbed.h" 00055 00056 00057 extern DigitalOut cs; 00058 extern DigitalIn ad_rdy; 00059 /******************************************************************************/ 00060 /******************************** AD7190 **************************************/ 00061 /******************************************************************************/ 00062 00063 00064 /* AD7190 Register Map */ 00065 #define AD7190_REG_COMM 0 // Communications Register (WO, 8-bit) 00066 #define AD7190_REG_STAT 0 // Status Register (RO, 8-bit) 00067 #define AD7190_REG_MODE 1 // Mode Register (RW, 24-bit 00068 #define AD7190_REG_CONF 2 // Configuration Register (RW, 24-bit) 00069 #define AD7190_REG_DATA 3 // Data Register (RO, 24/32-bit) 00070 #define AD7190_REG_ID 4 // ID Register (RO, 8-bit) 00071 #define AD7190_REG_GPOCON 5 // GPOCON Register (RW, 8-bit) 00072 #define AD7190_REG_OFFSET 6 // Offset Register (RW, 24-bit 00073 #define AD7190_REG_FULLSCALE 7 // Full-Scale Register (RW, 24-bit) 00074 00075 /* Communications Register Bit Designations (AD7190_REG_COMM) */ 00076 #define AD7190_COMM_WEN (1 << 7) // Write Enable. 00077 #define AD7190_COMM_WRITE (0 << 6) // Write Operation. 00078 #define AD7190_COMM_READ (1 << 6) // Read Operation. 00079 #define AD7190_COMM_ADDR(x) (((x) & 0x7) << 3) // Register Address. 00080 #define AD7190_COMM_CREAD (1 << 2) // Continuous Read of Data Register. 00081 00082 /* Status Register Bit Designations (AD7190_REG_STAT) */ 00083 #define AD7190_STAT_RDY (1 << 7) // Ready. 00084 #define AD7190_STAT_ERR (1 << 6) // ADC error bit. 00085 #define AD7190_STAT_NOREF (1 << 5) // Error no external reference. 00086 #define AD7190_STAT_PARITY (1 << 4) // Parity check of the data register. 00087 #define AD7190_STAT_CH2 (1 << 2) // Channel 2. 00088 #define AD7190_STAT_CH1 (1 << 1) // Channel 1. 00089 #define AD7190_STAT_CH0 (1 << 0) // Channel 0. 00090 00091 /* Mode Register Bit Designations (AD7190_REG_MODE) */ 00092 #define AD7190_MODE_SEL(x) (((x) & 0x7) << 21) // Operation Mode Select. 00093 #define AD7190_MODE_DAT_STA (1 << 20) // Status Register transmission. 00094 #define AD7190_MODE_CLKSRC(x) (((x) & 0x3) << 18) // Clock Source Select. 00095 #define AD7190_MODE_SINC3 (1 << 15) // SINC3 Filter Select. 00096 #define AD7190_MODE_ENPAR (1 << 13) // Parity Enable. 00097 #define AD7190_MODE_SCYCLE (1 << 11) // Single cycle conversion. 00098 #define AD7190_MODE_REJ60 (1 << 10) // 50/60Hz notch filter. 00099 #define AD7190_MODE_RATE(x) ((x) & 0x3FF) // Filter Update Rate Select. 00100 00101 /* Mode Register: AD7190_MODE_SEL(x) options */ 00102 #define AD7190_MODE_CONT 0 // Continuous Conversion Mode. 00103 #define AD7190_MODE_SINGLE 1 // Single Conversion Mode. 00104 #define AD7190_MODE_IDLE 2 // Idle Mode. 00105 #define AD7190_MODE_PWRDN 3 // Power-Down Mode. 00106 #define AD7190_MODE_CAL_INT_ZERO 4 // Internal Zero-Scale Calibration. 00107 #define AD7190_MODE_CAL_INT_FULL 5 // Internal Full-Scale Calibration. 00108 #define AD7190_MODE_CAL_SYS_ZERO 6 // System Zero-Scale Calibration. 00109 #define AD7190_MODE_CAL_SYS_FULL 7 // System Full-Scale Calibration. 00110 00111 /* Mode Register: AD7190_MODE_CLKSRC(x) options */ 00112 #define AD7190_CLK_EXT_MCLK1_2 0 // External crystal. The external crystal 00113 // is connected from MCLK1 to MCLK2. 00114 #define AD7190_CLK_EXT_MCLK2 1 // External Clock applied to MCLK2 00115 #define AD7190_CLK_INT 2 // Internal 4.92 MHz clock. 00116 // Pin MCLK2 is tristated. 00117 #define AD7190_CLK_INT_CO 3 // Internal 4.92 MHz clock. The internal 00118 // clock is available on MCLK2. 00119 00120 /* Configuration Register Bit Designations (AD7190_REG_CONF) */ 00121 #define AD7190_CONF_CHOP (1 << 23) // CHOP enable. 00122 #define AD7190_CONF_REFSEL (1 << 20) // REFIN1/REFIN2 Reference Select. 00123 #define AD7190_CONF_CHAN(x) (((x) & 0xFF) << 8) // Channel select. 00124 #define AD7190_CONF_BURN (1 << 7) // Burnout current enable. 00125 #define AD7190_CONF_REFDET (1 << 6) // Reference detect enable. 00126 #define AD7190_CONF_BUF (1 << 4) // Buffered Mode Enable. 00127 #define AD7190_CONF_UNIPOLAR (1 << 3) // Unipolar/Bipolar Enable. 00128 #define AD7190_CONF_GAIN(x) ((x) & 0x7) // Gain Select. 00129 00130 /* Configuration Register: AD7190_CONF_CHAN(x) options */ 00131 #define AD7190_CH_AIN1P_AIN2M 0 // AIN1(+) - AIN2(-) 00132 #define AD7190_CH_AIN3P_AIN4M 1 // AIN3(+) - AIN4(-) 00133 #define AD7190_CH_TEMP_SENSOR 2 // Temperature sensor 00134 #define AD7190_CH_AIN2P_AIN2M 3 // AIN2(+) - AIN2(-) 00135 #define AD7190_CH_AIN1P_AINCOM 4 // AIN1(+) - AINCOM 00136 #define AD7190_CH_AIN2P_AINCOM 5 // AIN2(+) - AINCOM 00137 #define AD7190_CH_AIN3P_AINCOM 6 // AIN3(+) - AINCOM 00138 #define AD7190_CH_AIN4P_AINCOM 7 // AIN4(+) - AINCOM 00139 00140 /* Configuration Register: AD7190_CONF_GAIN(x) options */ 00141 // ADC Input Range (5 V Reference) 00142 #define AD7190_CONF_GAIN_1 0 // Gain 1 +-5 V 00143 #define AD7190_CONF_GAIN_8 3 // Gain 8 +-625 mV 00144 #define AD7190_CONF_GAIN_16 4 // Gain 16 +-312.5 mV 00145 #define AD7190_CONF_GAIN_32 5 // Gain 32 +-156.2 mV 00146 #define AD7190_CONF_GAIN_64 6 // Gain 64 +-78.125 mV 00147 #define AD7190_CONF_GAIN_128 7 // Gain 128 +-39.06 mV 00148 00149 /* ID Register Bit Designations (AD7190_REG_ID) */ 00150 #define ID_AD7190 0x4 00151 #define AD7190_ID_MASK 0x0F 00152 00153 /* GPOCON Register Bit Designations (AD7190_REG_GPOCON) */ 00154 #define AD7190_GPOCON_BPDSW (1 << 6) // Bridge power-down switch enable 00155 #define AD7190_GPOCON_GP32EN (1 << 5) // Digital Output P3 and P2 enable 00156 #define AD7190_GPOCON_GP10EN (1 << 4) // Digital Output P1 and P0 enable 00157 #define AD7190_GPOCON_P3DAT (1 << 3) // P3 state 00158 #define AD7190_GPOCON_P2DAT (1 << 2) // P2 state 00159 #define AD7190_GPOCON_P1DAT (1 << 1) // P1 state 00160 #define AD7190_GPOCON_P0DAT (1 << 0) // P0 state 00161 00162 00163 00164 /******************************************************************************/ 00165 /*********************** Functions Declarations *******************************/ 00166 /******************************************************************************/ 00167 /* Read-buffer in order to use mbed-api */ 00168 00169 00170 /***************************************************************************//** 00171 * @brief Writes data into a register. 00172 * 00173 * @param registerAddress - Address of the register. 00174 * @param registerValue - Data value to write. 00175 * @param bytesNumber - Number of bytes to be written. 00176 * 00177 * @return none. 00178 *******************************************************************************/ 00179 void AD7190_SetRegisterValue(unsigned char registerAddress, 00180 unsigned long registerValue, 00181 unsigned char bytesNumber); 00182 00183 /***************************************************************************//** 00184 * @brief Reads the value of a register. 00185 * 00186 * @param registerAddress - Address of the register. 00187 * @param bytesNumber - Number of bytes that will be read. 00188 * 00189 * @return buffer - Value of the register. 00190 *******************************************************************************/ 00191 unsigned long AD7190_GetRegisterValue(unsigned char registerAddress, 00192 unsigned char bytesNumber); 00193 00194 /***************************************************************************//** 00195 * @brief Checks if the AD7190 part is present. 00196 * 00197 * @return status - Indicates if the part is present or not. 1 for ok , 0 for error 00198 *******************************************************************************/ 00199 unsigned char AD7190_Init(unsigned int speed); 00200 00201 00202 /***************************************************************************//** 00203 * @brief Resets the device. 00204 * 00205 * @return none. 00206 *******************************************************************************/ 00207 void AD7190_Reset(void); 00208 00209 /***************************************************************************//** 00210 * @brief Set device to idle or power-down. 00211 * 00212 * @param pwrMode - Selects idle mode or power-down mode. 00213 * Example: 0 - power-down 00214 * 1 - idle 00215 * 00216 * @return none. 00217 *******************************************************************************/ 00218 void AD7190_SetPower(unsigned char pwrMode); 00219 00220 00221 /***************************************************************************//** 00222 * @brief Waits for RDY pin to go low. 00223 * @comment timeOutCnt related to CPU clock 00224 * @return none. 00225 *******************************************************************************/ 00226 void AD7190_WaitRdyGoLow(void); 00227 00228 /***************************************************************************//** 00229 * @brief Selects the channel to be enabled. 00230 * 00231 * @param channel - Selects a channel. 00232 * 00233 * @return none. 00234 *******************************************************************************/ 00235 void AD7190_ChannelSelect(unsigned short channel); 00236 00237 00238 /***************************************************************************//** 00239 * @brief Performs the given calibration to the specified channel. 00240 * 00241 * @param mode - Calibration type. 00242 * @param channel - Channel to be calibrated. 00243 * 00244 * @return none. 00245 *******************************************************************************/ 00246 void AD7190_Calibrate(unsigned char mode, unsigned char channel); 00247 00248 /***************************************************************************//** 00249 * @brief Selects the polarity of the conversion and the ADC input range. 00250 * 00251 * @param polarity - Polarity select bit. 00252 Example: 0 - bipolar operation is selected. 00253 1 - unipolar operation is selected. 00254 * @param range - Gain select bits. These bits are written by the user to select 00255 the ADC input range. 00256 * 00257 * @return none. 00258 *******************************************************************************/ 00259 void AD7190_RangeSetup(unsigned char polarity, unsigned char range); 00260 00261 /***************************************************************************//** 00262 * @brief Returns the result of a single conversion. 00263 * 00264 * @return regData - Result of a single analog-to-digital conversion. 00265 *******************************************************************************/ 00266 unsigned long AD7190_SingleConversion(void); 00267 00268 /***************************************************************************//** 00269 * @brief Returns the average of several conversion results. 00270 * 00271 * @return samplesAverage - The average of the conversion results. 00272 *******************************************************************************/ 00273 unsigned long AD7190_ContinuousReadAvg(unsigned char sampleNumber); 00274 00275 /***************************************************************************//** 00276 * @brief Read data from temperature sensor and converts it to Celsius degrees. 00277 * 00278 * @return temperature - Celsius degrees. 00279 *******************************************************************************/ 00280 unsigned long AD7190_TemperatureRead(void); 00281 00282 00283 extern Serial pc; 00284 #endif /* __AD7190_H__ */
Generated on Wed Jul 13 2022 09:47:46 by
1.7.2