| 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 |
|
| 46 |
#include "xil_io.h" |
| 47 |
#include "xparameters.h" |
| 48 |
#include "stdio.h" |
| 49 |
#include "stdlib.h" |
| 50 |
#include "system_config.h" |
| 51 |
#include "AD7193.h" |
| 52 |
|
| 53 |
volatile int rxData = 0x00; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
void WriteCommReg(char txData) |
| 63 |
{ |
| 64 |
char txBuffer[1] = {0x00}; |
| 65 |
char rxBuffer[1] = {0x00}; |
| 66 |
|
| 67 |
txBuffer[0] = txData; |
| 68 |
SPI_TransferData(SPI_BASEADDR, CommunicationsRegLen, txBuffer, CommunicationsRegLen, rxBuffer, 1); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
unsigned char ReadStatusReg(void) |
| 79 |
{ |
| 80 |
char txBuffer[1] = {0x00}; |
| 81 |
char rxBuffer[1] = {0x00}; |
| 82 |
char commValue = 0; |
| 83 |
unsigned char rxData = 0; |
| 84 |
|
| 85 |
commValue = (0 << WEN) | |
| 86 |
(1 << RnW) | |
| 87 |
(0 << RS2) | |
| 88 |
(0 << RS1) | |
| 89 |
(0 << RS0) | |
| 90 |
(0 << CREAD); |
| 91 |
|
| 92 |
WriteCommReg(commValue); |
| 93 |
|
| 94 |
txBuffer[0] = 0xFF; |
| 95 |
SPI_TransferData(SPI_BASEADDR, StatusRegLen, txBuffer, StatusRegLen, rxBuffer, 1); |
| 96 |
rxData = rxBuffer[0]; |
| 97 |
|
| 98 |
return(rxData); |
| 99 |
} |
| 100 |
|
| 101 |
unsigned char WaitForReadyBit(void) |
| 102 |
{ |
| 103 |
unsigned char rxData = 0x00; |
| 104 |
|
| 105 |
rxData = ((ReadStatusReg() & (1 << RDY)) >> RDY); |
| 106 |
|
| 107 |
return(rxData); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
void WriteModeReg(int txData) |
| 118 |
{ |
| 119 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 120 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 121 |
char commValue = 0x00; |
| 122 |
|
| 123 |
commValue = (0 << WEN) | |
| 124 |
(0 << RnW) | |
| 125 |
(0 << RS2) | |
| 126 |
(0 << RS1) | |
| 127 |
(1 << RS0) | |
| 128 |
(0 << CREAD); |
| 129 |
|
| 130 |
WriteCommReg(commValue); |
| 131 |
|
| 132 |
txBuffer[0] = (txData & 0xFF0000) >> 16; |
| 133 |
txBuffer[1] = (txData & 0x00FF00) >> 8; |
| 134 |
txBuffer[2] = (txData & 0x0000FF); |
| 135 |
|
| 136 |
SPI_TransferData(SPI_BASEADDR, ModeRegLen, txBuffer, ModeRegLen, rxBuffer, 1); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
unsigned int ReadModeReg(void) |
| 147 |
{ |
| 148 |
unsigned int rxData = 0; |
| 149 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 150 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 151 |
char commValue = 0x00; |
| 152 |
|
| 153 |
commValue = (0 << WEN) | |
| 154 |
(1 << RnW) | |
| 155 |
(0 << RS2) | |
| 156 |
(0 << RS1) | |
| 157 |
(1 << RS0) | |
| 158 |
(0 << CREAD); |
| 159 |
|
| 160 |
WriteCommReg(commValue); |
| 161 |
|
| 162 |
txBuffer[0] = 0xFF; |
| 163 |
txBuffer[1] = 0xFF; |
| 164 |
txBuffer[2] = 0xFF; |
| 165 |
|
| 166 |
SPI_TransferData(SPI_BASEADDR, ModeRegLen, txBuffer, ModeRegLen, rxBuffer, 1); |
| 167 |
|
| 168 |
rxData = ((rxBuffer[0] & 0xFF) << 16) | |
| 169 |
((rxBuffer[1] & 0xFF) << 8) | |
| 170 |
((rxBuffer[2] & 0xFF)); |
| 171 |
|
| 172 |
return(rxData); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
void WriteConfigReg(int txData) |
| 183 |
{ |
| 184 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 185 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 186 |
char commValue = 0x00; |
| 187 |
|
| 188 |
commValue = (0 << WEN) | |
| 189 |
(0 << RnW) | |
| 190 |
(0 << RS2) | |
| 191 |
(1 << RS1) | |
| 192 |
(0 << RS0) | |
| 193 |
(0 << CREAD); |
| 194 |
|
| 195 |
WriteCommReg(commValue); |
| 196 |
|
| 197 |
txBuffer[0] = (txData & 0xFF0000) >> 16; |
| 198 |
txBuffer[1] = (txData & 0x00FF00) >> 8; |
| 199 |
txBuffer[2] = (txData & 0x0000FF); |
| 200 |
|
| 201 |
SPI_TransferData(SPI_BASEADDR, ConfigurationRegLen, txBuffer, ConfigurationRegLen, rxBuffer, 1); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
unsigned int ReadConfigReg(void) |
| 212 |
{ |
| 213 |
unsigned int rxData = 0; |
| 214 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 215 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 216 |
char commValue = 0x00; |
| 217 |
|
| 218 |
commValue = (0 << WEN) | |
| 219 |
(1 << RnW) | |
| 220 |
(0 << RS2) | |
| 221 |
(1 << RS1) | |
| 222 |
(0 << RS0) | |
| 223 |
(0 << CREAD); |
| 224 |
|
| 225 |
WriteCommReg(commValue); |
| 226 |
|
| 227 |
txBuffer[0] = 0xFF; |
| 228 |
txBuffer[1] = 0xFF; |
| 229 |
txBuffer[2] = 0xFF; |
| 230 |
|
| 231 |
SPI_TransferData(SPI_BASEADDR, ConfigurationRegLen, txBuffer, ConfigurationRegLen, rxBuffer, 1); |
| 232 |
|
| 233 |
rxData = ((rxBuffer[0] & 0xFF) << 16) | |
| 234 |
((rxBuffer[1] & 0xFF) << 8) | |
| 235 |
((rxBuffer[2] & 0xFF)); |
| 236 |
|
| 237 |
return(rxData); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
unsigned int ReadDataReg(void) |
| 248 |
{ |
| 249 |
unsigned int rxData = 0; |
| 250 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 251 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 252 |
char commValue = 0x00; |
| 253 |
|
| 254 |
commValue = (0 << WEN) | |
| 255 |
(1 << RnW) | |
| 256 |
(0 << RS2) | |
| 257 |
(1 << RS1) | |
| 258 |
(1 << RS0) | |
| 259 |
(0 << CREAD); |
| 260 |
|
| 261 |
WriteCommReg(commValue); |
| 262 |
|
| 263 |
txBuffer[0] = 0xFF; |
| 264 |
txBuffer[1] = 0xFF; |
| 265 |
txBuffer[2] = 0xFF; |
| 266 |
|
| 267 |
SPI_TransferData(SPI_BASEADDR, DataRegLen, txBuffer, DataRegLen, rxBuffer, 1); |
| 268 |
|
| 269 |
rxData = ((rxBuffer[0] & 0xFF) << 16) | |
| 270 |
((rxBuffer[1] & 0xFF) << 8) | |
| 271 |
((rxBuffer[2] & 0xFF)); |
| 272 |
|
| 273 |
return(rxData); |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
unsigned int ReadDataInfoReg(void) |
| 284 |
{ |
| 285 |
unsigned int rxData = 0; |
| 286 |
char txBuffer[4] = {0x00, 0x00, 0x00, 0x00}; |
| 287 |
char rxBuffer[4] = {0x00, 0x00, 0x00, 0x00}; |
| 288 |
char commValue = 0x00; |
| 289 |
|
| 290 |
commValue = (0 << WEN) | |
| 291 |
(1 << RnW) | |
| 292 |
(0 << RS2) | |
| 293 |
(1 << RS1) | |
| 294 |
(1 << RS0) | |
| 295 |
(0 << CREAD); |
| 296 |
|
| 297 |
WriteCommReg(commValue); |
| 298 |
|
| 299 |
txBuffer[0] = 0xFF; |
| 300 |
txBuffer[1] = 0xFF; |
| 301 |
txBuffer[2] = 0xFF; |
| 302 |
txBuffer[3] = 0xFF; |
| 303 |
|
| 304 |
SPI_TransferData(SPI_BASEADDR, DataInfoRegLen, txBuffer, DataInfoRegLen, rxBuffer, 1); |
| 305 |
|
| 306 |
rxData = ((rxBuffer[0] & 0xFF) << 24) | |
| 307 |
((rxBuffer[1] & 0xFF) << 16) | |
| 308 |
((rxBuffer[2] & 0xFF) << 8) | |
| 309 |
((rxBuffer[3] & 0xFF)); |
| 310 |
|
| 311 |
return(rxData); |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
unsigned char ReadIDReg(void) |
| 322 |
{ |
| 323 |
unsigned char rxData = 0; |
| 324 |
char txBuffer[1] = {0x00}; |
| 325 |
char rxBuffer[1] = {0x00}; |
| 326 |
char commValue = 0x00; |
| 327 |
|
| 328 |
commValue = (0 << WEN) | |
| 329 |
(1 << RnW) | |
| 330 |
(1 << RS2) | |
| 331 |
(0 << RS1) | |
| 332 |
(0 << RS0) | |
| 333 |
(0 << CREAD); |
| 334 |
|
| 335 |
WriteCommReg(commValue); |
| 336 |
|
| 337 |
txBuffer[0] = 0xFF; |
| 338 |
|
| 339 |
SPI_TransferData(SPI_BASEADDR, IDRegLen, txBuffer, IDRegLen, rxBuffer, 1); |
| 340 |
|
| 341 |
rxData = rxBuffer[0]; |
| 342 |
|
| 343 |
return(rxData); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
void WriteGPOCONReg(char txData) |
| 354 |
{ |
| 355 |
char txBuffer[1] = {0x00}; |
| 356 |
char rxBuffer[1] = {0x00}; |
| 357 |
char commValue = 0x00; |
| 358 |
|
| 359 |
commValue = (0 << WEN) | |
| 360 |
(0 << RnW) | |
| 361 |
(1 << RS2) | |
| 362 |
(0 << RS1) | |
| 363 |
(1 << RS0) | |
| 364 |
(0 << CREAD); |
| 365 |
|
| 366 |
WriteCommReg(commValue); |
| 367 |
|
| 368 |
txBuffer[0] = txData; |
| 369 |
|
| 370 |
SPI_TransferData(SPI_BASEADDR, GPOCONRegLen, txBuffer, GPOCONRegLen, rxBuffer, 1); |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
unsigned char ReadGPOCONReg(void) |
| 381 |
{ |
| 382 |
unsigned char rxData = 0x00; |
| 383 |
char txBuffer[1] = {0x00}; |
| 384 |
char rxBuffer[1] = {0x00}; |
| 385 |
char commValue = 0x00; |
| 386 |
|
| 387 |
commValue = (0 << WEN) | |
| 388 |
(1 << RnW) | |
| 389 |
(1 << RS2) | |
| 390 |
(0 << RS1) | |
| 391 |
(1 << RS0) | |
| 392 |
(0 << CREAD); |
| 393 |
|
| 394 |
WriteCommReg(commValue); |
| 395 |
|
| 396 |
txBuffer[0] = 0xFF; |
| 397 |
|
| 398 |
SPI_TransferData(SPI_BASEADDR, GPOCONRegLen, txBuffer, GPOCONRegLen, rxBuffer, 1); |
| 399 |
|
| 400 |
rxData = rxBuffer[0]; |
| 401 |
|
| 402 |
return(rxData); |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
void WriteOffsetReg(int txData) |
| 413 |
{ |
| 414 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 415 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 416 |
char commValue = 0x00; |
| 417 |
|
| 418 |
commValue = (0 << WEN) | |
| 419 |
(0 << RnW) | |
| 420 |
(1 << RS2) | |
| 421 |
(1 << RS1) | |
| 422 |
(0 << RS0) | |
| 423 |
(0 << CREAD); |
| 424 |
|
| 425 |
WriteCommReg(commValue); |
| 426 |
|
| 427 |
txBuffer[0] = (txData & 0xFF0000) >> 16; |
| 428 |
txBuffer[1] = (txData & 0x00FF00) >> 8; |
| 429 |
txBuffer[2] = (txData & 0x0000FF); |
| 430 |
|
| 431 |
SPI_TransferData(SPI_BASEADDR, OffsetRegLen, txBuffer, OffsetRegLen, rxBuffer, 1); |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
unsigned int ReadOffsetReg(void) |
| 442 |
{ |
| 443 |
unsigned int rxData = 0; |
| 444 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 445 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 446 |
char commValue = 0x00; |
| 447 |
|
| 448 |
commValue = (0 << WEN) | |
| 449 |
(1 << RnW) | |
| 450 |
(1 << RS2) | |
| 451 |
(1 << RS1) | |
| 452 |
(0 << RS0) | |
| 453 |
(0 << CREAD); |
| 454 |
|
| 455 |
WriteCommReg(commValue); |
| 456 |
|
| 457 |
txBuffer[0] = 0xFF; |
| 458 |
txBuffer[1] = 0xFF; |
| 459 |
txBuffer[2] = 0xFF; |
| 460 |
|
| 461 |
SPI_TransferData(SPI_BASEADDR, OffsetRegLen, txBuffer, OffsetRegLen, rxBuffer, 1); |
| 462 |
|
| 463 |
rxData = ((rxBuffer[0] & 0xFF) << 16) | |
| 464 |
((rxBuffer[1] & 0xFF) << 8) | |
| 465 |
((rxBuffer[2] & 0xFF)); |
| 466 |
|
| 467 |
return(rxData); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
void WriteFullScaleReg(int txData) |
| 478 |
{ |
| 479 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 480 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 481 |
char commValue = 0x00; |
| 482 |
|
| 483 |
commValue = (0 << WEN) | |
| 484 |
(0 << RnW) | |
| 485 |
(1 << RS2) | |
| 486 |
(1 << RS1) | |
| 487 |
(1 << RS0) | |
| 488 |
(0 << CREAD); |
| 489 |
|
| 490 |
WriteCommReg(commValue); |
| 491 |
|
| 492 |
txBuffer[0] = (txData & 0xFF0000) >> 16; |
| 493 |
txBuffer[1] = (txData & 0x00FF00) >> 8; |
| 494 |
txBuffer[2] = (txData & 0x0000FF); |
| 495 |
|
| 496 |
SPI_TransferData(SPI_BASEADDR, FullScaleRegLen, txBuffer, FullScaleRegLen, rxBuffer, 1); |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
unsigned int ReadFullScaleReg(void) |
| 507 |
{ |
| 508 |
unsigned int rxData = 0; |
| 509 |
char txBuffer[3] = {0x00, 0x00, 0x00}; |
| 510 |
char rxBuffer[3] = {0x00, 0x00, 0x00}; |
| 511 |
char commValue = 0x00; |
| 512 |
|
| 513 |
commValue = (0 << WEN) | |
| 514 |
(1 << RnW) | |
| 515 |
(1 << RS2) | |
| 516 |
(1 << RS1) | |
| 517 |
(1 << RS0) | |
| 518 |
(0 << CREAD); |
| 519 |
|
| 520 |
WriteCommReg(commValue); |
| 521 |
|
| 522 |
txBuffer[0] = 0xFF; |
| 523 |
txBuffer[1] = 0xFF; |
| 524 |
txBuffer[2] = 0xFF; |
| 525 |
|
| 526 |
SPI_TransferData(SPI_BASEADDR, FullScaleRegLen, txBuffer, FullScaleRegLen, rxBuffer, 1); |
| 527 |
|
| 528 |
rxData = ((rxBuffer[0] & 0xFF) << 16) | |
| 529 |
((rxBuffer[1] & 0xFF) << 8) | |
| 530 |
((rxBuffer[2] & 0xFF)); |
| 531 |
|
| 532 |
return(rxData); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
void AD7193_PrintValue(char mode) |
| 543 |
{ |
| 544 |
unsigned int rxData = 0; |
| 545 |
float value = 0.0; |
| 546 |
int code = 0; |
| 547 |
int whole = 0; |
| 548 |
int thousands = 0; |
| 549 |
float valueTemp = 0.0; |
| 550 |
int wholeTemp = 0; |
| 551 |
int thousandsTemp = 0; |
| 552 |
int vfs = 16777216; |
| 553 |
int vfs2 = 8388608; |
| 554 |
int channel = 0; |
| 555 |
|
| 556 |
|
| 557 |
rxData = ReadDataInfoReg(); |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
channel = rxData & 0x0000000F; |
| 562 |
|
| 563 |
code = (rxData & 0xFFFFFF00) >> 8; |
| 564 |
valueTemp = (rxData & 0xFFFFFF00) >> 8; |
| 565 |
|
| 566 |
if((mode == 1)||(mode == 3)||(mode == 5)) |
| 567 |
{ |
| 568 |
value = code * 2.5 / vfs; |
| 569 |
} |
| 570 |
else if((mode == 2)||(mode == 4)) |
| 571 |
{ |
| 572 |
value = ((code * 2.5) / vfs2) - 2.5; |
| 573 |
} |
| 574 |
|
| 575 |
if((mode == 1)||(mode == 2)||(mode == 5)) |
| 576 |
{ |
| 577 |
switch(channel) |
| 578 |
{ |
| 579 |
case 0x00: |
| 580 |
xil_printf("CH1 = "); |
| 581 |
break; |
| 582 |
case 0x01: |
| 583 |
xil_printf("CH2 = "); |
| 584 |
break; |
| 585 |
case 0x02: |
| 586 |
xil_printf("CH3 = "); |
| 587 |
break; |
| 588 |
case 0x03: |
| 589 |
xil_printf("CH4 = "); |
| 590 |
break; |
| 591 |
case 0x04: |
| 592 |
xil_printf("CH5 = "); |
| 593 |
break; |
| 594 |
case 0x05: |
| 595 |
xil_printf("CH6 = "); |
| 596 |
break; |
| 597 |
case 0x06: |
| 598 |
xil_printf("CH7 = "); |
| 599 |
break; |
| 600 |
case 0x07: |
| 601 |
xil_printf("CH8 = "); |
| 602 |
break; |
| 603 |
case 0x08: |
| 604 |
xil_printf("Temperature = "); |
| 605 |
break; |
| 606 |
default: |
| 607 |
xil_printf("Error"); |
| 608 |
break; |
| 609 |
} |
| 610 |
} |
| 611 |
else if((mode == 3)||(mode == 4)) |
| 612 |
{ |
| 613 |
switch(channel) |
| 614 |
{ |
| 615 |
case 0x00: |
| 616 |
xil_printf("CH1 = "); |
| 617 |
break; |
| 618 |
case 0x01: |
| 619 |
xil_printf("CH2 = "); |
| 620 |
break; |
| 621 |
case 0x02: |
| 622 |
xil_printf("CH3 = "); |
| 623 |
break; |
| 624 |
case 0x03: |
| 625 |
xil_printf("CH4 = "); |
| 626 |
break; |
| 627 |
default: |
| 628 |
xil_printf("Error"); |
| 629 |
break; |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
if(channel == 0x08) |
| 634 |
{ |
| 635 |
valueTemp = ((valueTemp - 0x800000) / 2815) - 273; |
| 636 |
wholeTemp = (int)valueTemp; |
| 637 |
thousandsTemp = (valueTemp - wholeTemp) * 1000; |
| 638 |
|
| 639 |
if(thousandsTemp < 10) |
| 640 |
{ |
| 641 |
xil_printf("%d.00%dC\n\r", wholeTemp,thousandsTemp); |
| 642 |
} |
| 643 |
else if(thousandsTemp < 100) |
| 644 |
{ |
| 645 |
xil_printf("%d.0%0dC\n\r", wholeTemp,thousandsTemp); |
| 646 |
} |
| 647 |
else |
| 648 |
{ |
| 649 |
xil_printf("%d.%dC\n\r", wholeTemp,thousandsTemp); |
| 650 |
} |
| 651 |
} |
| 652 |
else |
| 653 |
{ |
| 654 |
if ((rxData & 0x40) == 0x00) |
| 655 |
{ |
| 656 |
if(value < 0) |
| 657 |
{ |
| 658 |
value = value * (-1); |
| 659 |
whole = (int)value; |
| 660 |
thousands = (value - whole) * 1000; |
| 661 |
xil_printf("-"); |
| 662 |
} |
| 663 |
else |
| 664 |
{ |
| 665 |
whole = (int)value; |
| 666 |
thousands = (value - whole) * 1000; |
| 667 |
xil_printf("+"); |
| 668 |
} |
| 669 |
if(thousands < 10) |
| 670 |
{ |
| 671 |
xil_printf("%d.00%dV\n\r", whole,thousands); |
| 672 |
} |
| 673 |
else if(thousands < 100) |
| 674 |
{ |
| 675 |
xil_printf("%d.0%0dV\n\r", whole,thousands); |
| 676 |
} |
| 677 |
else |
| 678 |
{ |
| 679 |
xil_printf("%d.%dV\n\r", whole,thousands); |
| 680 |
} |
| 681 |
} |
| 682 |
else |
| 683 |
{ |
| 684 |
xil_printf("out of range\n\r"); |
| 685 |
} |
| 686 |
|
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
void AD7193_DemoMode1(void) |
| 698 |
{ |
| 699 |
int cfgValue = 0x00; |
| 700 |
int modeValue = 0x00; |
| 701 |
int nrConv = 0x00; |
| 702 |
int rxTest = 0x00; |
| 703 |
int prevCh = 0xFF; |
| 704 |
int pin; |
| 705 |
|
| 706 |
xil_printf("\n\r>>> Demo Mode 1 <<<\n\r"); |
| 707 |
xil_printf("Settings: Status Register added to Data Register\n\r"); |
| 708 |
xil_printf(" Inputs referenced to AINCOM\n\r"); |
| 709 |
xil_printf(" All 8 Inputs scanned\n\r"); |
| 710 |
xil_printf(" UNIPOLAR MODE\n\r"); |
| 711 |
xil_printf("\n\r"); |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
modeValue = (1 << DAT_STA) | |
| 716 |
(1 << CLK1) | |
| 717 |
(1 << FS6) | |
| 718 |
(1 << FS5); |
| 719 |
WriteModeReg(modeValue); |
| 720 |
|
| 721 |
|
| 722 |
cfgValue = (1 << Pseudo) | |
| 723 |
(1 << CH7) | |
| 724 |
(1 << CH6) | |
| 725 |
(1 << CH5) | |
| 726 |
(1 << CH4) | |
| 727 |
(1 << CH3) | |
| 728 |
(1 << CH2) | |
| 729 |
(1 << CH1) | |
| 730 |
(1 << CH0) | |
| 731 |
(1 << BUF) | |
| 732 |
(1 << UnB); |
| 733 |
WriteConfigReg(cfgValue); |
| 734 |
|
| 735 |
|
| 736 |
xil_printf("Demo program will make 4 conversions in this mode...\n\r"); |
| 737 |
xil_printf("Conversions remaining: 4. Press any key to start\n\r"); |
| 738 |
xil_printf("\n\r"); |
| 739 |
|
| 740 |
|
| 741 |
UartReadChar(); |
| 742 |
|
| 743 |
nrConv = 0; |
| 744 |
|
| 745 |
while(nrConv < 4) |
| 746 |
{ |
| 747 |
prevCh = 0x00; |
| 748 |
|
| 749 |
while(prevCh < 8) |
| 750 |
{ |
| 751 |
do |
| 752 |
{ |
| 753 |
pin = WaitForReadyBit(); |
| 754 |
} |
| 755 |
while(pin == 1); |
| 756 |
|
| 757 |
rxTest = ReadStatusReg(); |
| 758 |
|
| 759 |
if((rxTest & 0x0F) == prevCh) |
| 760 |
{ |
| 761 |
AD7193_PrintValue(1); |
| 762 |
prevCh++; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
if(nrConv < 0x03) |
| 767 |
{ |
| 768 |
xil_printf("\n\r"); |
| 769 |
xil_printf("Conversions remaining: %x. Press any key to continue...\n\r",3 - nrConv); |
| 770 |
xil_printf("\n\r"); |
| 771 |
|
| 772 |
|
| 773 |
UartReadChar(); |
| 774 |
} |
| 775 |
nrConv++; |
| 776 |
|
| 777 |
if(nrConv == 0x04) |
| 778 |
{ |
| 779 |
xil_printf("\n\r"); |
| 780 |
xil_printf("Demo Mode 1 Complete. Press any key to continue\n\r"); |
| 781 |
xil_printf("\n\r"); |
| 782 |
|
| 783 |
|
| 784 |
UartReadChar(); |
| 785 |
} |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
void AD7193_DemoMode3(void) |
| 797 |
{ |
| 798 |
int cfgValue = 0x00; |
| 799 |
int nrConv = 0x00; |
| 800 |
int rxTest = 0x00; |
| 801 |
int prevCh = 0xFF; |
| 802 |
int pin; |
| 803 |
|
| 804 |
xil_printf("\n\r>>> Demo Mode 3 <<<\n\r"); |
| 805 |
xil_printf("Changing settings...\n\r"); |
| 806 |
xil_printf("Settings: Status Register added to Data Register\n\r"); |
| 807 |
xil_printf(" Differential Inputs Mode\n\r"); |
| 808 |
xil_printf(" IN1-IN2 IN3-IN4 IN5-IN6 IN7-IN8 scanned\n\r"); |
| 809 |
xil_printf(" UNIPOLAR MODE\n\r"); |
| 810 |
xil_printf("\n\r"); |
| 811 |
|
| 812 |
|
| 813 |
cfgValue = (0 << Pseudo) | |
| 814 |
(0 << CH7) | |
| 815 |
(0 << CH6) | |
| 816 |
(0 << CH5) | |
| 817 |
(0 << CH4) | |
| 818 |
(1 << CH3) | |
| 819 |
(1 << CH2) | |
| 820 |
(1 << CH1) | |
| 821 |
(1 << CH0) | |
| 822 |
(1 << BUF) | |
| 823 |
(1 << UnB); |
| 824 |
WriteConfigReg(cfgValue); |
| 825 |
|
| 826 |
|
| 827 |
xil_printf("Demo program will make 4 conversions in this mode...\n\r"); |
| 828 |
xil_printf("Conversions remaining: 4. Press any key to start\n\r",3 - nrConv); |
| 829 |
xil_printf("\n\r"); |
| 830 |
|
| 831 |
|
| 832 |
UartReadChar(); |
| 833 |
|
| 834 |
while(nrConv < 4) |
| 835 |
{ |
| 836 |
prevCh = 0x00; |
| 837 |
|
| 838 |
while(prevCh < 4) |
| 839 |
{ |
| 840 |
do |
| 841 |
{ |
| 842 |
pin = WaitForReadyBit(); |
| 843 |
} |
| 844 |
while(pin == 1); |
| 845 |
|
| 846 |
rxTest = ReadStatusReg(); |
| 847 |
|
| 848 |
if((rxTest & 0x0F) == prevCh) |
| 849 |
{ |
| 850 |
AD7193_PrintValue(3); |
| 851 |
prevCh++; |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
if(nrConv < 3) |
| 856 |
{ |
| 857 |
xil_printf("\n\r"); |
| 858 |
xil_printf("Conversions remaining: %x. Press any key to continue...\n\r",3 - nrConv); |
| 859 |
xil_printf("\n\r"); |
| 860 |
|
| 861 |
UartReadChar(); |
| 862 |
} |
| 863 |
|
| 864 |
nrConv++; |
| 865 |
|
| 866 |
if(nrConv == 4) |
| 867 |
{ |
| 868 |
xil_printf("\n\r"); |
| 869 |
xil_printf("Demo Mode 3 Complete. Press any key to continue\n\r"); |
| 870 |
xil_printf("\n\r"); |
| 871 |
|
| 872 |
UartReadChar(); |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
void AD7193_DemoMode5(void) |
| 885 |
{ |
| 886 |
int cfgValue = 0x00; |
| 887 |
|
| 888 |
int pin; |
| 889 |
|
| 890 |
xil_printf("\n\r>>> Demo Mode 5 <<<\n\r"); |
| 891 |
xil_printf("Changing settings...\n\r"); |
| 892 |
xil_printf("Settings: Read internal Temperature sensor\n\r"); |
| 893 |
|
| 894 |
|
| 895 |
cfgValue = (1 << TEMP) | |
| 896 |
(0 << Pseudo) | |
| 897 |
(0 << CH7) | |
| 898 |
(0 << CH6) | |
| 899 |
(0 << CH5) | |
| 900 |
(0 << CH4) | |
| 901 |
(0 << CH3) | |
| 902 |
(0 << CH2) | |
| 903 |
(0 << CH1) | |
| 904 |
(0 << CH0) | |
| 905 |
(0 << BUF) | |
| 906 |
(0 << UnB); |
| 907 |
WriteConfigReg(cfgValue); |
| 908 |
|
| 909 |
|
| 910 |
xil_printf("Demo program will make 1 conversion in this mode...\n\r"); |
| 911 |
xil_printf("Press any key to start\n\r"); |
| 912 |
xil_printf("\n\r"); |
| 913 |
|
| 914 |
|
| 915 |
UartReadChar(); |
| 916 |
|
| 917 |
do |
| 918 |
{ |
| 919 |
pin = WaitForReadyBit(); |
| 920 |
} |
| 921 |
while(pin == 1); |
| 922 |
|
| 923 |
if((ReadStatusReg() & 0x0F) == 0x08) |
| 924 |
{ |
| 925 |
AD7193_PrintValue(5); |
| 926 |
} |
| 927 |
|
| 928 |
xil_printf("\n\r"); |
| 929 |
xil_printf("Demo Mode 5 Complete. Press any key to continue with Demo Mode 1\n\r"); |
| 930 |
xil_printf("\n\r"); |
| 931 |
|
| 932 |
UartReadChar(); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
void AD7193_DemoMode2(void) |
| 943 |
{ |
| 944 |
int cfgValue = 0x00; |
| 945 |
int modeValue = 0x00; |
| 946 |
int nrConv = 0x00; |
| 947 |
int rxTest = 0x00; |
| 948 |
int prevCh = 0xFF; |
| 949 |
int pin; |
| 950 |
|
| 951 |
xil_printf("\n\r>>> Demo Mode 2 <<<\n\r"); |
| 952 |
xil_printf("Settings: Status Register added to Data Register\n\r"); |
| 953 |
xil_printf(" Inputs referenced to AINCOM\n\r"); |
| 954 |
xil_printf(" All 8 Inputs scanned\n\r"); |
| 955 |
xil_printf(" BIPOLAR MODE\n\r"); |
| 956 |
xil_printf("\n\r"); |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
modeValue = (1 << DAT_STA) | |
| 961 |
(1 << CLK1) | |
| 962 |
(1 << FS6) | |
| 963 |
(1 << FS5); |
| 964 |
WriteModeReg(modeValue); |
| 965 |
|
| 966 |
|
| 967 |
cfgValue = (1 << Pseudo) | |
| 968 |
(1 << CH7) | |
| 969 |
(1 << CH6) | |
| 970 |
(1 << CH5) | |
| 971 |
(1 << CH4) | |
| 972 |
(1 << CH3) | |
| 973 |
(1 << CH2) | |
| 974 |
(1 << CH1) | |
| 975 |
(1 << CH0) | |
| 976 |
(1 << BUF) | |
| 977 |
(0 << UnB); |
| 978 |
WriteConfigReg(cfgValue); |
| 979 |
|
| 980 |
|
| 981 |
xil_printf("Demo program will make 4 conversions in this mode...\n\r"); |
| 982 |
xil_printf("Conversions remaining: 4. Press any key to start\n\r"); |
| 983 |
xil_printf("\n\r"); |
| 984 |
|
| 985 |
|
| 986 |
UartReadChar(); |
| 987 |
|
| 988 |
nrConv = 0; |
| 989 |
|
| 990 |
while(nrConv < 4) |
| 991 |
{ |
| 992 |
prevCh = 0x00; |
| 993 |
|
| 994 |
while(prevCh < 8) |
| 995 |
{ |
| 996 |
do |
| 997 |
{ |
| 998 |
pin = WaitForReadyBit(); |
| 999 |
} |
| 1000 |
while(pin == 1); |
| 1001 |
|
| 1002 |
rxTest = ReadStatusReg(); |
| 1003 |
|
| 1004 |
if((rxTest & 0x0F) == prevCh) |
| 1005 |
{ |
| 1006 |
AD7193_PrintValue(2); |
| 1007 |
prevCh++; |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
if(nrConv < 0x03) |
| 1012 |
{ |
| 1013 |
xil_printf("\n\r"); |
| 1014 |
xil_printf("Conversions remaining: %x. Press any key to continue...\n\r",3 - nrConv); |
| 1015 |
xil_printf("\n\r"); |
| 1016 |
|
| 1017 |
|
| 1018 |
UartReadChar(); |
| 1019 |
} |
| 1020 |
nrConv++; |
| 1021 |
|
| 1022 |
if(nrConv == 0x04) |
| 1023 |
{ |
| 1024 |
xil_printf("\n\r"); |
| 1025 |
xil_printf("Demo Mode 2 Complete. Press any key to continue\n\r"); |
| 1026 |
xil_printf("\n\r"); |
| 1027 |
|
| 1028 |
|
| 1029 |
UartReadChar(); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
void AD7193_DemoMode4(void) |
| 1042 |
{ |
| 1043 |
int cfgValue = 0x00; |
| 1044 |
int nrConv = 0x00; |
| 1045 |
int rxTest = 0x00; |
| 1046 |
int prevCh = 0xFF; |
| 1047 |
int pin; |
| 1048 |
|
| 1049 |
xil_printf("\n\r>>> Demo Mode 4 <<<\n\r"); |
| 1050 |
xil_printf("Changing settings...\n\r"); |
| 1051 |
xil_printf("Settings: Status Register added to Data Register\n\r"); |
| 1052 |
xil_printf(" Differential Inputs Mode\n\r"); |
| 1053 |
xil_printf(" IN1-IN2 IN3-IN4 IN5-IN6 IN7-IN8 scanned\n\r"); |
| 1054 |
xil_printf(" BIPOLAR MODE\n\r"); |
| 1055 |
xil_printf("\n\r"); |
| 1056 |
|
| 1057 |
|
| 1058 |
cfgValue = (0 << Pseudo) | |
| 1059 |
(0 << CH7) | |
| 1060 |
(0 << CH6) | |
| 1061 |
(0 << CH5) | |
| 1062 |
(0 << CH4) | |
| 1063 |
(1 << CH3) | |
| 1064 |
(1 << CH2) | |
| 1065 |
(1 << CH1) | |
| 1066 |
(1 << CH0) | |
| 1067 |
(1 << BUF) | |
| 1068 |
(0 << UnB); |
| 1069 |
WriteConfigReg(cfgValue); |
| 1070 |
|
| 1071 |
|
| 1072 |
xil_printf("Demo program will make 4 conversions in this mode...\n\r"); |
| 1073 |
xil_printf("Conversions remaining: 4. Press any key to start\n\r",3 - nrConv); |
| 1074 |
xil_printf("\n\r"); |
| 1075 |
|
| 1076 |
|
| 1077 |
UartReadChar(); |
| 1078 |
|
| 1079 |
while(nrConv < 4) |
| 1080 |
{ |
| 1081 |
prevCh = 0x00; |
| 1082 |
|
| 1083 |
while(prevCh < 4) |
| 1084 |
{ |
| 1085 |
do |
| 1086 |
{ |
| 1087 |
pin = WaitForReadyBit(); |
| 1088 |
} |
| 1089 |
while(pin == 1); |
| 1090 |
|
| 1091 |
rxTest = ReadStatusReg(); |
| 1092 |
|
| 1093 |
if((rxTest & 0x0F) == prevCh) |
| 1094 |
{ |
| 1095 |
AD7193_PrintValue(4); |
| 1096 |
prevCh++; |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
if(nrConv < 3) |
| 1101 |
{ |
| 1102 |
xil_printf("\n\r"); |
| 1103 |
xil_printf("Conversions remaining: %x. Press any key to continue...\n\r",3 - nrConv); |
| 1104 |
xil_printf("\n\r"); |
| 1105 |
|
| 1106 |
UartReadChar(); |
| 1107 |
} |
| 1108 |
|
| 1109 |
nrConv++; |
| 1110 |
|
| 1111 |
if(nrConv == 4) |
| 1112 |
{ |
| 1113 |
xil_printf("\n\r"); |
| 1114 |
xil_printf("Demo Mode 4 Complete. Press any key to continue\n\r"); |
| 1115 |
xil_printf("\n\r"); |
| 1116 |
|
| 1117 |
UartReadChar(); |
| 1118 |
} |
| 1119 |
} |
| 1120 |
} |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
void DemoProgram(void) |
| 1130 |
{ |
| 1131 |
xil_printf("\n\rPmodAD5 Demonstration Program\n\r\n\r"); |
| 1132 |
xil_printf(">>> Initial Register Values for AD7193 <<<\n\r"); |
| 1133 |
xil_printf("Status Register: 0x%x\n\r", ReadStatusReg()); |
| 1134 |
xil_printf("Mode Register: 0x%x\n\r",ReadModeReg()); |
| 1135 |
xil_printf("Config Register: 0x%x\n\r",ReadConfigReg()); |
| 1136 |
xil_printf("ID Register: 0x%x\n\r",ReadIDReg()); |
| 1137 |
xil_printf("GPOCON Register: 0x%x\n\r",ReadGPOCONReg()); |
| 1138 |
xil_printf("Offset Register: 0x%x\n\r",ReadOffsetReg()); |
| 1139 |
xil_printf("Full scale Register: 0x%x\n\r",ReadFullScaleReg()); |
| 1140 |
xil_printf("Press any key to continue...\n\r"); |
| 1141 |
|
| 1142 |
xil_printf("\n\r"); |
| 1143 |
|
| 1144 |
|
| 1145 |
UartReadChar(); |
| 1146 |
|
| 1147 |
while(1) |
| 1148 |
{ |
| 1149 |
AD7193_DemoMode1(); |
| 1150 |
AD7193_DemoMode2(); |
| 1151 |
AD7193_DemoMode3(); |
| 1152 |
AD7193_DemoMode4(); |
| 1153 |
AD7193_DemoMode5(); |
| 1154 |
} |
| 1155 |
} |