| 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 |
|
| 44 |
|
| 45 |
#include "Command.h" |
| 46 |
#include "Console.h" |
| 47 |
#include "cn0209.h" |
| 48 |
#include "TIME.h" |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
const struct cmd_info cmdList[] = { |
| 55 |
[0] = { |
| 56 |
.name = "help?", |
| 57 |
.description = "Displays all available commands.", |
| 58 |
.acceptedValue = "", |
| 59 |
.example = "", |
| 60 |
}, |
| 61 |
[1] = { |
| 62 |
.name = "ad7193Temp?", |
| 63 |
.description = "Displays the temperature from AD7193 device.", |
| 64 |
.acceptedValue = "", |
| 65 |
.example = "", |
| 66 |
}, |
| 67 |
[2] = { |
| 68 |
.name = "ad7193id?", |
| 69 |
.description = "Displays the AD7193 device ID.", |
| 70 |
.acceptedValue = "", |
| 71 |
.example = "", |
| 72 |
}, |
| 73 |
[3] = { |
| 74 |
.name = "ad7193Reset!", |
| 75 |
.description = "Reset the serial interface with the AD7193.", |
| 76 |
.acceptedValue = "", |
| 77 |
.example = "", |
| 78 |
}, |
| 79 |
[4] = { |
| 80 |
.name = "adt7310Temp?", |
| 81 |
.description = "Displays the temperature from ADT7310 device.", |
| 82 |
.acceptedValue = "", |
| 83 |
.example = "", |
| 84 |
}, |
| 85 |
[5] = { |
| 86 |
.name = "adt7310id?", |
| 87 |
.description = "Displays the ADT7310 device ID.", |
| 88 |
.acceptedValue = "", |
| 89 |
.example = "", |
| 90 |
}, |
| 91 |
[6] = { |
| 92 |
.name = "adt7310Reset!", |
| 93 |
.description = "Resets the serial interface with the ADT7310.", |
| 94 |
.acceptedValue = "", |
| 95 |
.example = "", |
| 96 |
}, |
| 97 |
[7] = { |
| 98 |
.name = "voltage?", |
| 99 |
.description = "Displays the input voltage on selected channel.", |
| 100 |
.acceptedValue = "Accepted values:\r\n\ |
| 101 |
\t1 - channel 1.\r\n\ |
| 102 |
\t2 - channel 2.", |
| 103 |
.example = "", |
| 104 |
}, |
| 105 |
[8] = { |
| 106 |
.name = "current?", |
| 107 |
.description = "Displays the input current on selected channel.", |
| 108 |
.acceptedValue = "Accepted values:\r\n\ |
| 109 |
\t1 - channel 1.\r\n\ |
| 110 |
\t2 - channel 2.", |
| 111 |
.example = "", |
| 112 |
}, |
| 113 |
[9] = { |
| 114 |
.name = "tempTC?", |
| 115 |
.description = "Displays the temperature detected by the thermocouple \ |
| 116 |
connected on selected channel.", |
| 117 |
.acceptedValue = "Accepted values:\r\n\ |
| 118 |
\t1 - channel 1.\r\n\ |
| 119 |
\t2 - channel 2.", |
| 120 |
.example = "", |
| 121 |
}, |
| 122 |
}; |
| 123 |
|
| 124 |
const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info)); |
| 125 |
float VREF = 4.5; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
cmdFunction cmdFunctions[] = {GetHelp,GetAd7193Temp,GetAd7193id,DoAd7193Reset, |
| 131 |
GetAdt7310Temp,GetAdt7310id,DoAdt7310Reset, |
| 132 |
GetVoltage,GetCurrent,GetTempTC}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
void GetHelp(double* param, char paramNo) |
| 140 |
{ |
| 141 |
unsigned char displayCmd; |
| 142 |
|
| 143 |
CONSOLE_Print("Available commands:\r\n"); |
| 144 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 145 |
{ |
| 146 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name, |
| 147 |
(char*)cmdList[displayCmd].description, |
| 148 |
(char*)cmdList[displayCmd].acceptedValue); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
void DisplayCmdList() |
| 158 |
{ |
| 159 |
unsigned char displayCmd; |
| 160 |
|
| 161 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 162 |
{ |
| 163 |
CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \ |
| 164 |
(char*)cmdList[displayCmd].description); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
void DisplayError(unsigned char funcNo) |
| 174 |
{ |
| 175 |
|
| 176 |
CONSOLE_Print("Invalid parameter!\r\n"); |
| 177 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \ |
| 178 |
(char*)cmdList[funcNo].description, \ |
| 179 |
(char*)cmdList[funcNo].acceptedValue); |
| 180 |
CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example); |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
char DoDeviceInit(void) |
| 193 |
{ |
| 194 |
if(CN0209_Init() == 0) |
| 195 |
{ |
| 196 |
CONSOLE_Print("Device OK\r\n"); |
| 197 |
DisplayCmdList(); |
| 198 |
return SUCCESS; |
| 199 |
} |
| 200 |
else |
| 201 |
{ |
| 202 |
CONSOLE_Print("Device Error\r\n"); |
| 203 |
return ERROR; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
void GetAd7193Temp(double* param, char paramNo) |
| 215 |
{ |
| 216 |
float temp = 0; |
| 217 |
|
| 218 |
temp = AD7193_TemperatureRead(); |
| 219 |
|
| 220 |
CONSOLE_Print("AD7193 temperature=%.2f[C].\r\n",temp); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
void GetAd7193id(double* param, char paramNo) |
| 231 |
{ |
| 232 |
unsigned long ad7193id; |
| 233 |
|
| 234 |
ad7193id = AD7193_Read(AD7193_REG_ID, 1); |
| 235 |
CONSOLE_Print("AD7193 ID = %d.\r\n",ad7193id); |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
void DoAd7193Reset(double* param, char paramNo) |
| 247 |
{ |
| 248 |
AD7193_Reset(); |
| 249 |
|
| 250 |
CONSOLE_Print("AD7193 was reset.\r\n"); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
void GetAdt7310Temp(double* param, char paramNo) |
| 261 |
{ |
| 262 |
float temp = 0; |
| 263 |
|
| 264 |
temp = ADT7310_TemperatureRead(); |
| 265 |
|
| 266 |
CONSOLE_Print("ADT7310 temperature=%.2f[C].\r\n",temp); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
void GetAdt7310id(double* param, char paramNo) |
| 277 |
{ |
| 278 |
unsigned long adt7310id; |
| 279 |
|
| 280 |
adt7310id = ADT7310_Read(ADT7310_REG_ID, 1); |
| 281 |
|
| 282 |
CONSOLE_Print("ADT7310 ID = %d.\r\n",adt7310id); |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
void DoAdt7310Reset(double* param, char paramNo) |
| 293 |
{ |
| 294 |
ADT7310_Reset(); |
| 295 |
|
| 296 |
CONSOLE_Print("ADT7310 was reset.\r\n"); |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
void GetVoltage(double* param, char paramNo) |
| 308 |
{ |
| 309 |
unsigned char channel; |
| 310 |
unsigned char switchSel; |
| 311 |
unsigned long value = 0; |
| 312 |
float voltageValue = 0; |
| 313 |
|
| 314 |
|
| 315 |
if(paramNo >= 1) |
| 316 |
{ |
| 317 |
if(param[0] < 1) |
| 318 |
{ |
| 319 |
param[0] = 1; |
| 320 |
} |
| 321 |
if(param[0] > 2) |
| 322 |
{ |
| 323 |
param[0] = 2; |
| 324 |
} |
| 325 |
channel = (unsigned char)param[0]; |
| 326 |
|
| 327 |
if (channel == 1) |
| 328 |
{ |
| 329 |
switchSel = 0x50; |
| 330 |
} |
| 331 |
else |
| 332 |
{ |
| 333 |
switchSel = 0xA0; |
| 334 |
} |
| 335 |
ADG1414_State(switchSel); |
| 336 |
AD7193_Write(AD7193_REG_CONF, 3, AD7193_CONF_PSEUDO + |
| 337 |
AD7193_CONF_CHAN(0x04) + |
| 338 |
AD7193_CONF_UNIPOLAR + |
| 339 |
AD7193_CONF_GAIN(AD7193_CONF_GAIN_1)); |
| 340 |
value = AD7193_SingleConversion(); |
| 341 |
ADG1414_State(0x0); |
| 342 |
voltageValue = (AD7193_ConvertToVolts(value,VREF,1,1)) * 1000; |
| 343 |
voltageValue = (2250000 - voltageValue); |
| 344 |
voltageValue *= 5; |
| 345 |
|
| 346 |
|
| 347 |
CONSOLE_Print("Input voltage=%d[uV] for channel %d.\r\n", |
| 348 |
(unsigned long)voltageValue, channel); |
| 349 |
} |
| 350 |
else |
| 351 |
{ |
| 352 |
|
| 353 |
DisplayError(7); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
void GetCurrent(double* param, char paramNo) |
| 365 |
{ |
| 366 |
unsigned char channel; |
| 367 |
unsigned char channelSel; |
| 368 |
unsigned long value = 0; |
| 369 |
float currentValue = 0; |
| 370 |
|
| 371 |
|
| 372 |
if(paramNo >= 1) |
| 373 |
{ |
| 374 |
if(param[0] < 1) |
| 375 |
{ |
| 376 |
param[0] = 1; |
| 377 |
} |
| 378 |
if(param[0] > 2) |
| 379 |
{ |
| 380 |
param[0] = 2; |
| 381 |
} |
| 382 |
channel = (unsigned char)param[0]; |
| 383 |
|
| 384 |
if (channel == 2) |
| 385 |
{ |
| 386 |
channelSel = 0x08; |
| 387 |
} |
| 388 |
else |
| 389 |
{ |
| 390 |
channelSel = 0x80; |
| 391 |
} |
| 392 |
|
| 393 |
ADG1414_State(0x0); |
| 394 |
AD7193_Write(AD7193_REG_CONF, 3, |
| 395 |
AD7193_CONF_PSEUDO + |
| 396 |
AD7193_CONF_CHAN(channelSel) + |
| 397 |
AD7193_CONF_UNIPOLAR + |
| 398 |
AD7193_CONF_GAIN(AD7193_CONF_GAIN_1)); |
| 399 |
|
| 400 |
value = AD7193_SingleConversion(); |
| 401 |
currentValue = AD7193_ConvertToVolts(value,VREF,1,1) * 1000; |
| 402 |
currentValue /= 200; |
| 403 |
|
| 404 |
|
| 405 |
CONSOLE_Print("Current=%.2f[uA] for channel %d.\r\n",currentValue, |
| 406 |
channel); |
| 407 |
} |
| 408 |
else |
| 409 |
{ |
| 410 |
|
| 411 |
DisplayError(8); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
void GetTempTC(double* param, char paramNo) |
| 424 |
{ |
| 425 |
unsigned char channel; |
| 426 |
unsigned char switchSel = 0; |
| 427 |
unsigned char channelSel = 0; |
| 428 |
unsigned long value = 0; |
| 429 |
float tcValue = 0; |
| 430 |
float tempRef = 0; |
| 431 |
|
| 432 |
|
| 433 |
if(paramNo >= 1) |
| 434 |
{ |
| 435 |
if(param[0] < 1) |
| 436 |
{ |
| 437 |
param[0] = 1; |
| 438 |
} |
| 439 |
if(param[0] > 2) |
| 440 |
{ |
| 441 |
param[0] = 2; |
| 442 |
} |
| 443 |
channel = (unsigned char)param[0]; |
| 444 |
|
| 445 |
if (channel == 1) |
| 446 |
{ |
| 447 |
switchSel = 0x03; |
| 448 |
channelSel = 0x01; |
| 449 |
ADG1414_State(switchSel); |
| 450 |
AD7193_Write(AD7193_REG_GPOCON, 1, AD7193_GPOCON_GP32EN + |
| 451 |
AD7193_GPOCON_P2DAT); |
| 452 |
TIME_DelayMs(100); |
| 453 |
AD7193_Write(AD7193_REG_CONF, 3, AD7193_CONF_CHAN(channelSel) + |
| 454 |
AD7193_CONF_GAIN(AD7193_CONF_GAIN_128)); |
| 455 |
TIME_DelayMs(100); |
| 456 |
} |
| 457 |
else |
| 458 |
{ |
| 459 |
switchSel = 0x0C; |
| 460 |
channelSel = 0x04; |
| 461 |
ADG1414_State(switchSel); |
| 462 |
AD7193_Write(AD7193_REG_GPOCON, 1, AD7193_GPOCON_GP32EN + |
| 463 |
AD7193_GPOCON_P3DAT); |
| 464 |
TIME_DelayMs(100); |
| 465 |
AD7193_Write(AD7193_REG_CONF, 3, AD7193_CONF_CHAN(channelSel) + |
| 466 |
AD7193_CONF_GAIN(AD7193_CONF_GAIN_128)); |
| 467 |
TIME_DelayMs(100); |
| 468 |
} |
| 469 |
|
| 470 |
value = AD7193_SingleConversion(); |
| 471 |
tcValue = AD7193_ConvertToVolts(value,VREF,128,0) * 1000; |
| 472 |
tcValue /= 40; |
| 473 |
|
| 474 |
tempRef = ADT7310_TemperatureRead(); |
| 475 |
tcValue += tempRef; |
| 476 |
|
| 477 |
AD7193_Write(AD7193_REG_GPOCON, 1, 0x0); |
| 478 |
ADG1414_State(0x0); |
| 479 |
|
| 480 |
CONSOLE_Print("TempTC=%.2f[C] for channel %d.\r\n",tcValue,channel); |
| 481 |
} |
| 482 |
else |
| 483 |
{ |
| 484 |
|
| 485 |
DisplayError(9); |
| 486 |
} |
| 487 |
} |