ADS1220 Library with ChipSelect Support and Code to Voltage Conversion Program

Dependents:   WeightScale

Committer:
sandeepmalladi
Date:
Wed Feb 15 15:37:49 2017 +0000
Revision:
2:45f4e10ec58b
Parent:
1:85ab9e2aab24
Convension Naming change

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sandeepmalladi 1:85ab9e2aab24 1 /***********************************************************************************************************************************************************************************************
sandeepmalladi 1:85ab9e2aab24 2 * File Name : ADS1220.cpp *
sandeepmalladi 1:85ab9e2aab24 3 * Author : Sandeep Reddy Malladi *
sandeepmalladi 2:45f4e10ec58b 4 * Designation : Entwicklungs ingenieur * *
sandeepmalladi 1:85ab9e2aab24 5 * Version : 1.0 *
sandeepmalladi 1:85ab9e2aab24 6 * Description : Low level drivers to implement for ADS1220 Using SPI Communication. *
sandeepmalladi 1:85ab9e2aab24 7 * *
sandeepmalladi 1:85ab9e2aab24 8 * *
sandeepmalladi 1:85ab9e2aab24 9 ************************************************************************************************************************************************************************************************/
sandeepmalladi 1:85ab9e2aab24 10
sandeepmalladi 0:90cd7e5e24af 11 #include "mbed.h"
sandeepmalladi 0:90cd7e5e24af 12 #include "ADS1220.h"
sandeepmalladi 0:90cd7e5e24af 13 #include <inttypes.h>
sandeepmalladi 0:90cd7e5e24af 14
sandeepmalladi 1:85ab9e2aab24 15 ADS1220::ADS1220(PinName mosi, PinName miso, PinName sclk,PinName cs):
sandeepmalladi 1:85ab9e2aab24 16 _device(mosi, miso, sclk),nCS_(cs)
sandeepmalladi 0:90cd7e5e24af 17 {
sandeepmalladi 0:90cd7e5e24af 18 _device.frequency(4000000);
sandeepmalladi 0:90cd7e5e24af 19 _device.format(8,1);
sandeepmalladi 0:90cd7e5e24af 20 }
sandeepmalladi 0:90cd7e5e24af 21
sandeepmalladi 1:85ab9e2aab24 22 void ADS1220::AssertCS( int fAssert)
sandeepmalladi 1:85ab9e2aab24 23 {
sandeepmalladi 1:85ab9e2aab24 24 if (fAssert)
sandeepmalladi 1:85ab9e2aab24 25 nCS_ = 1;
sandeepmalladi 1:85ab9e2aab24 26 else
sandeepmalladi 1:85ab9e2aab24 27 nCS_ = 0;
sandeepmalladi 1:85ab9e2aab24 28
sandeepmalladi 1:85ab9e2aab24 29 }
sandeepmalladi 0:90cd7e5e24af 30
sandeepmalladi 0:90cd7e5e24af 31 // ADS1220 Initial Configuration
sandeepmalladi 0:90cd7e5e24af 32 void ADS1220::Config(void)
sandeepmalladi 0:90cd7e5e24af 33 {
sandeepmalladi 0:90cd7e5e24af 34 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 35 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 36
sandeepmalladi 0:90cd7e5e24af 37 // clear prev value;
sandeepmalladi 0:90cd7e5e24af 38 Temp &= 0x00;
sandeepmalladi 0:90cd7e5e24af 39 Temp |= (ADS1220_MUX_2_3 | ADS1220_GAIN_128);//ADS1220_GAIN_128);
sandeepmalladi 0:90cd7e5e24af 40
sandeepmalladi 0:90cd7e5e24af 41 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 42 WriteRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 43
sandeepmalladi 0:90cd7e5e24af 44 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 45 // clear prev DataRate code;
sandeepmalladi 0:90cd7e5e24af 46 Temp &= 0x00;
sandeepmalladi 1:85ab9e2aab24 47 Temp |= (ADS1220_DR_20 | ADS1220_CC); // Set default start mode to 600sps and continuous conversions
sandeepmalladi 0:90cd7e5e24af 48
sandeepmalladi 0:90cd7e5e24af 49 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 50 WriteRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 51
sandeepmalladi 0:90cd7e5e24af 52 // ADS1220WriteRegister(ADS1220_2_REGISTER, 0x01, 0x00000000);
sandeepmalladi 0:90cd7e5e24af 53 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 54
sandeepmalladi 0:90cd7e5e24af 55 // clear prev DataRate code;
sandeepmalladi 0:90cd7e5e24af 56 Temp &= 0x00;
sandeepmalladi 1:85ab9e2aab24 57 Temp |= (ADS1220_VREF_EX_DED | ADS1220_REJECT_BOTH); // Set Internal Vref as 2.048 V
sandeepmalladi 0:90cd7e5e24af 58
sandeepmalladi 0:90cd7e5e24af 59 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 60 WriteRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 61 }
sandeepmalladi 0:90cd7e5e24af 62
sandeepmalladi 0:90cd7e5e24af 63
sandeepmalladi 0:90cd7e5e24af 64 void ADS1220::SendByte(unsigned char Value)
sandeepmalladi 0:90cd7e5e24af 65 {
sandeepmalladi 0:90cd7e5e24af 66
sandeepmalladi 0:90cd7e5e24af 67 _device.write(Value);
sandeepmalladi 0:90cd7e5e24af 68 }
sandeepmalladi 0:90cd7e5e24af 69
sandeepmalladi 0:90cd7e5e24af 70
sandeepmalladi 0:90cd7e5e24af 71 unsigned int ADS1220::ReceiveByte(void)
sandeepmalladi 0:90cd7e5e24af 72 {
sandeepmalladi 0:90cd7e5e24af 73 unsigned int readvalue;
sandeepmalladi 0:90cd7e5e24af 74 readvalue = _device.write(0x00);
sandeepmalladi 0:90cd7e5e24af 75
sandeepmalladi 0:90cd7e5e24af 76 return readvalue;
sandeepmalladi 0:90cd7e5e24af 77 }
sandeepmalladi 0:90cd7e5e24af 78
sandeepmalladi 0:90cd7e5e24af 79 /*
sandeepmalladi 0:90cd7e5e24af 80 ******************************************************************************
sandeepmalladi 0:90cd7e5e24af 81 higher level functions
sandeepmalladi 0:90cd7e5e24af 82 */
sandeepmalladi 0:90cd7e5e24af 83 unsigned int ADS1220::ReadData(void)
sandeepmalladi 0:90cd7e5e24af 84 {
sandeepmalladi 0:90cd7e5e24af 85 uint32_t Data;
sandeepmalladi 0:90cd7e5e24af 86
sandeepmalladi 0:90cd7e5e24af 87
sandeepmalladi 0:90cd7e5e24af 88 // assert CS to start transfer
sandeepmalladi 1:85ab9e2aab24 89 AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 90
sandeepmalladi 0:90cd7e5e24af 91 // send the command byte
sandeepmalladi 0:90cd7e5e24af 92 SendByte(ADS1220_CMD_RDATA);
sandeepmalladi 0:90cd7e5e24af 93
sandeepmalladi 0:90cd7e5e24af 94 // get the conversion result
sandeepmalladi 0:90cd7e5e24af 95 #ifdef ADS1120
sandeepmalladi 0:90cd7e5e24af 96 Data = ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 97 Data = (Data << 8) | ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 98 //Data = (Data << 8) | ADS1220ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 99
sandeepmalladi 0:90cd7e5e24af 100 // sign extend data
sandeepmalladi 0:90cd7e5e24af 101 if (Data & 0x8000)
sandeepmalladi 0:90cd7e5e24af 102 Data |= 0xffff0000;
sandeepmalladi 0:90cd7e5e24af 103 #else
sandeepmalladi 0:90cd7e5e24af 104 Data = ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 105 Data = (Data << 8) |ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 106 Data = (Data << 8) |ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 107
sandeepmalladi 0:90cd7e5e24af 108 // sign extend data
sandeepmalladi 0:90cd7e5e24af 109 if (Data & 0x800000)
sandeepmalladi 0:90cd7e5e24af 110 Data |= 0xff000000;
sandeepmalladi 0:90cd7e5e24af 111
sandeepmalladi 0:90cd7e5e24af 112 #endif
sandeepmalladi 0:90cd7e5e24af 113 // de-assert CS
sandeepmalladi 1:85ab9e2aab24 114 AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 115 return Data;
sandeepmalladi 0:90cd7e5e24af 116 }
sandeepmalladi 0:90cd7e5e24af 117
sandeepmalladi 0:90cd7e5e24af 118 void ADS1220::ReadRegister(int StartAddress, int NumRegs, unsigned * pData)
sandeepmalladi 0:90cd7e5e24af 119 {
sandeepmalladi 0:90cd7e5e24af 120 int i;
sandeepmalladi 0:90cd7e5e24af 121
sandeepmalladi 0:90cd7e5e24af 122 // assert CS to start transfer
sandeepmalladi 1:85ab9e2aab24 123 AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 124
sandeepmalladi 0:90cd7e5e24af 125 // send the command byte
sandeepmalladi 0:90cd7e5e24af 126 SendByte(ADS1220_CMD_RREG | (((StartAddress<<2) & 0x0c) |((NumRegs-1)&0x03)));
sandeepmalladi 0:90cd7e5e24af 127
sandeepmalladi 0:90cd7e5e24af 128 // get the register content
sandeepmalladi 0:90cd7e5e24af 129 for (i=0; i< NumRegs; i++)
sandeepmalladi 0:90cd7e5e24af 130 {
sandeepmalladi 0:90cd7e5e24af 131 *pData++ = ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 132 }
sandeepmalladi 0:90cd7e5e24af 133
sandeepmalladi 0:90cd7e5e24af 134 // de-assert CS
sandeepmalladi 1:85ab9e2aab24 135 AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 136
sandeepmalladi 0:90cd7e5e24af 137 return;
sandeepmalladi 0:90cd7e5e24af 138 }
sandeepmalladi 0:90cd7e5e24af 139
sandeepmalladi 0:90cd7e5e24af 140 void ADS1220::WriteRegister(int StartAddress, int NumRegs, unsigned * pData)
sandeepmalladi 0:90cd7e5e24af 141 {
sandeepmalladi 0:90cd7e5e24af 142 int i;
sandeepmalladi 0:90cd7e5e24af 143
sandeepmalladi 0:90cd7e5e24af 144 // assert CS to start transfer
sandeepmalladi 1:85ab9e2aab24 145 AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 146
sandeepmalladi 0:90cd7e5e24af 147 // send the command byte
sandeepmalladi 0:90cd7e5e24af 148 SendByte(ADS1220_CMD_WREG | (((StartAddress<<2) & 0x0c) |((NumRegs-1)&0x03)));
sandeepmalladi 0:90cd7e5e24af 149
sandeepmalladi 0:90cd7e5e24af 150 // send the data bytes
sandeepmalladi 0:90cd7e5e24af 151 for (i=0; i< NumRegs; i++)
sandeepmalladi 0:90cd7e5e24af 152 {
sandeepmalladi 0:90cd7e5e24af 153 SendByte(*pData++);
sandeepmalladi 0:90cd7e5e24af 154 }
sandeepmalladi 0:90cd7e5e24af 155
sandeepmalladi 0:90cd7e5e24af 156 // de-assert CS
sandeepmalladi 1:85ab9e2aab24 157 AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 158
sandeepmalladi 0:90cd7e5e24af 159 return;
sandeepmalladi 0:90cd7e5e24af 160 }
sandeepmalladi 0:90cd7e5e24af 161
sandeepmalladi 0:90cd7e5e24af 162 void ADS1220::SendResetCommand(void)
sandeepmalladi 0:90cd7e5e24af 163 {
sandeepmalladi 0:90cd7e5e24af 164 // assert CS to start transfer
sandeepmalladi 1:85ab9e2aab24 165 AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 166
sandeepmalladi 0:90cd7e5e24af 167 // send the command byte
sandeepmalladi 0:90cd7e5e24af 168 SendByte(ADS1220_CMD_RESET);
sandeepmalladi 0:90cd7e5e24af 169
sandeepmalladi 0:90cd7e5e24af 170 // de-assert CS
sandeepmalladi 1:85ab9e2aab24 171 AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 172
sandeepmalladi 0:90cd7e5e24af 173 return;
sandeepmalladi 0:90cd7e5e24af 174 }
sandeepmalladi 0:90cd7e5e24af 175
sandeepmalladi 0:90cd7e5e24af 176 void ADS1220::SendStartCommand(void)
sandeepmalladi 0:90cd7e5e24af 177 {
sandeepmalladi 0:90cd7e5e24af 178 // assert CS to start transfer
sandeepmalladi 1:85ab9e2aab24 179 AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 180
sandeepmalladi 0:90cd7e5e24af 181 // send the command byte
sandeepmalladi 0:90cd7e5e24af 182 SendByte(ADS1220_CMD_SYNC);
sandeepmalladi 0:90cd7e5e24af 183
sandeepmalladi 0:90cd7e5e24af 184 // de-assert CS
sandeepmalladi 1:85ab9e2aab24 185 AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 186
sandeepmalladi 0:90cd7e5e24af 187 return;
sandeepmalladi 0:90cd7e5e24af 188 }
sandeepmalladi 0:90cd7e5e24af 189
sandeepmalladi 0:90cd7e5e24af 190 void ADS1220::SendShutdownCommand(void)
sandeepmalladi 0:90cd7e5e24af 191 {
sandeepmalladi 0:90cd7e5e24af 192 // assert CS to start transfer
sandeepmalladi 1:85ab9e2aab24 193 AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 194
sandeepmalladi 0:90cd7e5e24af 195 // send the command byte
sandeepmalladi 0:90cd7e5e24af 196 SendByte(ADS1220_CMD_SHUTDOWN);
sandeepmalladi 0:90cd7e5e24af 197
sandeepmalladi 0:90cd7e5e24af 198 // de-assert CS
sandeepmalladi 1:85ab9e2aab24 199 AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 200
sandeepmalladi 0:90cd7e5e24af 201 return;
sandeepmalladi 0:90cd7e5e24af 202 }
sandeepmalladi 0:90cd7e5e24af 203
sandeepmalladi 0:90cd7e5e24af 204 /*
sandeepmalladi 0:90cd7e5e24af 205 ******************************************************************************
sandeepmalladi 0:90cd7e5e24af 206 register set value commands
sandeepmalladi 0:90cd7e5e24af 207 */
sandeepmalladi 0:90cd7e5e24af 208
sandeepmalladi 0:90cd7e5e24af 209 int ADS1220::SetChannel(int Mux)
sandeepmalladi 0:90cd7e5e24af 210 {
sandeepmalladi 0:90cd7e5e24af 211 unsigned int cMux = Mux;
sandeepmalladi 0:90cd7e5e24af 212 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 213 WriteRegister(ADS1220_0_REGISTER, 0x01, &cMux);
sandeepmalladi 0:90cd7e5e24af 214
sandeepmalladi 0:90cd7e5e24af 215 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 216 }
sandeepmalladi 0:90cd7e5e24af 217
sandeepmalladi 0:90cd7e5e24af 218 int ADS1220::SetGain(int Gain)
sandeepmalladi 0:90cd7e5e24af 219 {
sandeepmalladi 0:90cd7e5e24af 220 unsigned int cGain = Gain;
sandeepmalladi 0:90cd7e5e24af 221 // write the register value containing the new code back to the ADS
sandeepmalladi 0:90cd7e5e24af 222 WriteRegister(ADS1220_0_REGISTER, 0x01, &cGain);
sandeepmalladi 0:90cd7e5e24af 223
sandeepmalladi 0:90cd7e5e24af 224 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 225 }
sandeepmalladi 0:90cd7e5e24af 226
sandeepmalladi 0:90cd7e5e24af 227 int ADS1220::SetPGABypass(int Bypass)
sandeepmalladi 0:90cd7e5e24af 228 {
sandeepmalladi 0:90cd7e5e24af 229 unsigned int cBypass = Bypass;
sandeepmalladi 0:90cd7e5e24af 230 // write the register value containing the new code back to the ADS
sandeepmalladi 0:90cd7e5e24af 231 WriteRegister(ADS1220_0_REGISTER, 0x01, &cBypass);
sandeepmalladi 0:90cd7e5e24af 232
sandeepmalladi 0:90cd7e5e24af 233 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 234 }
sandeepmalladi 0:90cd7e5e24af 235
sandeepmalladi 0:90cd7e5e24af 236 int ADS1220::SetDataRate(int DataRate)
sandeepmalladi 0:90cd7e5e24af 237 {
sandeepmalladi 0:90cd7e5e24af 238 unsigned int cDataRate = DataRate;
sandeepmalladi 0:90cd7e5e24af 239 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 240 WriteRegister(ADS1220_1_REGISTER, 0x01, &cDataRate);
sandeepmalladi 0:90cd7e5e24af 241
sandeepmalladi 0:90cd7e5e24af 242 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 243 }
sandeepmalladi 0:90cd7e5e24af 244
sandeepmalladi 0:90cd7e5e24af 245 int ADS1220::SetClockMode(int ClockMode)
sandeepmalladi 0:90cd7e5e24af 246 {
sandeepmalladi 0:90cd7e5e24af 247 unsigned int cClockMode = ClockMode;
sandeepmalladi 0:90cd7e5e24af 248
sandeepmalladi 0:90cd7e5e24af 249 // write the register value containing the value back to the ADS
sandeepmalladi 0:90cd7e5e24af 250 WriteRegister(ADS1220_1_REGISTER, 0x01, &cClockMode);
sandeepmalladi 0:90cd7e5e24af 251
sandeepmalladi 0:90cd7e5e24af 252 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 253 }
sandeepmalladi 0:90cd7e5e24af 254
sandeepmalladi 0:90cd7e5e24af 255 int ADS1220::SetPowerDown(int PowerDown)
sandeepmalladi 0:90cd7e5e24af 256 {
sandeepmalladi 0:90cd7e5e24af 257 unsigned int cPowerDown = PowerDown;
sandeepmalladi 0:90cd7e5e24af 258
sandeepmalladi 0:90cd7e5e24af 259 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 260 WriteRegister(ADS1220_1_REGISTER, 0x01, &cPowerDown);
sandeepmalladi 0:90cd7e5e24af 261
sandeepmalladi 0:90cd7e5e24af 262 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 263 }
sandeepmalladi 0:90cd7e5e24af 264
sandeepmalladi 0:90cd7e5e24af 265 int ADS1220::SetTemperatureMode(int TempMode)
sandeepmalladi 0:90cd7e5e24af 266 {
sandeepmalladi 0:90cd7e5e24af 267 unsigned int cTempMode = TempMode;
sandeepmalladi 0:90cd7e5e24af 268
sandeepmalladi 0:90cd7e5e24af 269 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 270 WriteRegister(ADS1220_1_REGISTER, 0x01, &cTempMode);
sandeepmalladi 0:90cd7e5e24af 271
sandeepmalladi 0:90cd7e5e24af 272 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 273 }
sandeepmalladi 0:90cd7e5e24af 274
sandeepmalladi 0:90cd7e5e24af 275 int ADS1220::SetBurnOutSource(int BurnOut)
sandeepmalladi 0:90cd7e5e24af 276 {
sandeepmalladi 0:90cd7e5e24af 277 unsigned int cBurnOut = BurnOut;
sandeepmalladi 0:90cd7e5e24af 278
sandeepmalladi 0:90cd7e5e24af 279 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 280 WriteRegister(ADS1220_1_REGISTER, 0x01, &cBurnOut);
sandeepmalladi 0:90cd7e5e24af 281
sandeepmalladi 0:90cd7e5e24af 282 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 283 }
sandeepmalladi 0:90cd7e5e24af 284
sandeepmalladi 0:90cd7e5e24af 285 int ADS1220::SetVoltageReference(int VoltageRef)
sandeepmalladi 0:90cd7e5e24af 286 {
sandeepmalladi 0:90cd7e5e24af 287 unsigned int cVoltageRef = VoltageRef;
sandeepmalladi 0:90cd7e5e24af 288
sandeepmalladi 0:90cd7e5e24af 289 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 290 WriteRegister(ADS1220_2_REGISTER, 0x01, &cVoltageRef);
sandeepmalladi 0:90cd7e5e24af 291
sandeepmalladi 0:90cd7e5e24af 292 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 293 }
sandeepmalladi 0:90cd7e5e24af 294
sandeepmalladi 0:90cd7e5e24af 295 int ADS1220::Set50_60Rejection(int Rejection)
sandeepmalladi 0:90cd7e5e24af 296 {
sandeepmalladi 0:90cd7e5e24af 297 unsigned int cRejection = Rejection;
sandeepmalladi 0:90cd7e5e24af 298
sandeepmalladi 0:90cd7e5e24af 299 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 300 WriteRegister(ADS1220_2_REGISTER, 0x01, &cRejection);
sandeepmalladi 0:90cd7e5e24af 301
sandeepmalladi 0:90cd7e5e24af 302 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 303 }
sandeepmalladi 0:90cd7e5e24af 304
sandeepmalladi 0:90cd7e5e24af 305 int ADS1220::SetLowSidePowerSwitch(int PowerSwitch)
sandeepmalladi 0:90cd7e5e24af 306 {
sandeepmalladi 0:90cd7e5e24af 307 unsigned int cPowerSwitch = PowerSwitch;
sandeepmalladi 0:90cd7e5e24af 308
sandeepmalladi 0:90cd7e5e24af 309 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 310 WriteRegister(ADS1220_2_REGISTER, 0x01, &cPowerSwitch);
sandeepmalladi 0:90cd7e5e24af 311
sandeepmalladi 0:90cd7e5e24af 312 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 313 }
sandeepmalladi 0:90cd7e5e24af 314
sandeepmalladi 0:90cd7e5e24af 315 int ADS1220::SetCurrentDACOutput(int CurrentOutput)
sandeepmalladi 0:90cd7e5e24af 316 {
sandeepmalladi 0:90cd7e5e24af 317 unsigned int cCurrentOutput = CurrentOutput;
sandeepmalladi 0:90cd7e5e24af 318
sandeepmalladi 0:90cd7e5e24af 319 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 320 WriteRegister(ADS1220_2_REGISTER, 0x01, &cCurrentOutput);
sandeepmalladi 0:90cd7e5e24af 321
sandeepmalladi 0:90cd7e5e24af 322 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 323 }
sandeepmalladi 0:90cd7e5e24af 324
sandeepmalladi 0:90cd7e5e24af 325 int ADS1220::SetIDACRouting(int IDACRoute)
sandeepmalladi 0:90cd7e5e24af 326 {
sandeepmalladi 0:90cd7e5e24af 327 unsigned int cIDACRoute = IDACRoute;
sandeepmalladi 0:90cd7e5e24af 328
sandeepmalladi 0:90cd7e5e24af 329 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 330 WriteRegister(ADS1220_3_REGISTER, 0x01, &cIDACRoute);
sandeepmalladi 0:90cd7e5e24af 331
sandeepmalladi 0:90cd7e5e24af 332 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 333 }
sandeepmalladi 0:90cd7e5e24af 334
sandeepmalladi 0:90cd7e5e24af 335 int ADS1220::SetDRDYMode(int DRDYMode)
sandeepmalladi 0:90cd7e5e24af 336 {
sandeepmalladi 0:90cd7e5e24af 337 unsigned int cDRDYMode = DRDYMode;
sandeepmalladi 0:90cd7e5e24af 338
sandeepmalladi 0:90cd7e5e24af 339 // write the register value containing the new gain code back to the ADS
sandeepmalladi 0:90cd7e5e24af 340 WriteRegister(ADS1220_3_REGISTER, 0x01, &cDRDYMode);
sandeepmalladi 0:90cd7e5e24af 341
sandeepmalladi 0:90cd7e5e24af 342 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 343 }
sandeepmalladi 0:90cd7e5e24af 344
sandeepmalladi 0:90cd7e5e24af 345 /*
sandeepmalladi 0:90cd7e5e24af 346 ******************************************************************************
sandeepmalladi 0:90cd7e5e24af 347 register get value commands
sandeepmalladi 0:90cd7e5e24af 348 */
sandeepmalladi 0:90cd7e5e24af 349
sandeepmalladi 0:90cd7e5e24af 350 int ADS1220::GetChannel(void)
sandeepmalladi 0:90cd7e5e24af 351 {
sandeepmalladi 0:90cd7e5e24af 352 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 353
sandeepmalladi 0:90cd7e5e24af 354 //Parse Mux data from register
sandeepmalladi 0:90cd7e5e24af 355 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 356
sandeepmalladi 0:90cd7e5e24af 357 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 358 return (Temp >>4);
sandeepmalladi 0:90cd7e5e24af 359 }
sandeepmalladi 0:90cd7e5e24af 360
sandeepmalladi 0:90cd7e5e24af 361 int ADS1220::GetGain(void)
sandeepmalladi 0:90cd7e5e24af 362 {
sandeepmalladi 0:90cd7e5e24af 363 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 364
sandeepmalladi 0:90cd7e5e24af 365 //Parse Gain data from register
sandeepmalladi 0:90cd7e5e24af 366 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 367
sandeepmalladi 0:90cd7e5e24af 368 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 369 return ( (Temp & 0x0e) >>1);
sandeepmalladi 0:90cd7e5e24af 370 }
sandeepmalladi 0:90cd7e5e24af 371
sandeepmalladi 0:90cd7e5e24af 372 int ADS1220::GetPGABypass(void)
sandeepmalladi 0:90cd7e5e24af 373 {
sandeepmalladi 0:90cd7e5e24af 374 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 375
sandeepmalladi 0:90cd7e5e24af 376 //Parse Bypass data from register
sandeepmalladi 0:90cd7e5e24af 377 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 378
sandeepmalladi 0:90cd7e5e24af 379 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 380 return (Temp & 0x01);
sandeepmalladi 0:90cd7e5e24af 381 }
sandeepmalladi 0:90cd7e5e24af 382
sandeepmalladi 0:90cd7e5e24af 383 int ADS1220::GetDataRate(void)
sandeepmalladi 0:90cd7e5e24af 384 {
sandeepmalladi 0:90cd7e5e24af 385 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 386
sandeepmalladi 0:90cd7e5e24af 387 //Parse DataRate data from register
sandeepmalladi 0:90cd7e5e24af 388 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 389
sandeepmalladi 0:90cd7e5e24af 390 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 391 return ( Temp >>5 );
sandeepmalladi 0:90cd7e5e24af 392 }
sandeepmalladi 0:90cd7e5e24af 393
sandeepmalladi 0:90cd7e5e24af 394 int ADS1220::GetClockMode(void)
sandeepmalladi 0:90cd7e5e24af 395 {
sandeepmalladi 0:90cd7e5e24af 396 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 397
sandeepmalladi 0:90cd7e5e24af 398 //Parse ClockMode data from register
sandeepmalladi 0:90cd7e5e24af 399 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 400
sandeepmalladi 0:90cd7e5e24af 401 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 402 return ( (Temp & 0x18) >>3 );
sandeepmalladi 0:90cd7e5e24af 403 }
sandeepmalladi 0:90cd7e5e24af 404
sandeepmalladi 0:90cd7e5e24af 405 int ADS1220::GetPowerDown(void)
sandeepmalladi 0:90cd7e5e24af 406 {
sandeepmalladi 0:90cd7e5e24af 407 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 408
sandeepmalladi 0:90cd7e5e24af 409 //Parse PowerDown data from register
sandeepmalladi 0:90cd7e5e24af 410 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 411
sandeepmalladi 0:90cd7e5e24af 412 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 413 return ( (Temp & 0x04) >>2 );
sandeepmalladi 0:90cd7e5e24af 414 }
sandeepmalladi 0:90cd7e5e24af 415
sandeepmalladi 0:90cd7e5e24af 416 int ADS1220::GetTemperatureMode(void)
sandeepmalladi 0:90cd7e5e24af 417 {
sandeepmalladi 0:90cd7e5e24af 418 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 419
sandeepmalladi 0:90cd7e5e24af 420 //Parse TempMode data from register
sandeepmalladi 0:90cd7e5e24af 421 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 422
sandeepmalladi 0:90cd7e5e24af 423 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 424 return ( (Temp & 0x02) >>1 );
sandeepmalladi 0:90cd7e5e24af 425 }
sandeepmalladi 0:90cd7e5e24af 426
sandeepmalladi 0:90cd7e5e24af 427 int ADS1220::GetBurnOutSource(void)
sandeepmalladi 0:90cd7e5e24af 428 {
sandeepmalladi 0:90cd7e5e24af 429 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 430
sandeepmalladi 0:90cd7e5e24af 431 //Parse BurnOut data from register
sandeepmalladi 0:90cd7e5e24af 432 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 433
sandeepmalladi 0:90cd7e5e24af 434 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 435 return ( Temp & 0x01 );
sandeepmalladi 0:90cd7e5e24af 436 }
sandeepmalladi 0:90cd7e5e24af 437
sandeepmalladi 0:90cd7e5e24af 438 int ADS1220::GetVoltageReference(void)
sandeepmalladi 0:90cd7e5e24af 439 {
sandeepmalladi 0:90cd7e5e24af 440 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 441
sandeepmalladi 0:90cd7e5e24af 442 //Parse VoltageRef data from register
sandeepmalladi 0:90cd7e5e24af 443 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 444
sandeepmalladi 0:90cd7e5e24af 445 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 446 return ( Temp >>6 );
sandeepmalladi 0:90cd7e5e24af 447 }
sandeepmalladi 0:90cd7e5e24af 448
sandeepmalladi 0:90cd7e5e24af 449 int ADS1220::Get50_60Rejection(void)
sandeepmalladi 0:90cd7e5e24af 450 {
sandeepmalladi 0:90cd7e5e24af 451 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 452
sandeepmalladi 0:90cd7e5e24af 453 //Parse Rejection data from register
sandeepmalladi 0:90cd7e5e24af 454 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 455
sandeepmalladi 0:90cd7e5e24af 456 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 457 return ( (Temp & 0x30) >>4 );
sandeepmalladi 0:90cd7e5e24af 458 }
sandeepmalladi 0:90cd7e5e24af 459
sandeepmalladi 0:90cd7e5e24af 460 int ADS1220::GetLowSidePowerSwitch(void)
sandeepmalladi 0:90cd7e5e24af 461 {
sandeepmalladi 0:90cd7e5e24af 462 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 463
sandeepmalladi 0:90cd7e5e24af 464 //Parse PowerSwitch data from register
sandeepmalladi 0:90cd7e5e24af 465 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 466
sandeepmalladi 0:90cd7e5e24af 467 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 468 return ( (Temp & 0x08) >>3);
sandeepmalladi 0:90cd7e5e24af 469 }
sandeepmalladi 0:90cd7e5e24af 470
sandeepmalladi 0:90cd7e5e24af 471 int ADS1220::GetCurrentDACOutput(void)
sandeepmalladi 0:90cd7e5e24af 472 {
sandeepmalladi 0:90cd7e5e24af 473 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 474
sandeepmalladi 0:90cd7e5e24af 475 //Parse IDACOutput data from register
sandeepmalladi 0:90cd7e5e24af 476 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 477
sandeepmalladi 0:90cd7e5e24af 478 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 479 return ( Temp & 0x07 );
sandeepmalladi 0:90cd7e5e24af 480 }
sandeepmalladi 0:90cd7e5e24af 481
sandeepmalladi 0:90cd7e5e24af 482 int ADS1220::GetIDACRouting(int WhichOne)
sandeepmalladi 0:90cd7e5e24af 483 {
sandeepmalladi 0:90cd7e5e24af 484 // Check WhichOne sizing
sandeepmalladi 0:90cd7e5e24af 485 if (WhichOne >1) return ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 486
sandeepmalladi 0:90cd7e5e24af 487 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 488
sandeepmalladi 0:90cd7e5e24af 489 //Parse Mux data from register
sandeepmalladi 0:90cd7e5e24af 490 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 491
sandeepmalladi 0:90cd7e5e24af 492 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 493 if (WhichOne) return ( (Temp & 0x1c) >>2);
sandeepmalladi 0:90cd7e5e24af 494
sandeepmalladi 0:90cd7e5e24af 495 else return ( Temp >>5 );
sandeepmalladi 0:90cd7e5e24af 496
sandeepmalladi 0:90cd7e5e24af 497 }
sandeepmalladi 0:90cd7e5e24af 498
sandeepmalladi 0:90cd7e5e24af 499 int ADS1220::GetDRDYMode(void)
sandeepmalladi 0:90cd7e5e24af 500 {
sandeepmalladi 0:90cd7e5e24af 501 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 502
sandeepmalladi 0:90cd7e5e24af 503 //Parse DRDYMode data from register
sandeepmalladi 0:90cd7e5e24af 504 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 505
sandeepmalladi 0:90cd7e5e24af 506 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 507 return ( (Temp & 0x02) >>1 );
sandeepmalladi 0:90cd7e5e24af 508 }
sandeepmalladi 0:90cd7e5e24af 509
sandeepmalladi 0:90cd7e5e24af 510
sandeepmalladi 0:90cd7e5e24af 511
sandeepmalladi 0:90cd7e5e24af 512 /* Useful Functions within Main Program for Setting Register Contents
sandeepmalladi 0:90cd7e5e24af 513 *
sandeepmalladi 0:90cd7e5e24af 514 * These functions show the programming flow based on the header definitions.
sandeepmalladi 0:90cd7e5e24af 515 * The calls are not made within the demo example, but could easily be used by calling the function
sandeepmalladi 0:90cd7e5e24af 516 * defined within the program to complete a fully useful program.
sandeepmalladi 0:90cd7e5e24af 517 * Similar function calls were made in the firwmare design for the ADS1220EVM.
sandeepmalladi 0:90cd7e5e24af 518 *
sandeepmalladi 0:90cd7e5e24af 519 * The following function calls use ASCII data sent from a COM port to control settings
sandeepmalladi 0:90cd7e5e24af 520 * on the The data is recontructed from ASCII and then combined with the
sandeepmalladi 0:90cd7e5e24af 521 * register contents to save as new configuration settings.
sandeepmalladi 0:90cd7e5e24af 522 *
sandeepmalladi 0:90cd7e5e24af 523 * Function names correspond to datasheet register definitions
sandeepmalladi 0:90cd7e5e24af 524 */
sandeepmalladi 1:85ab9e2aab24 525 void ADS1220::set_MUX(int c)
sandeepmalladi 0:90cd7e5e24af 526 {
sandeepmalladi 1:85ab9e2aab24 527 int mux = c - 48;
sandeepmalladi 0:90cd7e5e24af 528 int dERROR;
sandeepmalladi 1:85ab9e2aab24 529 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 530
sandeepmalladi 0:90cd7e5e24af 531
sandeepmalladi 0:90cd7e5e24af 532 if (mux>=49 && mux<=54) mux -= 39;
sandeepmalladi 0:90cd7e5e24af 533
sandeepmalladi 0:90cd7e5e24af 534 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 535 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 536 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 537
sandeepmalladi 0:90cd7e5e24af 538 Temp &= 0x0f; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 539 // Change Data rate
sandeepmalladi 0:90cd7e5e24af 540 switch(mux) {
sandeepmalladi 0:90cd7e5e24af 541 case 0:
sandeepmalladi 0:90cd7e5e24af 542 dERROR = SetChannel(Temp + ADS1220_MUX_0_1);
sandeepmalladi 0:90cd7e5e24af 543 break;
sandeepmalladi 0:90cd7e5e24af 544 case 1:
sandeepmalladi 0:90cd7e5e24af 545 dERROR = SetChannel(Temp + ADS1220_MUX_0_2);
sandeepmalladi 0:90cd7e5e24af 546 break;
sandeepmalladi 0:90cd7e5e24af 547 case 2:
sandeepmalladi 0:90cd7e5e24af 548 dERROR = SetChannel(Temp + ADS1220_MUX_0_3);
sandeepmalladi 0:90cd7e5e24af 549 break;
sandeepmalladi 0:90cd7e5e24af 550 case 3:
sandeepmalladi 0:90cd7e5e24af 551 dERROR = SetChannel(Temp + ADS1220_MUX_1_2);
sandeepmalladi 0:90cd7e5e24af 552 break;
sandeepmalladi 0:90cd7e5e24af 553 case 4:
sandeepmalladi 0:90cd7e5e24af 554 dERROR = SetChannel(Temp + ADS1220_MUX_1_3);
sandeepmalladi 0:90cd7e5e24af 555 break;
sandeepmalladi 0:90cd7e5e24af 556 case 5:
sandeepmalladi 0:90cd7e5e24af 557 dERROR = SetChannel(Temp + ADS1220_MUX_2_3);
sandeepmalladi 0:90cd7e5e24af 558 break;
sandeepmalladi 0:90cd7e5e24af 559 case 6:
sandeepmalladi 0:90cd7e5e24af 560 dERROR = SetChannel(Temp + ADS1220_MUX_1_0);
sandeepmalladi 0:90cd7e5e24af 561 break;
sandeepmalladi 0:90cd7e5e24af 562 case 7:
sandeepmalladi 0:90cd7e5e24af 563 dERROR = SetChannel(Temp + ADS1220_MUX_3_2);
sandeepmalladi 0:90cd7e5e24af 564 break;
sandeepmalladi 0:90cd7e5e24af 565 case 8:
sandeepmalladi 0:90cd7e5e24af 566 dERROR = SetChannel(Temp + ADS1220_MUX_0_G);
sandeepmalladi 0:90cd7e5e24af 567 break;
sandeepmalladi 0:90cd7e5e24af 568 case 9:
sandeepmalladi 0:90cd7e5e24af 569 dERROR = SetChannel(Temp + ADS1220_MUX_1_G);
sandeepmalladi 0:90cd7e5e24af 570 break;
sandeepmalladi 0:90cd7e5e24af 571 case 10:
sandeepmalladi 0:90cd7e5e24af 572 dERROR = SetChannel(Temp + ADS1220_MUX_2_G);
sandeepmalladi 0:90cd7e5e24af 573 break;
sandeepmalladi 0:90cd7e5e24af 574 case 11:
sandeepmalladi 0:90cd7e5e24af 575 dERROR = SetChannel(Temp + ADS1220_MUX_3_G);
sandeepmalladi 0:90cd7e5e24af 576 break;
sandeepmalladi 0:90cd7e5e24af 577 case 12:
sandeepmalladi 0:90cd7e5e24af 578 dERROR = SetChannel(Temp + ADS1220_MUX_EX_VREF);
sandeepmalladi 0:90cd7e5e24af 579 break;
sandeepmalladi 0:90cd7e5e24af 580 case 13:
sandeepmalladi 0:90cd7e5e24af 581 dERROR = SetChannel(Temp + ADS1220_MUX_AVDD);
sandeepmalladi 0:90cd7e5e24af 582 break;
sandeepmalladi 0:90cd7e5e24af 583 case 14:
sandeepmalladi 0:90cd7e5e24af 584 dERROR = SetChannel(Temp + ADS1220_MUX_DIV2);
sandeepmalladi 0:90cd7e5e24af 585 break;
sandeepmalladi 0:90cd7e5e24af 586 case 15:
sandeepmalladi 0:90cd7e5e24af 587 dERROR = SetChannel(Temp + ADS1220_MUX_DIV2);
sandeepmalladi 0:90cd7e5e24af 588 break;
sandeepmalladi 0:90cd7e5e24af 589 default:
sandeepmalladi 0:90cd7e5e24af 590 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 591 break;
sandeepmalladi 0:90cd7e5e24af 592 }
sandeepmalladi 0:90cd7e5e24af 593
sandeepmalladi 0:90cd7e5e24af 594 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 595 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 596
sandeepmalladi 0:90cd7e5e24af 597 }
sandeepmalladi 0:90cd7e5e24af 598
sandeepmalladi 0:90cd7e5e24af 599 void ADS1220::set_GAIN(char c)
sandeepmalladi 0:90cd7e5e24af 600 {
sandeepmalladi 0:90cd7e5e24af 601 int pga = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 602 int dERROR;
sandeepmalladi 0:90cd7e5e24af 603 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 604
sandeepmalladi 0:90cd7e5e24af 605 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 606 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 607 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 608
sandeepmalladi 0:90cd7e5e24af 609 Temp &= 0xf1; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 610 // Change gain rate
sandeepmalladi 0:90cd7e5e24af 611 switch(pga) {
sandeepmalladi 0:90cd7e5e24af 612 case 0:
sandeepmalladi 0:90cd7e5e24af 613 dERROR = SetGain(Temp + ADS1220_GAIN_1);
sandeepmalladi 0:90cd7e5e24af 614 break;
sandeepmalladi 0:90cd7e5e24af 615 case 1:
sandeepmalladi 0:90cd7e5e24af 616 dERROR = SetGain(Temp + ADS1220_GAIN_2);
sandeepmalladi 0:90cd7e5e24af 617 break;
sandeepmalladi 0:90cd7e5e24af 618 case 2:
sandeepmalladi 0:90cd7e5e24af 619 dERROR = SetGain(Temp + ADS1220_GAIN_4);
sandeepmalladi 0:90cd7e5e24af 620 break;
sandeepmalladi 0:90cd7e5e24af 621 case 3:
sandeepmalladi 0:90cd7e5e24af 622 dERROR = SetGain(Temp + ADS1220_GAIN_8);
sandeepmalladi 0:90cd7e5e24af 623 break;
sandeepmalladi 0:90cd7e5e24af 624 case 4:
sandeepmalladi 0:90cd7e5e24af 625 dERROR = SetGain(Temp + ADS1220_GAIN_16);
sandeepmalladi 0:90cd7e5e24af 626 break;
sandeepmalladi 0:90cd7e5e24af 627 case 5:
sandeepmalladi 0:90cd7e5e24af 628 dERROR = SetGain(Temp + ADS1220_GAIN_32);
sandeepmalladi 0:90cd7e5e24af 629 break;
sandeepmalladi 0:90cd7e5e24af 630 case 6:
sandeepmalladi 0:90cd7e5e24af 631 dERROR = SetGain(Temp + ADS1220_GAIN_64);
sandeepmalladi 0:90cd7e5e24af 632 break;
sandeepmalladi 0:90cd7e5e24af 633 case 7:
sandeepmalladi 0:90cd7e5e24af 634 dERROR = SetGain(Temp + ADS1220_GAIN_128);
sandeepmalladi 0:90cd7e5e24af 635 break;
sandeepmalladi 0:90cd7e5e24af 636 default:
sandeepmalladi 0:90cd7e5e24af 637 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 638 break;
sandeepmalladi 0:90cd7e5e24af 639 }
sandeepmalladi 0:90cd7e5e24af 640
sandeepmalladi 0:90cd7e5e24af 641
sandeepmalladi 0:90cd7e5e24af 642
sandeepmalladi 0:90cd7e5e24af 643 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 644 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 645 }
sandeepmalladi 0:90cd7e5e24af 646
sandeepmalladi 0:90cd7e5e24af 647 void ADS1220::set_PGA_BYPASS(char c)
sandeepmalladi 0:90cd7e5e24af 648 {
sandeepmalladi 0:90cd7e5e24af 649 int buff = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 650 int dERROR;
sandeepmalladi 0:90cd7e5e24af 651 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 652
sandeepmalladi 0:90cd7e5e24af 653 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 654 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 655 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 656
sandeepmalladi 0:90cd7e5e24af 657 Temp &= 0xfe; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 658 // Change PGA Bypass
sandeepmalladi 0:90cd7e5e24af 659 switch(buff) {
sandeepmalladi 0:90cd7e5e24af 660 case 0:
sandeepmalladi 0:90cd7e5e24af 661 dERROR = SetPGABypass(Temp);
sandeepmalladi 0:90cd7e5e24af 662 break;
sandeepmalladi 0:90cd7e5e24af 663 case 1:
sandeepmalladi 0:90cd7e5e24af 664 dERROR = SetPGABypass(Temp + ADS1220_PGA_BYPASS);
sandeepmalladi 0:90cd7e5e24af 665 break;
sandeepmalladi 0:90cd7e5e24af 666 default:
sandeepmalladi 0:90cd7e5e24af 667 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 668 break;
sandeepmalladi 0:90cd7e5e24af 669
sandeepmalladi 0:90cd7e5e24af 670 }
sandeepmalladi 0:90cd7e5e24af 671
sandeepmalladi 0:90cd7e5e24af 672 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 673 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 674
sandeepmalladi 0:90cd7e5e24af 675 }
sandeepmalladi 0:90cd7e5e24af 676
sandeepmalladi 0:90cd7e5e24af 677 void ADS1220::set_DR(char c)
sandeepmalladi 0:90cd7e5e24af 678 {
sandeepmalladi 0:90cd7e5e24af 679 int spd = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 680 int dERROR;
sandeepmalladi 0:90cd7e5e24af 681 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 682
sandeepmalladi 0:90cd7e5e24af 683 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 684 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 685 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 686
sandeepmalladi 0:90cd7e5e24af 687 Temp &= 0x1f; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 688 // Change Data rate
sandeepmalladi 0:90cd7e5e24af 689 switch(spd) {
sandeepmalladi 0:90cd7e5e24af 690 case 0:
sandeepmalladi 0:90cd7e5e24af 691 dERROR = SetDataRate(Temp + ADS1220_DR_20);
sandeepmalladi 0:90cd7e5e24af 692 break;
sandeepmalladi 0:90cd7e5e24af 693 case 1:
sandeepmalladi 0:90cd7e5e24af 694 dERROR = SetDataRate(Temp + ADS1220_DR_45);
sandeepmalladi 0:90cd7e5e24af 695 break;
sandeepmalladi 0:90cd7e5e24af 696 case 2:
sandeepmalladi 0:90cd7e5e24af 697 dERROR = SetDataRate(Temp + ADS1220_DR_90);
sandeepmalladi 0:90cd7e5e24af 698 break;
sandeepmalladi 0:90cd7e5e24af 699 case 3:
sandeepmalladi 0:90cd7e5e24af 700 dERROR = SetDataRate(Temp + ADS1220_DR_175);
sandeepmalladi 0:90cd7e5e24af 701 break;
sandeepmalladi 0:90cd7e5e24af 702 case 4:
sandeepmalladi 0:90cd7e5e24af 703 dERROR = SetDataRate(Temp + ADS1220_DR_330);
sandeepmalladi 0:90cd7e5e24af 704 break;
sandeepmalladi 0:90cd7e5e24af 705 case 5:
sandeepmalladi 0:90cd7e5e24af 706 dERROR = SetDataRate(Temp + ADS1220_DR_600);
sandeepmalladi 0:90cd7e5e24af 707 break;
sandeepmalladi 0:90cd7e5e24af 708 case 6:
sandeepmalladi 0:90cd7e5e24af 709 dERROR = SetDataRate(Temp + ADS1220_DR_1000);
sandeepmalladi 0:90cd7e5e24af 710 break;
sandeepmalladi 0:90cd7e5e24af 711 case 7:
sandeepmalladi 0:90cd7e5e24af 712 dERROR = SetDataRate(Temp + ADS1220_DR_1000);
sandeepmalladi 0:90cd7e5e24af 713 break;
sandeepmalladi 0:90cd7e5e24af 714 default:
sandeepmalladi 0:90cd7e5e24af 715 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 716 break;
sandeepmalladi 0:90cd7e5e24af 717 }
sandeepmalladi 0:90cd7e5e24af 718
sandeepmalladi 0:90cd7e5e24af 719 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 720 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 721
sandeepmalladi 0:90cd7e5e24af 722 }
sandeepmalladi 0:90cd7e5e24af 723
sandeepmalladi 0:90cd7e5e24af 724 void ADS1220::set_MODE(char c)
sandeepmalladi 0:90cd7e5e24af 725 {
sandeepmalladi 0:90cd7e5e24af 726 int spd = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 727 int dERROR;
sandeepmalladi 0:90cd7e5e24af 728 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 729
sandeepmalladi 0:90cd7e5e24af 730 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 731 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 732 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 733
sandeepmalladi 0:90cd7e5e24af 734 Temp &= 0xe7; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 735 // Change Data rate
sandeepmalladi 0:90cd7e5e24af 736 switch(spd) {
sandeepmalladi 0:90cd7e5e24af 737 case 0:
sandeepmalladi 0:90cd7e5e24af 738 dERROR = SetClockMode(Temp + ADS1220_MODE_NORMAL);
sandeepmalladi 0:90cd7e5e24af 739 break;
sandeepmalladi 0:90cd7e5e24af 740 case 1:
sandeepmalladi 0:90cd7e5e24af 741 dERROR = SetClockMode(Temp + ADS1220_MODE_DUTY);
sandeepmalladi 0:90cd7e5e24af 742 break;
sandeepmalladi 0:90cd7e5e24af 743 case 2:
sandeepmalladi 0:90cd7e5e24af 744 dERROR = SetClockMode(Temp + ADS1220_MODE_TURBO);
sandeepmalladi 0:90cd7e5e24af 745 break;
sandeepmalladi 0:90cd7e5e24af 746 case 3:
sandeepmalladi 0:90cd7e5e24af 747 dERROR = SetClockMode(Temp + ADS1220_MODE_DCT);
sandeepmalladi 0:90cd7e5e24af 748 break;
sandeepmalladi 0:90cd7e5e24af 749 default:
sandeepmalladi 0:90cd7e5e24af 750 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 751 break;
sandeepmalladi 0:90cd7e5e24af 752
sandeepmalladi 0:90cd7e5e24af 753 }
sandeepmalladi 0:90cd7e5e24af 754
sandeepmalladi 0:90cd7e5e24af 755 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 756 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 757
sandeepmalladi 0:90cd7e5e24af 758 }
sandeepmalladi 0:90cd7e5e24af 759
sandeepmalladi 0:90cd7e5e24af 760 void ADS1220::set_CM(char c)
sandeepmalladi 0:90cd7e5e24af 761 {
sandeepmalladi 0:90cd7e5e24af 762 int pwrdn = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 763 int dERROR;
sandeepmalladi 0:90cd7e5e24af 764 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 765
sandeepmalladi 0:90cd7e5e24af 766 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 767 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 768 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 769
sandeepmalladi 0:90cd7e5e24af 770 Temp &= 0xfb; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 771 // Change power down mode
sandeepmalladi 0:90cd7e5e24af 772 switch(pwrdn) {
sandeepmalladi 0:90cd7e5e24af 773 case 0:
sandeepmalladi 0:90cd7e5e24af 774 dERROR = SetPowerDown(Temp);
sandeepmalladi 0:90cd7e5e24af 775 break;
sandeepmalladi 0:90cd7e5e24af 776 case 1:
sandeepmalladi 0:90cd7e5e24af 777 dERROR = SetPowerDown(Temp + ADS1220_CC);
sandeepmalladi 0:90cd7e5e24af 778 break;
sandeepmalladi 0:90cd7e5e24af 779 default:
sandeepmalladi 0:90cd7e5e24af 780 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 781 break;
sandeepmalladi 0:90cd7e5e24af 782
sandeepmalladi 0:90cd7e5e24af 783 }
sandeepmalladi 0:90cd7e5e24af 784
sandeepmalladi 0:90cd7e5e24af 785 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 786 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 787
sandeepmalladi 0:90cd7e5e24af 788 }
sandeepmalladi 0:90cd7e5e24af 789
sandeepmalladi 0:90cd7e5e24af 790 void ADS1220::set_TS(char c)
sandeepmalladi 0:90cd7e5e24af 791 {
sandeepmalladi 0:90cd7e5e24af 792 int tmp = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 793 int dERROR;
sandeepmalladi 0:90cd7e5e24af 794 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 795
sandeepmalladi 0:90cd7e5e24af 796 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 797 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 798 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 799
sandeepmalladi 0:90cd7e5e24af 800 Temp &= 0xfd; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 801 // Change Temp Diode Setting
sandeepmalladi 0:90cd7e5e24af 802 switch(tmp) {
sandeepmalladi 0:90cd7e5e24af 803 case 0:
sandeepmalladi 0:90cd7e5e24af 804 dERROR = SetTemperatureMode(Temp);
sandeepmalladi 0:90cd7e5e24af 805 break;
sandeepmalladi 0:90cd7e5e24af 806 case 1:
sandeepmalladi 0:90cd7e5e24af 807 dERROR = SetTemperatureMode(Temp + ADS1220_TEMP_SENSOR);
sandeepmalladi 0:90cd7e5e24af 808 break;
sandeepmalladi 0:90cd7e5e24af 809 default:
sandeepmalladi 0:90cd7e5e24af 810 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 811 break;
sandeepmalladi 0:90cd7e5e24af 812
sandeepmalladi 0:90cd7e5e24af 813 }
sandeepmalladi 0:90cd7e5e24af 814
sandeepmalladi 0:90cd7e5e24af 815 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 816 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 817
sandeepmalladi 0:90cd7e5e24af 818 }
sandeepmalladi 0:90cd7e5e24af 819
sandeepmalladi 0:90cd7e5e24af 820 void ADS1220::set_BCS(char c)
sandeepmalladi 0:90cd7e5e24af 821 {
sandeepmalladi 0:90cd7e5e24af 822 int bo = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 823 int dERROR;
sandeepmalladi 0:90cd7e5e24af 824 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 825
sandeepmalladi 0:90cd7e5e24af 826 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 827 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 828 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 829
sandeepmalladi 0:90cd7e5e24af 830 Temp &= 0xfe; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 831 // Change PGA Bypass
sandeepmalladi 0:90cd7e5e24af 832 switch(bo) {
sandeepmalladi 0:90cd7e5e24af 833 case 0:
sandeepmalladi 0:90cd7e5e24af 834 dERROR = SetBurnOutSource(Temp);
sandeepmalladi 0:90cd7e5e24af 835 break;
sandeepmalladi 0:90cd7e5e24af 836 case 1:
sandeepmalladi 0:90cd7e5e24af 837 dERROR = SetBurnOutSource(Temp + ADS1220_BCS);
sandeepmalladi 0:90cd7e5e24af 838 break;
sandeepmalladi 0:90cd7e5e24af 839 default:
sandeepmalladi 0:90cd7e5e24af 840 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 841 break;
sandeepmalladi 0:90cd7e5e24af 842
sandeepmalladi 0:90cd7e5e24af 843 }
sandeepmalladi 0:90cd7e5e24af 844
sandeepmalladi 0:90cd7e5e24af 845 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 846 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 847
sandeepmalladi 0:90cd7e5e24af 848 }
sandeepmalladi 0:90cd7e5e24af 849
sandeepmalladi 0:90cd7e5e24af 850 void ADS1220::set_VREF(char c)
sandeepmalladi 0:90cd7e5e24af 851 {
sandeepmalladi 0:90cd7e5e24af 852 int ref = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 853 int dERROR;
sandeepmalladi 0:90cd7e5e24af 854 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 855
sandeepmalladi 0:90cd7e5e24af 856 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 857 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 858 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 859
sandeepmalladi 0:90cd7e5e24af 860 Temp &= 0x3f; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 861 // Change Reference
sandeepmalladi 0:90cd7e5e24af 862 switch(ref) {
sandeepmalladi 0:90cd7e5e24af 863 case 0:
sandeepmalladi 0:90cd7e5e24af 864 dERROR = SetVoltageReference(Temp + ADS1220_VREF_INT);
sandeepmalladi 0:90cd7e5e24af 865 break;
sandeepmalladi 0:90cd7e5e24af 866 case 1:
sandeepmalladi 0:90cd7e5e24af 867 dERROR = SetVoltageReference(Temp + ADS1220_VREF_EX_DED);
sandeepmalladi 0:90cd7e5e24af 868 break;
sandeepmalladi 0:90cd7e5e24af 869 case 2:
sandeepmalladi 0:90cd7e5e24af 870 dERROR = SetVoltageReference(Temp + ADS1220_VREF_EX_AIN);
sandeepmalladi 0:90cd7e5e24af 871 break;
sandeepmalladi 0:90cd7e5e24af 872 case 3:
sandeepmalladi 0:90cd7e5e24af 873 dERROR = SetVoltageReference(Temp + ADS1220_VREF_SUPPLY);
sandeepmalladi 0:90cd7e5e24af 874 break;
sandeepmalladi 0:90cd7e5e24af 875 default:
sandeepmalladi 0:90cd7e5e24af 876 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 877 break;
sandeepmalladi 0:90cd7e5e24af 878
sandeepmalladi 0:90cd7e5e24af 879 }
sandeepmalladi 0:90cd7e5e24af 880
sandeepmalladi 0:90cd7e5e24af 881 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 882 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 883
sandeepmalladi 0:90cd7e5e24af 884 }
sandeepmalladi 0:90cd7e5e24af 885 void ADS1220::set_50_60(char c)
sandeepmalladi 0:90cd7e5e24af 886 {
sandeepmalladi 0:90cd7e5e24af 887 int flt = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 888 int dERROR;
sandeepmalladi 0:90cd7e5e24af 889 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 890
sandeepmalladi 0:90cd7e5e24af 891 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 892 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 893 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 894
sandeepmalladi 0:90cd7e5e24af 895 Temp &= 0xcf; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 896 // Change Filter
sandeepmalladi 0:90cd7e5e24af 897 switch(flt) {
sandeepmalladi 0:90cd7e5e24af 898 case 0:
sandeepmalladi 0:90cd7e5e24af 899 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_OFF);
sandeepmalladi 0:90cd7e5e24af 900 break;
sandeepmalladi 0:90cd7e5e24af 901 case 1:
sandeepmalladi 0:90cd7e5e24af 902 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_BOTH);
sandeepmalladi 0:90cd7e5e24af 903 break;
sandeepmalladi 0:90cd7e5e24af 904 case 2:
sandeepmalladi 0:90cd7e5e24af 905 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_50);
sandeepmalladi 0:90cd7e5e24af 906 break;
sandeepmalladi 0:90cd7e5e24af 907 case 3:
sandeepmalladi 0:90cd7e5e24af 908 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_60);
sandeepmalladi 0:90cd7e5e24af 909 break;
sandeepmalladi 0:90cd7e5e24af 910 default:
sandeepmalladi 0:90cd7e5e24af 911 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 912 break;
sandeepmalladi 0:90cd7e5e24af 913
sandeepmalladi 0:90cd7e5e24af 914 }
sandeepmalladi 0:90cd7e5e24af 915
sandeepmalladi 0:90cd7e5e24af 916 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 917 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 918
sandeepmalladi 0:90cd7e5e24af 919 }
sandeepmalladi 0:90cd7e5e24af 920
sandeepmalladi 0:90cd7e5e24af 921 void ADS1220::set_PSW(char c)
sandeepmalladi 0:90cd7e5e24af 922 {
sandeepmalladi 0:90cd7e5e24af 923 int sw = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 924 int dERROR;
sandeepmalladi 0:90cd7e5e24af 925 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 926
sandeepmalladi 0:90cd7e5e24af 927 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 928 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 929 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 930
sandeepmalladi 0:90cd7e5e24af 931 Temp &= 0xf7; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 932 // Change power down mode
sandeepmalladi 0:90cd7e5e24af 933 switch(sw) {
sandeepmalladi 0:90cd7e5e24af 934 case 0:
sandeepmalladi 0:90cd7e5e24af 935 dERROR = SetLowSidePowerSwitch(Temp);
sandeepmalladi 0:90cd7e5e24af 936 break;
sandeepmalladi 0:90cd7e5e24af 937 case 1:
sandeepmalladi 0:90cd7e5e24af 938 dERROR = SetLowSidePowerSwitch(Temp + ADS1220_PSW_SW);
sandeepmalladi 0:90cd7e5e24af 939 break;
sandeepmalladi 0:90cd7e5e24af 940 default:
sandeepmalladi 0:90cd7e5e24af 941 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 942 break;
sandeepmalladi 0:90cd7e5e24af 943
sandeepmalladi 0:90cd7e5e24af 944 }
sandeepmalladi 0:90cd7e5e24af 945
sandeepmalladi 0:90cd7e5e24af 946 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 947 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 948
sandeepmalladi 0:90cd7e5e24af 949 }
sandeepmalladi 0:90cd7e5e24af 950
sandeepmalladi 0:90cd7e5e24af 951 void ADS1220::set_IDAC(char c)
sandeepmalladi 0:90cd7e5e24af 952 {
sandeepmalladi 0:90cd7e5e24af 953 int current = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 954 int dERROR;
sandeepmalladi 0:90cd7e5e24af 955 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 956
sandeepmalladi 0:90cd7e5e24af 957 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 958 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 959 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 960
sandeepmalladi 0:90cd7e5e24af 961 Temp &= 0xf8; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 962 // Change IDAC Current Output
sandeepmalladi 0:90cd7e5e24af 963 switch(current) {
sandeepmalladi 0:90cd7e5e24af 964 case 0:
sandeepmalladi 0:90cd7e5e24af 965 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_OFF);
sandeepmalladi 0:90cd7e5e24af 966 break;
sandeepmalladi 0:90cd7e5e24af 967 case 1:
sandeepmalladi 0:90cd7e5e24af 968 #ifdef ADS1120
sandeepmalladi 0:90cd7e5e24af 969 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_OFF);
sandeepmalladi 0:90cd7e5e24af 970 #else
sandeepmalladi 0:90cd7e5e24af 971 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_10);
sandeepmalladi 0:90cd7e5e24af 972 #endif
sandeepmalladi 0:90cd7e5e24af 973
sandeepmalladi 0:90cd7e5e24af 974 break;
sandeepmalladi 0:90cd7e5e24af 975 case 2:
sandeepmalladi 0:90cd7e5e24af 976 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_50);
sandeepmalladi 0:90cd7e5e24af 977 break;
sandeepmalladi 0:90cd7e5e24af 978 case 3:
sandeepmalladi 0:90cd7e5e24af 979 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_100);
sandeepmalladi 0:90cd7e5e24af 980 break;
sandeepmalladi 0:90cd7e5e24af 981 case 4:
sandeepmalladi 0:90cd7e5e24af 982 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_250);
sandeepmalladi 0:90cd7e5e24af 983 break;
sandeepmalladi 0:90cd7e5e24af 984 case 5:
sandeepmalladi 0:90cd7e5e24af 985 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_500);
sandeepmalladi 0:90cd7e5e24af 986 break;
sandeepmalladi 0:90cd7e5e24af 987 case 6:
sandeepmalladi 0:90cd7e5e24af 988 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_1000);
sandeepmalladi 0:90cd7e5e24af 989 break;
sandeepmalladi 0:90cd7e5e24af 990 case 7:
sandeepmalladi 0:90cd7e5e24af 991 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_2000);
sandeepmalladi 0:90cd7e5e24af 992 break;
sandeepmalladi 0:90cd7e5e24af 993 default:
sandeepmalladi 0:90cd7e5e24af 994 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 995 break;
sandeepmalladi 0:90cd7e5e24af 996
sandeepmalladi 0:90cd7e5e24af 997 }
sandeepmalladi 0:90cd7e5e24af 998
sandeepmalladi 0:90cd7e5e24af 999 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 1000 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 1001
sandeepmalladi 0:90cd7e5e24af 1002 }
sandeepmalladi 0:90cd7e5e24af 1003
sandeepmalladi 0:90cd7e5e24af 1004 void ADS1220::set_IMUX(char c, int i)
sandeepmalladi 0:90cd7e5e24af 1005 {
sandeepmalladi 0:90cd7e5e24af 1006 int mux = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 1007 int dERROR;
sandeepmalladi 0:90cd7e5e24af 1008 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 1009
sandeepmalladi 0:90cd7e5e24af 1010 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 1011 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 1012 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 1013
sandeepmalladi 0:90cd7e5e24af 1014 if (i==1) {
sandeepmalladi 0:90cd7e5e24af 1015 Temp &= 0xe3; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 1016
sandeepmalladi 0:90cd7e5e24af 1017 // Change IDAC2 MUX Output
sandeepmalladi 0:90cd7e5e24af 1018
sandeepmalladi 0:90cd7e5e24af 1019 switch(mux) {
sandeepmalladi 0:90cd7e5e24af 1020 case 0:
sandeepmalladi 0:90cd7e5e24af 1021 Temp |= ADS1220_IDAC2_OFF;
sandeepmalladi 0:90cd7e5e24af 1022 break;
sandeepmalladi 0:90cd7e5e24af 1023 case 1:
sandeepmalladi 0:90cd7e5e24af 1024 Temp |= ADS1220_IDAC2_AIN0;
sandeepmalladi 0:90cd7e5e24af 1025 break;
sandeepmalladi 0:90cd7e5e24af 1026 case 2:
sandeepmalladi 0:90cd7e5e24af 1027 Temp |= ADS1220_IDAC2_AIN1;
sandeepmalladi 0:90cd7e5e24af 1028 break;
sandeepmalladi 0:90cd7e5e24af 1029 case 3:
sandeepmalladi 0:90cd7e5e24af 1030 Temp |= ADS1220_IDAC2_AIN2;
sandeepmalladi 0:90cd7e5e24af 1031 break;
sandeepmalladi 0:90cd7e5e24af 1032 case 4:
sandeepmalladi 0:90cd7e5e24af 1033 Temp |= ADS1220_IDAC2_AIN3;
sandeepmalladi 0:90cd7e5e24af 1034 break;
sandeepmalladi 0:90cd7e5e24af 1035 case 5:
sandeepmalladi 0:90cd7e5e24af 1036 Temp |= ADS1220_IDAC2_REFP0;
sandeepmalladi 0:90cd7e5e24af 1037 break;
sandeepmalladi 0:90cd7e5e24af 1038 case 6:
sandeepmalladi 0:90cd7e5e24af 1039 Temp |= ADS1220_IDAC2_REFN0;
sandeepmalladi 0:90cd7e5e24af 1040 break;
sandeepmalladi 0:90cd7e5e24af 1041 case 7:
sandeepmalladi 0:90cd7e5e24af 1042 Temp |= ADS1220_IDAC2_REFN0;
sandeepmalladi 0:90cd7e5e24af 1043 break;
sandeepmalladi 0:90cd7e5e24af 1044 default:
sandeepmalladi 0:90cd7e5e24af 1045 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 1046 break;
sandeepmalladi 0:90cd7e5e24af 1047
sandeepmalladi 0:90cd7e5e24af 1048 }
sandeepmalladi 0:90cd7e5e24af 1049 }
sandeepmalladi 0:90cd7e5e24af 1050 else {
sandeepmalladi 0:90cd7e5e24af 1051 Temp &= 0x1f;
sandeepmalladi 0:90cd7e5e24af 1052 // Change IDAC1 MUX Output
sandeepmalladi 0:90cd7e5e24af 1053 switch(mux) {
sandeepmalladi 0:90cd7e5e24af 1054 case 0:
sandeepmalladi 0:90cd7e5e24af 1055 Temp |= ADS1220_IDAC1_OFF;
sandeepmalladi 0:90cd7e5e24af 1056 break;
sandeepmalladi 0:90cd7e5e24af 1057 case 1:
sandeepmalladi 0:90cd7e5e24af 1058 Temp |= ADS1220_IDAC1_AIN0;
sandeepmalladi 0:90cd7e5e24af 1059 break;
sandeepmalladi 0:90cd7e5e24af 1060 case 2:
sandeepmalladi 0:90cd7e5e24af 1061 Temp |= ADS1220_IDAC1_AIN1;
sandeepmalladi 0:90cd7e5e24af 1062 break;
sandeepmalladi 0:90cd7e5e24af 1063 case 3:
sandeepmalladi 0:90cd7e5e24af 1064 Temp |= ADS1220_IDAC1_AIN2;
sandeepmalladi 0:90cd7e5e24af 1065 break;
sandeepmalladi 0:90cd7e5e24af 1066 case 4:
sandeepmalladi 0:90cd7e5e24af 1067 Temp |= ADS1220_IDAC1_AIN3;
sandeepmalladi 0:90cd7e5e24af 1068 break;
sandeepmalladi 0:90cd7e5e24af 1069 case 5:
sandeepmalladi 0:90cd7e5e24af 1070 Temp |= ADS1220_IDAC1_REFP0;
sandeepmalladi 0:90cd7e5e24af 1071 break;
sandeepmalladi 0:90cd7e5e24af 1072 case 6:
sandeepmalladi 0:90cd7e5e24af 1073 Temp |= ADS1220_IDAC1_REFN0;
sandeepmalladi 0:90cd7e5e24af 1074 break;
sandeepmalladi 0:90cd7e5e24af 1075 case 7:
sandeepmalladi 0:90cd7e5e24af 1076 Temp |= ADS1220_IDAC1_REFN0;
sandeepmalladi 0:90cd7e5e24af 1077 break;
sandeepmalladi 0:90cd7e5e24af 1078 default:
sandeepmalladi 0:90cd7e5e24af 1079 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 1080 break;
sandeepmalladi 0:90cd7e5e24af 1081 }
sandeepmalladi 0:90cd7e5e24af 1082 }
sandeepmalladi 0:90cd7e5e24af 1083
sandeepmalladi 0:90cd7e5e24af 1084 if (dERROR==ADS1220_NO_ERROR)
sandeepmalladi 0:90cd7e5e24af 1085 dERROR = SetIDACRouting(Temp);
sandeepmalladi 0:90cd7e5e24af 1086
sandeepmalladi 0:90cd7e5e24af 1087 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 1088 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 1089
sandeepmalladi 0:90cd7e5e24af 1090 }
sandeepmalladi 0:90cd7e5e24af 1091
sandeepmalladi 0:90cd7e5e24af 1092 void ADS1220::set_DRDYM(char c)
sandeepmalladi 0:90cd7e5e24af 1093 {
sandeepmalladi 0:90cd7e5e24af 1094 int drdy = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 1095 int dERROR;
sandeepmalladi 0:90cd7e5e24af 1096 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 1097
sandeepmalladi 0:90cd7e5e24af 1098 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 1099 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 1100 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 1101
sandeepmalladi 0:90cd7e5e24af 1102 Temp &= 0xfd; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 1103 // Change DRDY Mode Setting
sandeepmalladi 0:90cd7e5e24af 1104 switch(drdy) {
sandeepmalladi 0:90cd7e5e24af 1105 case 0:
sandeepmalladi 0:90cd7e5e24af 1106 dERROR = SetDRDYMode(Temp);
sandeepmalladi 0:90cd7e5e24af 1107 break;
sandeepmalladi 0:90cd7e5e24af 1108 case 1:
sandeepmalladi 0:90cd7e5e24af 1109 dERROR = SetDRDYMode(Temp + ADS1220_DRDY_MODE);
sandeepmalladi 0:90cd7e5e24af 1110 break;
sandeepmalladi 0:90cd7e5e24af 1111 default:
sandeepmalladi 0:90cd7e5e24af 1112 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 1113 break;
sandeepmalladi 0:90cd7e5e24af 1114
sandeepmalladi 0:90cd7e5e24af 1115 }
sandeepmalladi 0:90cd7e5e24af 1116
sandeepmalladi 0:90cd7e5e24af 1117 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 1118 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 1119
sandeepmalladi 0:90cd7e5e24af 1120 }
sandeepmalladi 0:90cd7e5e24af 1121
sandeepmalladi 0:90cd7e5e24af 1122
sandeepmalladi 0:90cd7e5e24af 1123
sandeepmalladi 0:90cd7e5e24af 1124
sandeepmalladi 0:90cd7e5e24af 1125 void ADS1220::set_ERROR_Transmit(void)
sandeepmalladi 0:90cd7e5e24af 1126 {
sandeepmalladi 0:90cd7e5e24af 1127 /* De-initialize the SPI comunication BUS */
sandeepmalladi 0:90cd7e5e24af 1128 }
sandeepmalladi 0:90cd7e5e24af 1129
sandeepmalladi 0:90cd7e5e24af 1130 void ADS1220::set_ERROR_Receive(void)
sandeepmalladi 0:90cd7e5e24af 1131 {
sandeepmalladi 0:90cd7e5e24af 1132 /* De-initialize the SPI comunication BUS */
sandeepmalladi 0:90cd7e5e24af 1133 // serial.printf("\rSPI Failed during Reception\n\r");
sandeepmalladi 0:90cd7e5e24af 1134 }
sandeepmalladi 0:90cd7e5e24af 1135
sandeepmalladi 0:90cd7e5e24af 1136 void ADS1220::set_ERROR(void)
sandeepmalladi 0:90cd7e5e24af 1137 {
sandeepmalladi 0:90cd7e5e24af 1138 /* De-initialize the SPI comunication BUS */
sandeepmalladi 0:90cd7e5e24af 1139 //serial.printf("\rADS1220 Error\n\r");
sandeepmalladi 0:90cd7e5e24af 1140 }