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