| 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 "AD5449.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 = "load=", |
| 63 |
.description = "Loads selected DAC input register with a given value.", |
| 64 |
.acceptedValue = "Accepted values:\r\n\ |
| 65 |
\tchannel:\r\n\ |
| 66 |
\t0 - select DAC A input register.\r\n\ |
| 67 |
\t1 - select DAC B input register.\r\n\ |
| 68 |
\tvalue:\r\n\ |
| 69 |
\t0 .. (2^DAC_Resolution)-1 - value to be written in register.", |
| 70 |
.example = "To load DAC B input register with 500, type: load=1 500", |
| 71 |
}, |
| 72 |
[2] = { |
| 73 |
.name = "loadAll=", |
| 74 |
.description = "Loads both DAC input registers.", |
| 75 |
.acceptedValue = "Accepted values:\r\n\ |
| 76 |
\t0 .. (2^DAC_Resolution)-1 - value to be written in register.", |
| 77 |
.example = "To load both DAC input registers with 3525, \ |
| 78 |
type: loadBoth=3525", |
| 79 |
}, |
| 80 |
[3] = { |
| 81 |
.name = "loadAndUpdate=", |
| 82 |
.description = "Loads and updates the selected DAC with a given value.", |
| 83 |
.acceptedValue = "Accepted values:\r\n\ |
| 84 |
\tchannel:\r\n\ |
| 85 |
\t0 - select DAC A.\r\n\ |
| 86 |
\t1 - select DAC B.\r\n\ |
| 87 |
\tvalue:\r\n\ |
| 88 |
\t0 .. (2^DAC_Resolution)-1 - value to be written in register.", |
| 89 |
.example = "To load and update DAC A with 2000, \ |
| 90 |
type: loadAndUpdate=0 2000", |
| 91 |
}, |
| 92 |
[4] = { |
| 93 |
.name = "updateAll!", |
| 94 |
.description = "Updates both DAC outputs.", |
| 95 |
.acceptedValue = "", |
| 96 |
.example = "", |
| 97 |
}, |
| 98 |
[5] = { |
| 99 |
.name = "readback?", |
| 100 |
.description = "Reads from the selected DAC register.", |
| 101 |
.acceptedValue = "Accepted values:\r\n\ |
| 102 |
\tchannel:\r\n\ |
| 103 |
\t0 - read from DAC A.\r\n\ |
| 104 |
\t1 - read from DAC B.", |
| 105 |
.example = "To read from the DAC A register, type: readback?0", |
| 106 |
}, |
| 107 |
[6] = { |
| 108 |
.name = "clearToZero!", |
| 109 |
.description = "Clears both DAC outputs to zero scale.", |
| 110 |
.acceptedValue = "", |
| 111 |
.example = "", |
| 112 |
}, |
| 113 |
[7] = { |
| 114 |
.name = "clearToMid!", |
| 115 |
.description = "Clears both DAC outputs to midscale.", |
| 116 |
.acceptedValue = "", |
| 117 |
.example = "", |
| 118 |
}, |
| 119 |
[8] = { |
| 120 |
.name = "ldacPin=", |
| 121 |
.description = "Sets the output value of LDAC pin.", |
| 122 |
.acceptedValue = "Accepted values:\r\n\ |
| 123 |
\t0 - sets LDAC pin low.(default)\r\n\ |
| 124 |
\t1 - sets LDAC pin high.", |
| 125 |
.example = "To set the LDAC pin high, type: ldacPin=1", |
| 126 |
}, |
| 127 |
[9] = { |
| 128 |
.name = "ldacPin?", |
| 129 |
.description = "Displays the value of LDAC pin.", |
| 130 |
.acceptedValue = "", |
| 131 |
.example = "", |
| 132 |
}, |
| 133 |
[10] = { |
| 134 |
.name = "clrPin=", |
| 135 |
.description = "Sets the output value of CLR pin.", |
| 136 |
.acceptedValue = "Accepted values:\r\n\ |
| 137 |
\t0 - sets CLR pin low.\r\n\ |
| 138 |
\t1 - sets CLR pin high.(default)", |
| 139 |
.example = "To set the CLR pin low, type: clrPin=0", |
| 140 |
}, |
| 141 |
[11] = { |
| 142 |
.name = "clrPin?", |
| 143 |
.description = "Displays the value of CLR pin.", |
| 144 |
.acceptedValue = "", |
| 145 |
.example = "", |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info)); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
cmdFunction cmdFunctions[12] = {GetHelp, SetLoad, SetLoadAll, SetLoadAndUpdate, |
| 155 |
SetUpdateAll, GetReadback, SetClearToZero, |
| 156 |
SetClearToMid, SetLdacPin, GetLdacPin, |
| 157 |
SetClrPin, GetClrPin}; |
| 158 |
|
| 159 |
|
| 160 |
AD5449_type_t deviceType; |
| 161 |
unsigned char ldac = 0; |
| 162 |
unsigned char clr = 1; |
| 163 |
unsigned short max_value = 0; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
void DisplayError(unsigned char funcNo) |
| 171 |
{ |
| 172 |
|
| 173 |
CONSOLE_Print("Invalid parameter!\r\n"); |
| 174 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \ |
| 175 |
(char*)cmdList[funcNo].description, \ |
| 176 |
(char*)cmdList[funcNo].acceptedValue); |
| 177 |
CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
void DisplayCmdList() |
| 186 |
{ |
| 187 |
unsigned char displayCmd; |
| 188 |
|
| 189 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 190 |
{ |
| 191 |
CONSOLE_Print("Invalid parameter!\r\n"); |
| 192 |
CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \ |
| 193 |
(char*)cmdList[displayCmd].description); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
void paramLimit(double* param, |
| 205 |
unsigned short lowerLimit, |
| 206 |
unsigned short upperLimit) |
| 207 |
{ |
| 208 |
if(*param < lowerLimit) |
| 209 |
{ |
| 210 |
*param = lowerLimit; |
| 211 |
} |
| 212 |
else |
| 213 |
{ |
| 214 |
if(*param > upperLimit) |
| 215 |
{ |
| 216 |
*param = upperLimit; |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
void GetHelp(double* param, char paramNo) |
| 227 |
{ |
| 228 |
unsigned char displayCmd; |
| 229 |
|
| 230 |
CONSOLE_Print("Available commands:\r\n"); |
| 231 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 232 |
{ |
| 233 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name, |
| 234 |
(char*)cmdList[displayCmd].description, |
| 235 |
(char*)cmdList[displayCmd].acceptedValue); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
void DoDeviceLock(void) |
| 245 |
{ |
| 246 |
char device = 0; |
| 247 |
char deviceLocked = -1; |
| 248 |
|
| 249 |
while(deviceLocked < 0) |
| 250 |
{ |
| 251 |
CONSOLE_Print("Please specify your device.\r\n\ |
| 252 |
For AD5415 type 0\r\n\ |
| 253 |
For AD5426 type 1\r\n\ |
| 254 |
For AD5429 type 2\r\n\ |
| 255 |
For AD5432 type 3\r\n\ |
| 256 |
For AD5439 type 4\r\n\ |
| 257 |
For AD5443 type 5\r\n\ |
| 258 |
For AD5449 type 6\r\n"); |
| 259 |
CONSOLE_GetCommand(&device); |
| 260 |
if((device >= 0x30) && (device <= 0x36)) |
| 261 |
{ |
| 262 |
deviceLocked = 1; |
| 263 |
switch(device) |
| 264 |
{ |
| 265 |
case 0x30 : |
| 266 |
{ |
| 267 |
deviceType = ID_AD5415; |
| 268 |
max_value = 0xFFF; |
| 269 |
break; |
| 270 |
} |
| 271 |
case 0x31 : |
| 272 |
{ |
| 273 |
deviceType = ID_AD5426; |
| 274 |
max_value = 0xFF; |
| 275 |
break; |
| 276 |
} |
| 277 |
case 0x32 : |
| 278 |
{ |
| 279 |
deviceType = ID_AD5429; |
| 280 |
max_value = 0xFF; |
| 281 |
break; |
| 282 |
} |
| 283 |
case 0x33 : |
| 284 |
{ |
| 285 |
deviceType = ID_AD5432; |
| 286 |
max_value = 0x3FF; |
| 287 |
break; |
| 288 |
} |
| 289 |
case 0x34 : |
| 290 |
{ |
| 291 |
deviceType = ID_AD5439; |
| 292 |
max_value = 0x3FF; |
| 293 |
break; |
| 294 |
} |
| 295 |
case 0x35 : |
| 296 |
{ |
| 297 |
deviceType = ID_AD5443; |
| 298 |
max_value = 0xFFF; |
| 299 |
break; |
| 300 |
} |
| 301 |
case 0x36 : |
| 302 |
{ |
| 303 |
deviceType = ID_AD5449; |
| 304 |
max_value = 0xFFF; |
| 305 |
break; |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
else |
| 310 |
{ |
| 311 |
CONSOLE_Print("Please type the number corresponding for \ |
| 312 |
your device!\r\n"); |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
char DoDeviceInit(void) |
| 327 |
{ |
| 328 |
|
| 329 |
DoDeviceLock(); |
| 330 |
|
| 331 |
if(AD5449_Init(deviceType) == 0) |
| 332 |
{ |
| 333 |
CONSOLE_Print("Device OK\r\n"); |
| 334 |
DisplayCmdList(); |
| 335 |
return SUCCESS; |
| 336 |
} |
| 337 |
else |
| 338 |
{ |
| 339 |
CONSOLE_Print("Device Error\r\n"); |
| 340 |
return ERROR; |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
void SetLoadAndUpdate(double* param, char paramNo) |
| 353 |
{ |
| 354 |
|
| 355 |
unsigned char channel = 0; |
| 356 |
unsigned short dacValue = 0; |
| 357 |
|
| 358 |
|
| 359 |
if(paramNo >= 2) |
| 360 |
{ |
| 361 |
paramLimit(¶m[0], 0, 1); |
| 362 |
paramLimit(¶m[1], 0, max_value); |
| 363 |
|
| 364 |
channel = (unsigned char)param[0]; |
| 365 |
dacValue = (unsigned short)param[1]; |
| 366 |
|
| 367 |
AD5449_LoadUpdateChannel(channel, dacValue); |
| 368 |
|
| 369 |
CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue); |
| 370 |
} |
| 371 |
else |
| 372 |
{ |
| 373 |
|
| 374 |
DisplayError(3); |
| 375 |
} |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
void SetLoad(double* param, char paramNo) |
| 388 |
{ |
| 389 |
unsigned char channel = 0; |
| 390 |
unsigned short dacValue = 0; |
| 391 |
|
| 392 |
|
| 393 |
if(paramNo >= 2) |
| 394 |
{ |
| 395 |
paramLimit(¶m[0], 0, 1); |
| 396 |
paramLimit(¶m[1], 0, max_value); |
| 397 |
|
| 398 |
channel = (unsigned char)param[0]; |
| 399 |
dacValue = (unsigned short)param[1]; |
| 400 |
|
| 401 |
AD5449_LoadChannel(channel, dacValue); |
| 402 |
|
| 403 |
CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue); |
| 404 |
} |
| 405 |
else |
| 406 |
{ |
| 407 |
|
| 408 |
DisplayError(1); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
void SetLdacPin(double* param, char paramNo) |
| 420 |
{ |
| 421 |
unsigned char status = 0; |
| 422 |
|
| 423 |
|
| 424 |
if(paramNo >= 1) |
| 425 |
{ |
| 426 |
paramLimit(¶m[0], 0, 1); |
| 427 |
|
| 428 |
status = (unsigned char) param[0]; |
| 429 |
|
| 430 |
if (status == 0) |
| 431 |
{ |
| 432 |
AD5449_LDAC_LOW; |
| 433 |
ldac = 0; |
| 434 |
} |
| 435 |
else |
| 436 |
{ |
| 437 |
if (status == 1) |
| 438 |
{ |
| 439 |
AD5449_LDAC_HIGH; |
| 440 |
ldac = 1; |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
CONSOLE_Print("%s%d\r\n",(char*)cmdList[8].name, status); |
| 445 |
} |
| 446 |
else |
| 447 |
{ |
| 448 |
|
| 449 |
DisplayError(8); |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
void SetClrPin(double* param, char paramNo) |
| 461 |
{ |
| 462 |
unsigned char status = 0; |
| 463 |
|
| 464 |
|
| 465 |
if(paramNo >= 1) |
| 466 |
{ |
| 467 |
paramLimit(¶m[0], 0, 1); |
| 468 |
|
| 469 |
status = (unsigned char) param[0]; |
| 470 |
|
| 471 |
if (status == 0) |
| 472 |
{ |
| 473 |
AD5449_CLR_LOW; |
| 474 |
clr = 0; |
| 475 |
} |
| 476 |
else |
| 477 |
{ |
| 478 |
if (status == 1) |
| 479 |
{ |
| 480 |
AD5449_CLR_HIGH; |
| 481 |
clr = 1; |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
CONSOLE_Print("%s%d\r\n",(char*)cmdList[10].name, status); |
| 486 |
} |
| 487 |
else |
| 488 |
{ |
| 489 |
|
| 490 |
DisplayError(10); |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
void GetReadback(double* param, char paramNo) |
| 502 |
{ |
| 503 |
unsigned char channel = 0; |
| 504 |
unsigned short dacValue = 0; |
| 505 |
|
| 506 |
|
| 507 |
if(paramNo >= 1) |
| 508 |
{ |
| 509 |
paramLimit(¶m[0], 0, 1); |
| 510 |
channel = (unsigned char)param[0]; |
| 511 |
dacValue = AD5449_ReadbackChannel(channel); |
| 512 |
|
| 513 |
CONSOLE_Print("register=%d for channel %d\r\n", dacValue, channel); |
| 514 |
} |
| 515 |
else |
| 516 |
{ |
| 517 |
|
| 518 |
DisplayError(5); |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
void SetLoadAll(double* param, char paramNo) |
| 530 |
{ |
| 531 |
unsigned short dacValue = 0; |
| 532 |
|
| 533 |
if((deviceType == ID_AD5426) | |
| 534 |
(deviceType == ID_AD5432) | |
| 535 |
(deviceType == ID_AD5443) ) |
| 536 |
{ |
| 537 |
CONSOLE_Print("This function is not supported \ |
| 538 |
by the current device!\n\r"); |
| 539 |
} |
| 540 |
else |
| 541 |
{ |
| 542 |
|
| 543 |
if(paramNo >= 1) |
| 544 |
{ |
| 545 |
paramLimit(¶m[0], 0, max_value); |
| 546 |
dacValue = (unsigned short)param[0]; |
| 547 |
AD5449_LoadAll(dacValue); |
| 548 |
|
| 549 |
CONSOLE_Print("value=%d\r\n", dacValue); |
| 550 |
} |
| 551 |
else |
| 552 |
{ |
| 553 |
|
| 554 |
DisplayError(2); |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
void SetUpdateAll(double* param, char paramNo) |
| 567 |
{ |
| 568 |
if((deviceType == ID_AD5426) | |
| 569 |
(deviceType == ID_AD5432) | |
| 570 |
(deviceType == ID_AD5443) ) |
| 571 |
{ |
| 572 |
CONSOLE_Print("This function is not supported \ |
| 573 |
by the current device!\n\r"); |
| 574 |
} |
| 575 |
else |
| 576 |
{ |
| 577 |
AD5449_UpdateAll(); |
| 578 |
|
| 579 |
CONSOLE_Print("Both DAC outputs were updated.\r\n"); |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
void SetClearToZero(double* param, char paramNo) |
| 591 |
{ |
| 592 |
AD5449_ClearScaleSetup(AD5449_ZERO_SCALE); |
| 593 |
|
| 594 |
CONSOLE_Print("Both DAC outputs were cleared to zero scale.\r\n"); |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
void SetClearToMid(double* param, char paramNo) |
| 605 |
{ |
| 606 |
AD5449_ClearScaleSetup(AD5449_MID_SCALE); |
| 607 |
|
| 608 |
CONSOLE_Print("Both DAC outputs were cleared to midscale.\r\n"); |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
void GetLdacPin(double* param, char paramNo) |
| 619 |
{ |
| 620 |
|
| 621 |
CONSOLE_Print("LDAC=%d\r\n",ldac); |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
void GetClrPin(double* param, char paramNo) |
| 632 |
{ |
| 633 |
|
| 634 |
CONSOLE_Print("CLR=%d\r\n",clr); |
| 635 |
} |