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.
AD7790.h
00001 /** 00002 * @file AD7790.h 00003 * @brief Header file for AD7790 ADC 00004 * @author Analog Devices Inc. 00005 * 00006 * For support please go to: 00007 * Github: https://github.com/analogdevicesinc/mbed-adi 00008 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers 00009 * Product: http://www.analog.com/ad7790 00010 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all 00011 00012 ******************************************************************************** 00013 * Copyright 2016(c) Analog Devices, Inc. 00014 * 00015 * All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * - Redistributions of source code must retain the above copyright 00020 * notice, this list of conditions and the following disclaimer. 00021 * - Redistributions in binary form must reproduce the above copyright 00022 * notice, this list of conditions and the following disclaimer in 00023 * the documentation and/or other materials provided with the 00024 * distribution. 00025 * - Neither the name of Analog Devices, Inc. nor the names of its 00026 * contributors may be used to endorse or promote products derived 00027 * from this software without specific prior written permission. 00028 * - The use of this software may or may not infringe the patent rights 00029 * of one or more patent holders. This license does not release you 00030 * from the requirement that you obtain separate licenses from these 00031 * patent holders to use this software. 00032 * - Use of the software either in source or binary form, must be run 00033 * on or directly connected to an Analog Devices Inc. component. 00034 * 00035 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00036 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00037 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00038 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00039 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00040 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00041 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00042 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00043 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00044 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00045 * 00046 ********************************************************************************/ 00047 00048 #ifndef AD7790_H 00049 #define AD7790_H 00050 00051 #include "mbed.h" 00052 00053 /** 00054 * Comment this line if you want to turn off the debug mode. 00055 * The debug mode will send a message if an exception occurs within AD7790 driver 00056 */ 00057 00058 #define AD7790_DEBUG_MODE 00059 00060 /** 00061 * @brief Analog Devices AD7790 SPI 16-bit Buffered Sigma-Delta ADC 00062 */ 00063 class AD7790 00064 { 00065 public: 00066 /// AD7790 registers 00067 typedef enum { 00068 COMMUNICATION_REG = 0, ///< Communication register 00069 STATUS_REG = 0, ///< Status register 00070 MODE_REG, ///< Mode register 00071 FILTER_REG, ///< Filter Register 00072 DATA_REG ///< Data register 00073 } AD7790Register_t; 00074 00075 /// AD7790 channel configuration 00076 typedef enum { 00077 DIFFERENTIAL = 0, ///< AIN(+)-AIN(-) 00078 RESERVED, ///< reserved 00079 SHORT, ///< AIN(-)-AIN(-) 00080 VDDMONITOR ///< Monitor VDD 00081 } AD7790Channel_t; 00082 00083 typedef enum { 00084 CONTINOUS_CONVERSION_MODE = 0, 00085 SINGLE_CONVERSION_MODE = 0x80, 00086 SHUTDOWN_MODE = 0xC0 00087 } AD7790Mode_t; 00088 00089 typedef enum { 00090 MD1 = 0x80, ///< Mode Select Bit 1 00091 MD0 = 0x40, ///< Mode Select Bit 0 00092 G1 = 0x20, ///< Range bit 1 00093 G0 = 0x10, ///< Range bit 0 00094 BO = 0x08, ///< Burnout Current Enable bit 00095 BUF = 0x02, ///< Buffered mode bit 00096 } ModeRegisterBits_t ; 00097 00098 typedef enum { 00099 CLKDIV1 = 0x40, ///< Clock divider bit 1 00100 CLKDIV0 = 0x20, ///< Clock divider bit 0 00101 FS2 = 0x04, ///< Update rate bit 2 00102 FS1 = 0x02, ///< Update rate bit 1 00103 FS0 = 0x01, ///< Update rate bit 0 00104 } FilterRegisterBits_t ; 00105 00106 typedef enum { 00107 RANGE_VREF = 0, 00108 RANGE_VREF_DIV_2, 00109 RANGE_VREF_DIV_4, 00110 RANGE_VREF_DIV_8, 00111 } AnalogInputRange_t; 00112 00113 /** SPI configuration & constructor */ 00114 AD7790( float reference_voltage, PinName CS = SPI_CS, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK); 00115 void frequency(int hz); 00116 00117 /** Low level SPI bus comm methods */ 00118 void reset(void); 00119 00120 /** Register access methods*/ 00121 void set_channel(AD7790Channel_t channel); 00122 void set_conversion_mode(AD7790Mode_t mode); 00123 uint16_t read_data_reg(); 00124 uint8_t read_status_reg(void); 00125 void write_filter_reg(uint8_t regVal); 00126 uint8_t read_filter_reg(void); 00127 void write_mode_reg(uint8_t regVal); 00128 uint8_t read_mode_reg(void); 00129 void set_range(AnalogInputRange_t range); 00130 AnalogInputRange_t get_range(void); 00131 00132 /** Reference voltage methods */ 00133 void set_reference_voltage(float ref); 00134 float get_reference_voltage(void); 00135 00136 /** Voltage read methods */ 00137 float read_voltage(void); 00138 float data_to_voltage(uint16_t data); 00139 uint16_t voltage_to_data(float voltage); 00140 00141 /** AnalogIn API */ 00142 float read(void); 00143 uint16_t read_u16(void); 00144 00145 #ifdef MBED_OPERATORS 00146 operator float(); 00147 #endif 00148 00149 private: 00150 DigitalIn miso;///< DigitalIn must be initialized before SPI to prevent pin MUX overwrite 00151 SPI ad7790; ///< SPI instance of the AD7790 00152 DigitalOut cs; ///< DigitalOut instance for the chipselect of the AD7790 00153 00154 float _vref; 00155 uint8_t _PGA_gain; 00156 bool _continous_conversion; 00157 AD7790Channel_t _channel; 00158 00159 void write_reg(AD7790Register_t regAddress, uint8_t regValue); 00160 uint16_t write_spi(uint16_t data); 00161 uint16_t read_reg (AD7790Register_t regAddress); 00162 00163 const static uint16_t _SINGLE_CONVERSION_TIMEOUT = 0xFFFF; // in 10us = 100ms 00164 const static uint16_t _CONTINOUS_CONVERSION_TIMEOUT = 0xFFFF; 00165 const static uint16_t _RESOLUTION = 0xFFFF; 00166 const static uint8_t _RESET = 0xFF; 00167 const static uint8_t _DUMMY_BYTE = 0xFF; 00168 const static uint16_t _READ_FLAG = 0x0800; 00169 const static uint8_t _DATA_READ = 0x38; // Read from the Data Register 00170 const static uint8_t _DELAY_TIMING = 0x02; 00171 const static uint8_t _SPI_MODE = 3; 00172 }; 00173 00174 #endif
Generated on Tue Jul 12 2022 17:59:52 by
1.7.2
CN0357 - Toxic gas measurement
CN0216 - Weight Scale