AD7793.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /***************************************************************************//**
  2. * @file AD7793.h
  3. * @brief Header file of AD7793 Driver.
  4. * @author Bancisor Mihai
  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: 500
  41. *******************************************************************************/
  42. #ifndef __AD7793_H__
  43. #define __AD7793_H__
  44. /******************************************************************************/
  45. /* AD7793 */
  46. /******************************************************************************/
  47. /* AD7793 GPIO */
  48. #define AD7793_RDY_STATE GPIO1_STATE
  49. /*AD7793 Registers*/
  50. #define AD7793_REG_COMM 0 /* Communications Register(WO, 8-bit) */
  51. #define AD7793_REG_STAT 0 /* Status Register (RO, 8-bit) */
  52. #define AD7793_REG_MODE 1 /* Mode Register (RW, 16-bit */
  53. #define AD7793_REG_CONF 2 /* Configuration Register (RW, 16-bit)*/
  54. #define AD7793_REG_DATA 3 /* Data Register (RO, 16-/24-bit) */
  55. #define AD7793_REG_ID 4 /* ID Register (RO, 8-bit) */
  56. #define AD7793_REG_IO 5 /* IO Register (RO, 8-bit) */
  57. #define AD7793_REG_OFFSET 6 /* Offset Register (RW, 24-bit */
  58. #define AD7793_REG_FULLSALE 7 /* Full-Scale Register (RW, 24-bit */
  59. /* Communications Register Bit Designations (AD7793_REG_COMM) */
  60. #define AD7793_COMM_WEN (1 << 7) /* Write Enable */
  61. #define AD7793_COMM_WRITE (0 << 6) /* Write Operation */
  62. #define AD7793_COMM_READ (1 << 6) /* Read Operation */
  63. #define AD7793_COMM_ADDR(x) (((x) & 0x7) << 3) /* Register Address */
  64. #define AD7793_COMM_CREAD (1 << 2) /* Continuous Read of Data Register */
  65. /* Status Register Bit Designations (AD7793_REG_STAT) */
  66. #define AD7793_STAT_RDY (1 << 7) /* Ready */
  67. #define AD7793_STAT_ERR (1 << 6) /* Error (Overrange, Underrange) */
  68. #define AD7793_STAT_CH3 (1 << 2) /* Channel 3 */
  69. #define AD7793_STAT_CH2 (1 << 1) /* Channel 2 */
  70. #define AD7793_STAT_CH1 (1 << 0) /* Channel 1 */
  71. /* Mode Register Bit Designations (AD7793_REG_MODE) */
  72. #define AD7793_MODE_SEL(x) (((x) & 0x7) << 13) /* Operation Mode Select */
  73. #define AD7793_MODE_CLKSRC(x) (((x) & 0x3) << 6) /* ADC Clock Source Select */
  74. #define AD7793_MODE_RATE(x) ((x) & 0xF) /* Filter Update Rate Select */
  75. /* AD7793_MODE_SEL(x) options */
  76. #define AD7793_MODE_CONT 0 /* Continuous Conversion Mode */
  77. #define AD7793_MODE_SINGLE 1 /* Single Conversion Mode */
  78. #define AD7793_MODE_IDLE 2 /* Idle Mode */
  79. #define AD7793_MODE_PWRDN 3 /* Power-Down Mode */
  80. #define AD7793_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
  81. #define AD7793_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
  82. #define AD7793_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
  83. #define AD7793_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */
  84. /* AD7793_MODE_CLKSRC(x) options */
  85. #define AD7793_CLK_INT 0 /* Internal 64 kHz Clk not available at the CLK pin */
  86. #define AD7793_CLK_INT_CO 1 /* Internal 64 kHz Clk available at the CLK pin */
  87. #define AD7793_CLK_EXT 2 /* External 64 kHz Clock */
  88. #define AD7793_CLK_EXT_DIV2 3 /* External Clock divided by 2 */
  89. /* Configuration Register Bit Designations (AD7793_REG_CONF) */
  90. #define AD7793_CONF_VBIAS(x) (((x) & 0x3) << 14) /* Bias Voltage Generator Enable */
  91. #define AD7793_CONF_BO_EN (1 << 13) /* Burnout Current Enable */
  92. #define AD7793_CONF_UNIPOLAR (1 << 12) /* Unipolar/Bipolar Enable */
  93. #define AD7793_CONF_BOOST (1 << 11) /* Boost Enable */
  94. #define AD7793_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */
  95. #define AD7793_CONF_REFSEL(x) (((x) & 0x1) << 7) /* INT/EXT Reference Select */
  96. #define AD7793_CONF_BUF (1 << 4) /* Buffered Mode Enable */
  97. #define AD7793_CONF_CHAN(x) ((x) & 0x7) /* Channel select */
  98. /* AD7793_CONF_GAIN(x) options */
  99. #define AD7793_GAIN_1 0
  100. #define AD7793_GAIN_2 1
  101. #define AD7793_GAIN_4 2
  102. #define AD7793_GAIN_8 3
  103. #define AD7793_GAIN_16 4
  104. #define AD7793_GAIN_32 5
  105. #define AD7793_GAIN_64 6
  106. #define AD7793_GAIN_128 7
  107. /* AD7793_CONF_REFSEL(x) options */
  108. #define AD7793_REFSEL_INT 1 /* Internal Reference Selected. */
  109. #define AD7793_REFSEL_EXT 0 /* External Reference Applied between REFIN(+) and REFIN(–). */
  110. /* AD7793_CONF_CHAN(x) options */
  111. #define AD7793_CH_AIN1P_AIN1M 0 /* AIN1(+) - AIN1(-) */
  112. #define AD7793_CH_AIN2P_AIN2M 1 /* AIN2(+) - AIN2(-) */
  113. #define AD7793_CH_AIN3P_AIN3M 2 /* AIN3(+) - AIN3(-) */
  114. #define AD7793_CH_AIN1M_AIN1M 3 /* AIN1(-) - AIN1(-) */
  115. #define AD7793_CH_TEMP 6 /* Temp Sensor */
  116. #define AD7793_CH_AVDD_MONITOR 7 /* AVDD Monitor */
  117. /* ID Register Bit Designations (AD7793_REG_ID) */
  118. #define AD7793_ID 0xB
  119. #define AD7793_ID_MASK 0xF
  120. /* IO (Excitation Current Sources) Register Bit Designations (AD7793_REG_IO) */
  121. #define AD7793_IEXCDIR(x) (((x) & 0x3) << 2)
  122. #define AD7793_IEXCEN(x) (((x) & 0x3) << 0)
  123. /* AD7793_IEXCDIR(x) options*/
  124. #define AD7793_DIR_IEXC1_IOUT1_IEXC2_IOUT2 0 /* IEXC1 connect to IOUT1, IEXC2 connect to IOUT2 */
  125. #define AD7793_DIR_IEXC1_IOUT2_IEXC2_IOUT1 1 /* IEXC1 connect to IOUT2, IEXC2 connect to IOUT1 */
  126. #define AD7793_DIR_IEXC1_IEXC2_IOUT1 2 /* Both current sources IEXC1,2 connect to IOUT1 */
  127. #define AD7793_DIR_IEXC1_IEXC2_IOUT2 3 /* Both current sources IEXC1,2 connect to IOUT2 */
  128. /* AD7793_IEXCEN(x) options*/
  129. #define AD7793_EN_IXCEN_10uA 1 /* Excitation Current 10uA */
  130. #define AD7793_EN_IXCEN_210uA 2 /* Excitation Current 210uA */
  131. #define AD7793_EN_IXCEN_1mA 3 /* Excitation Current 1mA */
  132. /******************************************************************************/
  133. /* Functions Prototypes */
  134. /******************************************************************************/
  135. /* Initialize AD7793 and check if the device is present*/
  136. unsigned char AD7793_Init(void);
  137. /* Sends 32 consecutive 1's on SPI in order to reset the part. */
  138. void AD7793_Reset(void);
  139. /* Reads the value of the selected register. */
  140. unsigned long AD7793_GetRegisterValue(unsigned char regAddress,
  141. unsigned char size,
  142. unsigned char modifyCS);
  143. /* Writes a value to the register. */
  144. void AD7793_SetRegisterValue(unsigned char regAddress,
  145. unsigned long regValue,
  146. unsigned char size,
  147. unsigned char modifyCS);
  148. /* Waits for RDY pin to go low. */
  149. void AD7793_WaitRdyGoLow(void);
  150. /* Sets the operating mode of AD7793. */
  151. void AD7793_SetMode(unsigned long mode);
  152. /* Selects the channel of AD7793. */
  153. void AD7793_SetChannel(unsigned long channel);
  154. /* Sets the gain of the In-Amp. */
  155. void AD7793_SetGain(unsigned long gain);
  156. /* Sets the reference source for the ADC. */
  157. void AD7793_SetIntReference(unsigned char type);
  158. /* Performs the given calibration to the specified channel. */
  159. void AD7793_Calibrate(unsigned char mode, unsigned char channel);
  160. /* Returns the result of a single conversion. */
  161. unsigned long AD7793_SingleConversion(void);
  162. /* Returns the average of several conversion results. */
  163. unsigned long AD7793_ContinuousReadAvg(unsigned char sampleNumber);
  164. #endif // _AD7793_H_