| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#ifndef __AD7193_H__ |
| 44 |
#define __AD7193_H__ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#include "Communication.h" |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#define AD7193_SLAVE_ID 1 |
| 57 |
|
| 58 |
|
| 59 |
#define AD7193_CS_LOW SPI_CS_LOW |
| 60 |
#define AD7193_CS_HIGH SPI_CS_HIGH |
| 61 |
|
| 62 |
|
| 63 |
#define AD7193_RDY_STATE SPI_MISO |
| 64 |
|
| 65 |
|
| 66 |
#define AD7193_REG_COMM 0 // Communications Register (WO, 8-bit) |
| 67 |
#define AD7193_REG_STAT 0 // Status Register (RO, 8-bit) |
| 68 |
#define AD7193_REG_MODE 1 // Mode Register (RW, 24-bit |
| 69 |
#define AD7193_REG_CONF 2 // Configuration Register (RW, 24-bit) |
| 70 |
#define AD7193_REG_DATA 3 // Data Register (RO, 24/32-bit) |
| 71 |
#define AD7193_REG_ID 4 // ID Register (RO, 8-bit) |
| 72 |
#define AD7193_REG_GPOCON 5 // GPOCON Register (RW, 8-bit) |
| 73 |
#define AD7193_REG_OFFSET 6 // Offset Register (RW, 24-bit |
| 74 |
#define AD7193_REG_FULLSCALE 7 // Full-Scale Register (RW, 24-bit) |
| 75 |
|
| 76 |
|
| 77 |
#define AD7193_COMM_WEN (1 << 7) // Write Enable. |
| 78 |
#define AD7193_COMM_WRITE (0 << 6) // Write Operation. |
| 79 |
#define AD7193_COMM_READ (1 << 6) // Read Operation. |
| 80 |
#define AD7193_COMM_ADDR(x) (((x) & 0x7) << 3) // Register Address. |
| 81 |
#define AD7193_COMM_CREAD (1 << 2) // Continuous Read of Data Register. |
| 82 |
|
| 83 |
|
| 84 |
#define AD7193_STAT_RDY (1 << 7) // Ready. |
| 85 |
#define AD7193_STAT_ERR (1 << 6) // ADC error bit. |
| 86 |
#define AD7193_STAT_NOREF (1 << 5) // Error no external reference. |
| 87 |
#define AD7193_STAT_PARITY (1 << 4) // Parity check of the data register. |
| 88 |
#define AD7193_STAT_CH3 (1 << 3) // Channel 3. |
| 89 |
#define AD7193_STAT_CH2 (1 << 2) // Channel 2. |
| 90 |
#define AD7193_STAT_CH1 (1 << 1) // Channel 1. |
| 91 |
#define AD7193_STAT_CH0 (1 << 0) // Channel 0. |
| 92 |
|
| 93 |
|
| 94 |
#define AD7193_MODE_SEL(x) (((unsigned long)(x) & 0x7) << 21) // Operation Mode Select. |
| 95 |
#define AD7193_MODE_DAT_STA ((unsigned long)1 << 20) // Status Register transmission. |
| 96 |
#define AD7193_MODE_CLKSRC(x) (((unsigned long)(x) & 0x3) << 18) // Clock Source Select. |
| 97 |
#define AD7193_MODE_AVG(x) (((unsigned long)(x) & 0x3) << 16) // Fast settling filter. |
| 98 |
#define AD7193_MODE_SINC3 (1 << 15) // SINC3 Filter Select. |
| 99 |
#define AD7193_MODE_ENPAR (1 << 13) // Parity Enable. |
| 100 |
#define AD7193_MODE_CLKDIV (1 << 12) // Clock divide by 2 (AD7190/2 only). |
| 101 |
#define AD7193_MODE_SCYCLE (1 << 11) // Single cycle conversion. |
| 102 |
#define AD7193_MODE_REJ60 (1 << 10) // 50/60Hz notch filter. |
| 103 |
#define AD7193_MODE_RATE(x) ((x) & 0x3FF) // Filter Update Rate Select. |
| 104 |
|
| 105 |
|
| 106 |
#define AD7193_MODE_CONT 0 // Continuous Conversion Mode. |
| 107 |
#define AD7193_MODE_SINGLE 1 // Single Conversion Mode. |
| 108 |
#define AD7193_MODE_IDLE 2 // Idle Mode. |
| 109 |
#define AD7193_MODE_PWRDN 3 // Power-Down Mode. |
| 110 |
#define AD7193_MODE_CAL_INT_ZERO 4 // Internal Zero-Scale Calibration. |
| 111 |
#define AD7193_MODE_CAL_INT_FULL 5 // Internal Full-Scale Calibration. |
| 112 |
#define AD7193_MODE_CAL_SYS_ZERO 6 // System Zero-Scale Calibration. |
| 113 |
#define AD7193_MODE_CAL_SYS_FULL 7 // System Full-Scale Calibration. |
| 114 |
|
| 115 |
|
| 116 |
#define AD7193_CLK_EXT_MCLK1_2 0 // External crystal. The external crystal |
| 117 |
|
| 118 |
#define AD7193_CLK_EXT_MCLK2 1 // External Clock applied to MCLK2 |
| 119 |
#define AD7193_CLK_INT 2 // Internal 4.92 MHz clock. |
| 120 |
|
| 121 |
#define AD7193_CLK_INT_CO 3 // Internal 4.92 MHz clock. The internal |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
#define AD7193_AVG_NONE 0 // No averaging (fast settling mode disabled). |
| 126 |
#define AD7193_AVG_BY_2 1 // Average by 2. |
| 127 |
#define AD7193_AVG_BY_8 2 // Average by 8. |
| 128 |
#define AD7193_AVG_BY_16 3 // Average by 16. |
| 129 |
|
| 130 |
|
| 131 |
#define AD7193_CONF_CHOP ((unsigned long)1 << 23) // CHOP enable. |
| 132 |
#define AD7193_CONF_REFSEL ((unsigned long)1 << 20) // REFIN1/REFIN2 Reference Select. |
| 133 |
#define AD7193_CONF_PSEUDO ((unsigned long)1 << 18) // Pseudo differential analog inputs. |
| 134 |
#define AD7193_CONF_CHAN(x) ((unsigned long)((x) & 0x3FF) << 8) // Channel select. |
| 135 |
#define AD7193_CONF_BURN (1 << 7) // Burnout current enable. |
| 136 |
#define AD7193_CONF_REFDET (1 << 6) // Reference detect enable. |
| 137 |
#define AD7193_CONF_BUF (1 << 4) // Buffered Mode Enable. |
| 138 |
#define AD7193_CONF_UNIPOLAR (1 << 3) // Unipolar/Bipolar Enable. |
| 139 |
#define AD7193_CONF_GAIN(x) ((x) & 0x7) // Gain Select. |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
#define AD7193_CH_0 0 // AIN1(+) - AIN2(-); AIN1 - AINCOM |
| 144 |
#define AD7193_CH_1 1 // AIN3(+) - AIN4(-); AIN2 - AINCOM |
| 145 |
#define AD7193_CH_2 2 // AIN5(+) - AIN6(-); AIN3 - AINCOM |
| 146 |
#define AD7193_CH_3 3 // AIN7(+) - AIN8(-); AIN4 - AINCOM |
| 147 |
#define AD7193_CH_4 4 // AIN1(+) - AIN2(-); AIN5 - AINCOM |
| 148 |
#define AD7193_CH_5 5 // AIN3(+) - AIN4(-); AIN6 - AINCOM |
| 149 |
#define AD7193_CH_6 6 // AIN5(+) - AIN6(-); AIN7 - AINCOM |
| 150 |
#define AD7193_CH_7 7 // AIN7(+) - AIN8(-); AIN8 - AINCOM |
| 151 |
#define AD7193_CH_TEMP 8 // Temperature sensor |
| 152 |
#define AD7193_CH_SHORT 9 // AIN2(+) - AIN2(-); AINCOM(+) - AINCOM(-) |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
#define AD7193_CONF_GAIN_1 0 // Gain 1 +-2.5 V |
| 157 |
#define AD7193_CONF_GAIN_8 3 // Gain 8 +-312.5 mV |
| 158 |
#define AD7193_CONF_GAIN_16 4 // Gain 16 +-156.2 mV |
| 159 |
#define AD7193_CONF_GAIN_32 5 // Gain 32 +-78.125 mV |
| 160 |
#define AD7193_CONF_GAIN_64 6 // Gain 64 +-39.06 mV |
| 161 |
#define AD7193_CONF_GAIN_128 7 // Gain 128 +-19.53 mV |
| 162 |
|
| 163 |
|
| 164 |
#define ID_AD7193 0x2 |
| 165 |
#define AD7193_ID_MASK 0x0F |
| 166 |
|
| 167 |
|
| 168 |
#define AD7193_GPOCON_BPDSW (1 << 6) // Bridge power-down switch enable |
| 169 |
#define AD7193_GPOCON_GP32EN (1 << 5) // Digital Output P3 and P2 enable |
| 170 |
#define AD7193_GPOCON_GP10EN (1 << 4) // Digital Output P1 and P0 enable |
| 171 |
#define AD7193_GPOCON_P3DAT (1 << 3) // P3 state |
| 172 |
#define AD7193_GPOCON_P2DAT (1 << 2) // P2 state |
| 173 |
#define AD7193_GPOCON_P1DAT (1 << 1) // P1 state |
| 174 |
#define AD7193_GPOCON_P0DAT (1 << 0) // P0 state |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
char AD7193_Init(void); |
| 182 |
|
| 183 |
|
| 184 |
void AD7193_SetRegisterValue(unsigned char registerAddress, |
| 185 |
unsigned long registerValue, |
| 186 |
unsigned char bytesNumber, |
| 187 |
unsigned char modifyCS); |
| 188 |
|
| 189 |
|
| 190 |
unsigned long AD7193_GetRegisterValue(unsigned char registerAddress, |
| 191 |
unsigned char bytesNumber, |
| 192 |
unsigned char modifyCS); |
| 193 |
|
| 194 |
|
| 195 |
void AD7193_Reset(void); |
| 196 |
|
| 197 |
|
| 198 |
void AD7193_SetPower(unsigned char pwrMode); |
| 199 |
|
| 200 |
|
| 201 |
void AD7193_WaitRdyGoLow(void); |
| 202 |
|
| 203 |
|
| 204 |
void AD7193_ChannelSelect(unsigned short channel); |
| 205 |
|
| 206 |
|
| 207 |
void AD7193_Calibrate(unsigned char mode, unsigned char channel); |
| 208 |
|
| 209 |
|
| 210 |
void AD7193_RangeSetup(unsigned char polarity, unsigned char range); |
| 211 |
|
| 212 |
|
| 213 |
unsigned long AD7193_SingleConversion(void); |
| 214 |
|
| 215 |
|
| 216 |
unsigned long AD7193_ContinuousReadAvg(unsigned char sampleNumber); |
| 217 |
|
| 218 |
|
| 219 |
float AD7193_TemperatureRead(void); |
| 220 |
|
| 221 |
|
| 222 |
float AD7193_ConvertToVolts(unsigned long rawData, float vRef); |
| 223 |
|
| 224 |
#endif |