| 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 "ad5629r.h" |
| 48 |
#include "TIME.h" |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
const struct cmd_info cmdList[] = { |
| 54 |
[0] = { |
| 55 |
.name = "help?", |
| 56 |
.description = "Displays all available commands.", |
| 57 |
.acceptedValue = "", |
| 58 |
.example = "", |
| 59 |
}, |
| 60 |
[1] = { |
| 61 |
.name = "reset!", |
| 62 |
.description = "Makes a power-on reset.", |
| 63 |
.acceptedValue = "", |
| 64 |
.example = "", |
| 65 |
}, |
| 66 |
[2] = { |
| 67 |
.name = "powerMode=", |
| 68 |
.description = "Selects a given power mode for selected DAC.", |
| 69 |
.acceptedValue = "Accepted values:\r\n\ |
| 70 |
\tchannel:\r\n\ |
| 71 |
\t0 .. 7 - selected DAC A .. H.\r\n\ |
| 72 |
\tpower mode:\r\n\ |
| 73 |
\t0 - normal operation.\r\n\ |
| 74 |
\t1 - 1KOhm to GND.\r\n\ |
| 75 |
\t2 - 100KOhms to GND.\r\n\ |
| 76 |
\t3 - three-state.", |
| 77 |
.example = "To select 1KOhm to GND power mode for DAC A, type: \ |
| 78 |
powerMode=0 1", |
| 79 |
}, |
| 80 |
[3] = { |
| 81 |
.name = "powerMode?", |
| 82 |
.description = "Displays the power mode for one selected DAC.", |
| 83 |
.acceptedValue = "Accepted values:\r\n\ |
| 84 |
\tchannel:\r\n\ |
| 85 |
\t0 .. 7 - selected DAC A .. H.", |
| 86 |
.example = "To display the power mode for DAC B, type:powerMode?1", |
| 87 |
}, |
| 88 |
[4] = { |
| 89 |
.name = "intRef=", |
| 90 |
.description = "Turns on/off the internal reference.", |
| 91 |
.acceptedValue = "Accepted values:\r\n\ |
| 92 |
\t0 - turns off the internal reference.\r\n\ |
| 93 |
\t1 - turns on the internal reference.", |
| 94 |
.example = "To power on the internal reference, type: intRef=1", |
| 95 |
}, |
| 96 |
[5] = { |
| 97 |
.name = "intRef?", |
| 98 |
.description = "Displays the status of the internal reference.", |
| 99 |
.acceptedValue = "", |
| 100 |
.example = "", |
| 101 |
}, |
| 102 |
[6] = { |
| 103 |
.name = "loadN=", |
| 104 |
.description = "Loads selected DAC register with a given value.", |
| 105 |
.acceptedValue = "Accepted values:\r\n\ |
| 106 |
\tchannel:\r\n\ |
| 107 |
\t0 .. 7 - selected DAC A .. H.\r\n\ |
| 108 |
\t15 - all DACs. \r\n\ |
| 109 |
\tvalue:\r\n\ |
| 110 |
\t0 .. (2^DacResolution)-1 - value to be written in register.", |
| 111 |
.example = "To load DAC B register with 1000, type: loadN=1 1000", |
| 112 |
}, |
| 113 |
[7] = { |
| 114 |
.name = "updateN=", |
| 115 |
.description = "Updates the selected DAC with the last value written in register.", |
| 116 |
.acceptedValue = "Accepted values:\r\n\ |
| 117 |
\tchannel:\r\n\ |
| 118 |
\t0 .. 7 - selected DAC A .. H.\r\n\ |
| 119 |
\t15 - all DACs. \r\n\ |
| 120 |
\tvalue:\r\n\ |
| 121 |
\t0 .. (2^DacResolution)-1 - value to be written in register.", |
| 122 |
.example = "To update DAC H output, type: updateN=7", |
| 123 |
}, |
| 124 |
[8] = { |
| 125 |
.name = "loadNUpdateN=", |
| 126 |
.description = "Loads and updates the selected DAC with a given value.", |
| 127 |
.acceptedValue = "Accepted values:\r\n\ |
| 128 |
\tchannel:\r\n\ |
| 129 |
\t0 .. 7 - selected DAC A .. H.\r\n\ |
| 130 |
\t15 - all DACs. \r\n\ |
| 131 |
\tvalue:\r\n\ |
| 132 |
\t0 .. (2^DacResolution)-1 - value to be written in register.", |
| 133 |
.example = "To load and update DAC A with 2000, type: loadNUpdateN=0 \ |
| 134 |
2000", |
| 135 |
}, |
| 136 |
[9] = { |
| 137 |
.name = "loadNUpdateAll=", |
| 138 |
.description = "Loads the selected DAC with a given value and updates \ |
| 139 |
all DACs.", |
| 140 |
.acceptedValue = "Accepted values:\r\n\ |
| 141 |
\tchannel:\r\n\ |
| 142 |
\t0 .. 7 - selected DAC A .. H.\r\n\ |
| 143 |
\t15 - all DACs. \r\n\ |
| 144 |
\tvalue:\r\n\ |
| 145 |
\t0 .. (2^DacResolution)-1 - value to be written in register.", |
| 146 |
.example = "To load DAC C with 4000 and update all DAC outputs, type: \ |
| 147 |
loadNUpdateAll=2 4000", |
| 148 |
}, |
| 149 |
[10] = { |
| 150 |
.name = "enLdacPin=", |
| 151 |
.description = "Enables/Disables the LDAC pin for selected DAC.", |
| 152 |
.acceptedValue = "Accepted values:\r\n\ |
| 153 |
\tchannel:\r\n\ |
| 154 |
\t0 .. 7 - selected DAC A .. H.\r\n\ |
| 155 |
\tvalue:\r\n\ |
| 156 |
\t1 - disable LDAC pin.\r\n\ |
| 157 |
\t0 - enable LDAC pin.", |
| 158 |
.example = "To disable the LDAC pin for DAC H, type: enLdacPin=7 1", |
| 159 |
}, |
| 160 |
[11] = { |
| 161 |
.name = "enLdacPin?", |
| 162 |
.description = "Displays the status(enabled or disabled) of the LDAC \ |
| 163 |
pin for a selected DAC.", |
| 164 |
.acceptedValue = "Accepted values:\r\n\ |
| 165 |
\tchannel:\r\n\ |
| 166 |
\t0 .. 7 - selected DAC A .. H.", |
| 167 |
.example = "To display the status of LDAC pin for DAC D, type: \ |
| 168 |
enLdacPin?3", |
| 169 |
}, |
| 170 |
[12] = { |
| 171 |
.name = "clrCode=", |
| 172 |
.description = "Loads Clear Code Register with specific clear code.", |
| 173 |
.acceptedValue = "Accepted values:\r\n\ |
| 174 |
\t0 - clears code to zero scale when CLR pin goes from high to low.\r\n\ |
| 175 |
\t1 - clears code to midscale when CLR pin goes from high to low.\r\n\ |
| 176 |
\t2 - clears code to full scale when CLR pin goes from high to low.\r\n\ |
| 177 |
\t3 - no operation.", |
| 178 |
.example = "To set the active clear code to midscale, type: clrCode=1", |
| 179 |
}, |
| 180 |
[13] = { |
| 181 |
.name = "clrCode?", |
| 182 |
.description = "Displays the active clear code.", |
| 183 |
.acceptedValue = "", |
| 184 |
.example = "", |
| 185 |
}, |
| 186 |
[14] = { |
| 187 |
.name = "ldacPin=", |
| 188 |
.description = "Sets the output value of LDAC pin.", |
| 189 |
.acceptedValue = "Accepted values:\r\n\ |
| 190 |
\t0 - sets LDAC pin low.(default)\r\n\ |
| 191 |
\t1 - sets LDAC pin high.", |
| 192 |
.example = "To set the LDAC pin high, type: ldacPin=1", |
| 193 |
}, |
| 194 |
[15] = { |
| 195 |
.name = "ldacPin?", |
| 196 |
.description = "Displays the value of LDAC pin.", |
| 197 |
.acceptedValue = "", |
| 198 |
.example = "", |
| 199 |
}, |
| 200 |
[16] = { |
| 201 |
.name = "clrPin=", |
| 202 |
.description = "Sets the output value of CLR pin.", |
| 203 |
.acceptedValue = "Accepted values:\r\n\ |
| 204 |
\t0 - sets CLR pin low.\r\n\ |
| 205 |
\t1 - sets CLR pin high.(default)", |
| 206 |
.example = "To set the CLR pin low, type: clrPin=0", |
| 207 |
}, |
| 208 |
[17] = { |
| 209 |
.name = "clrPin?", |
| 210 |
.description = "Displays the value of CLR pin.", |
| 211 |
.acceptedValue = "", |
| 212 |
.example = "", |
| 213 |
} |
| 214 |
}; |
| 215 |
|
| 216 |
const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info)); |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
cmdFunction cmdFunctions[18] = {GetHelp, DoReset, SetPowerMode, GetPowerMode, |
| 222 |
SetIntRef,GetIntRef, SetLoadN, SetUpdateN, |
| 223 |
SetLoadNAndUpdateN, SetLoadNAndUpdateAll, |
| 224 |
SetEnLdacPin, GetEnLdacPin, SetClrCode, |
| 225 |
GetClrCode, SetLdacPin, GetLdacPin, |
| 226 |
SetClrPin, GetClrPin}; |
| 227 |
|
| 228 |
|
| 229 |
AD5629R_type deviceType; |
| 230 |
unsigned char ldac = 0; |
| 231 |
unsigned char clr = 1; |
| 232 |
unsigned short max_value = 0; |
| 233 |
unsigned char ref = 0; |
| 234 |
unsigned char clrCode = 0; |
| 235 |
unsigned char powerMode[8] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 236 |
unsigned char ldacRegVal = 0; |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
void DisplayError(unsigned char funcNo) |
| 245 |
{ |
| 246 |
|
| 247 |
CONSOLE_Print("Invalid parameter!\r\n"); |
| 248 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \ |
| 249 |
(char*)cmdList[funcNo].description, |
| 250 |
(char*)cmdList[funcNo].acceptedValue); |
| 251 |
CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
void DisplayCmdList() |
| 260 |
{ |
| 261 |
unsigned char displayCmd; |
| 262 |
|
| 263 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 264 |
{ |
| 265 |
CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \ |
| 266 |
(char*)cmdList[displayCmd].description); |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
void GetHelp(double* param, char paramNo) |
| 276 |
{ |
| 277 |
unsigned char displayCmd; |
| 278 |
|
| 279 |
CONSOLE_Print("Available commands:\r\n"); |
| 280 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 281 |
{ |
| 282 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name, |
| 283 |
(char*)cmdList[displayCmd].description, |
| 284 |
(char*)cmdList[displayCmd].acceptedValue); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
void DoDeviceLock(void) |
| 294 |
{ |
| 295 |
char device = 0; |
| 296 |
char deviceLocked = -1; |
| 297 |
|
| 298 |
while(deviceLocked < 0) |
| 299 |
{ |
| 300 |
CONSOLE_Print("Please specify your device.\r\n\ |
| 301 |
For AD5629R type: 0\r\n\ |
| 302 |
For AD5669R type: 1\r\n\ |
| 303 |
For AD5668 type: 2\r\n\ |
| 304 |
For AD5648 type: 3\r\n\ |
| 305 |
For AD5628 type: 4\r\n\ |
| 306 |
"); |
| 307 |
CONSOLE_GetCommand(&device); |
| 308 |
if((device >= 0x30) && (device <= 0x34)) |
| 309 |
{ |
| 310 |
deviceLocked = 1; |
| 311 |
switch(device) |
| 312 |
{ |
| 313 |
case 0x30 : |
| 314 |
{ |
| 315 |
deviceType = ID_AD5629R; |
| 316 |
max_value = 0xFFF; |
| 317 |
break; |
| 318 |
} |
| 319 |
case 0x31 : |
| 320 |
{ |
| 321 |
deviceType = ID_AD5669R; |
| 322 |
max_value = 0xFFFF; |
| 323 |
break; |
| 324 |
} |
| 325 |
case 0x32 : |
| 326 |
{ |
| 327 |
deviceType = ID_AD5668; |
| 328 |
max_value = 0xFFFF; |
| 329 |
break; |
| 330 |
} |
| 331 |
case 0x33 : |
| 332 |
{ |
| 333 |
deviceType = ID_AD5648; |
| 334 |
max_value = 0x3FFF; |
| 335 |
break; |
| 336 |
} |
| 337 |
case 0x34 : |
| 338 |
{ |
| 339 |
deviceType = ID_AD5628; |
| 340 |
max_value = 0xFFF; |
| 341 |
break; |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
else |
| 346 |
{ |
| 347 |
CONSOLE_Print("Please type the number corresponding for \ |
| 348 |
your device!\r\n"); |
| 349 |
} |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
char DoDeviceInit(void) |
| 363 |
{ |
| 364 |
DoDeviceLock(); |
| 365 |
|
| 366 |
if(AD5629R_Init(AD5629R_I2C_ADDR_2, deviceType) == 0) |
| 367 |
{ |
| 368 |
CONSOLE_Print("Device OK\r\n"); |
| 369 |
DisplayCmdList(); |
| 370 |
return SUCCESS; |
| 371 |
} |
| 372 |
else |
| 373 |
{ |
| 374 |
CONSOLE_Print("Device Error\r\n"); |
| 375 |
return ERROR; |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
void DoReset(double* param, char paramNo) |
| 388 |
{ |
| 389 |
AD5629R_Reset(); |
| 390 |
|
| 391 |
CONSOLE_Print("Device was reset.\r\n"); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
void SetPowerMode(double* param, char paramNo) |
| 403 |
{ |
| 404 |
|
| 405 |
unsigned char channel = 0; |
| 406 |
unsigned char mode = 0; |
| 407 |
|
| 408 |
|
| 409 |
if(paramNo >= 2) |
| 410 |
{ |
| 411 |
if(param[0] < 0) |
| 412 |
{ |
| 413 |
param[0] = 0; |
| 414 |
} |
| 415 |
else |
| 416 |
{ |
| 417 |
if(param[0] > 7) |
| 418 |
{ |
| 419 |
param[0] = 7; |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
if(param[1] < 0) |
| 424 |
{ |
| 425 |
param[1] = 0; |
| 426 |
} |
| 427 |
else |
| 428 |
{ |
| 429 |
if(param[1] > 3) |
| 430 |
{ |
| 431 |
param[1] = 3; |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
channel = (unsigned char)param[0]; |
| 436 |
mode = (unsigned char)param[1]; |
| 437 |
AD5629R_SetPowerMode((1 << channel), mode); |
| 438 |
powerMode[channel] = mode; |
| 439 |
|
| 440 |
CONSOLE_Print("channel=%d; powerMode=%d\r\n",channel, mode); |
| 441 |
} |
| 442 |
else |
| 443 |
{ |
| 444 |
|
| 445 |
DisplayError(2); |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
void GetPowerMode(double* param, char paramNo) |
| 457 |
{ |
| 458 |
unsigned char channel = 0; |
| 459 |
|
| 460 |
|
| 461 |
if(paramNo >= 1) |
| 462 |
{ |
| 463 |
if(param[0] < 0) |
| 464 |
{ |
| 465 |
param[0] = 0; |
| 466 |
} |
| 467 |
else |
| 468 |
{ |
| 469 |
if(param[0] > 7) |
| 470 |
{ |
| 471 |
param[0] = 7; |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
channel = (unsigned char)param[0]; |
| 476 |
|
| 477 |
CONSOLE_Print("channel=%d; powerMode=%d\r\n",channel, powerMode[channel]); |
| 478 |
} |
| 479 |
else |
| 480 |
{ |
| 481 |
|
| 482 |
DisplayError(3); |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
void SetIntRef(double* param, char paramNo) |
| 494 |
{ |
| 495 |
unsigned char status = 0; |
| 496 |
|
| 497 |
|
| 498 |
if(paramNo >= 1) |
| 499 |
{ |
| 500 |
if(param[0] < 0) |
| 501 |
{ |
| 502 |
param[0] = 0; |
| 503 |
} |
| 504 |
else |
| 505 |
{ |
| 506 |
if(param[0] > 1) |
| 507 |
{ |
| 508 |
param[0] = 1; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
status = (unsigned char)param[0]; |
| 513 |
AD5629R_SetRef(status); |
| 514 |
ref = status; |
| 515 |
|
| 516 |
if (status == 0) |
| 517 |
{ |
| 518 |
CONSOLE_Print("The internal reference is disabled.\r\n"); |
| 519 |
} |
| 520 |
else |
| 521 |
{ |
| 522 |
CONSOLE_Print("The internal reference is enabled.\r\n"); |
| 523 |
} |
| 524 |
} |
| 525 |
else |
| 526 |
{ |
| 527 |
|
| 528 |
DisplayError(4); |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
void GetIntRef(double* param, char paramNo) |
| 540 |
{ |
| 541 |
|
| 542 |
if (ref == 0) |
| 543 |
{ |
| 544 |
CONSOLE_Print("The internal reference is disabled.\r\n"); |
| 545 |
} |
| 546 |
else |
| 547 |
{ |
| 548 |
CONSOLE_Print("The internal reference is enabled.\r\n"); |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
void SetLoadN(double* param, char paramNo) |
| 561 |
{ |
| 562 |
|
| 563 |
unsigned char channel = 0; |
| 564 |
unsigned short dacValue = 0; |
| 565 |
|
| 566 |
|
| 567 |
if(paramNo >= 2) |
| 568 |
{ |
| 569 |
if(param[0] < 0) |
| 570 |
{ |
| 571 |
param[0] = 0; |
| 572 |
} |
| 573 |
else |
| 574 |
{ |
| 575 |
if(param[0] > 7) |
| 576 |
{ |
| 577 |
if(param[0] < 15) |
| 578 |
{ |
| 579 |
param[0] = 7; |
| 580 |
} |
| 581 |
else |
| 582 |
{ |
| 583 |
param[0] = 15; |
| 584 |
} |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
if(param[1] < 0) |
| 589 |
{ |
| 590 |
param[1] = 0; |
| 591 |
} |
| 592 |
else |
| 593 |
{ |
| 594 |
if(param[1] > max_value) |
| 595 |
{ |
| 596 |
param[1] = max_value; |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
channel = (unsigned char)param[0]; |
| 601 |
dacValue = (unsigned short)param[1]; |
| 602 |
AD5629R_WriteRegN(channel, dacValue); |
| 603 |
|
| 604 |
if (channel == 15) |
| 605 |
{ |
| 606 |
CONSOLE_Print("channel=all; value=%d\r\n", dacValue); |
| 607 |
} |
| 608 |
else |
| 609 |
{ |
| 610 |
CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue); |
| 611 |
} |
| 612 |
} |
| 613 |
else |
| 614 |
{ |
| 615 |
|
| 616 |
DisplayError(6); |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
void SetUpdateN(double* param, char paramNo) |
| 629 |
{ |
| 630 |
unsigned char channel = 0; |
| 631 |
|
| 632 |
|
| 633 |
if(paramNo >= 1) |
| 634 |
{ |
| 635 |
if(param[0] < 0) |
| 636 |
{ |
| 637 |
param[0] = 0; |
| 638 |
} |
| 639 |
else |
| 640 |
{ |
| 641 |
if(param[0] > 7) |
| 642 |
{ |
| 643 |
if(param[0] < 15) |
| 644 |
{ |
| 645 |
param[0] = 7; |
| 646 |
} |
| 647 |
else |
| 648 |
{ |
| 649 |
param[0] = 15; |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
channel = (unsigned char)param[0]; |
| 655 |
AD5629R_UpdateDacN(channel); |
| 656 |
|
| 657 |
|
| 658 |
if (channel == 15) |
| 659 |
{ |
| 660 |
CONSOLE_Print("all channels were updated\r\n"); |
| 661 |
} |
| 662 |
else |
| 663 |
{ |
| 664 |
CONSOLE_Print("channel %d was updated\r\n",channel); |
| 665 |
} |
| 666 |
} |
| 667 |
else |
| 668 |
{ |
| 669 |
|
| 670 |
DisplayError(7); |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
void SetLoadNAndUpdateN(double* param, char paramNo) |
| 683 |
{ |
| 684 |
|
| 685 |
unsigned char channel = 0; |
| 686 |
unsigned short dacValue = 0; |
| 687 |
|
| 688 |
|
| 689 |
if(paramNo >= 2) |
| 690 |
{ |
| 691 |
if(param[0] < 0) |
| 692 |
{ |
| 693 |
param[0] = 0; |
| 694 |
} |
| 695 |
else |
| 696 |
{ |
| 697 |
if(param[0] > 7) |
| 698 |
{ |
| 699 |
if(param[0] < 15) |
| 700 |
{ |
| 701 |
param[0] = 7; |
| 702 |
} |
| 703 |
else |
| 704 |
{ |
| 705 |
param[0] = 15; |
| 706 |
} |
| 707 |
} |
| 708 |
} |
| 709 |
|
| 710 |
if(param[1] < 0) |
| 711 |
{ |
| 712 |
param[1] = 0; |
| 713 |
} |
| 714 |
else |
| 715 |
{ |
| 716 |
if(param[1] > max_value) |
| 717 |
{ |
| 718 |
param[1] = max_value; |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
channel = (unsigned char)param[0]; |
| 723 |
dacValue = (unsigned short)param[1]; |
| 724 |
AD5629R_WriteRegNUpdateN(channel, dacValue); |
| 725 |
|
| 726 |
if (channel == 15) |
| 727 |
{ |
| 728 |
CONSOLE_Print("channel=all; value=%d\r\n", dacValue); |
| 729 |
} |
| 730 |
else |
| 731 |
{ |
| 732 |
CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue); |
| 733 |
} |
| 734 |
} |
| 735 |
else |
| 736 |
{ |
| 737 |
|
| 738 |
DisplayError(8); |
| 739 |
} |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
void SetLoadNAndUpdateAll(double* param, char paramNo) |
| 751 |
{ |
| 752 |
|
| 753 |
unsigned char channel = 0; |
| 754 |
unsigned short dacValue = 0; |
| 755 |
|
| 756 |
|
| 757 |
if(paramNo >= 2) |
| 758 |
{ |
| 759 |
if(param[0] < 0) |
| 760 |
{ |
| 761 |
param[0] = 0; |
| 762 |
} |
| 763 |
else |
| 764 |
{ |
| 765 |
if(param[0] > 7) |
| 766 |
{ |
| 767 |
if(param[0] < 15) |
| 768 |
{ |
| 769 |
param[0] = 7; |
| 770 |
} |
| 771 |
else |
| 772 |
{ |
| 773 |
param[0] = 15; |
| 774 |
} |
| 775 |
} |
| 776 |
} |
| 777 |
|
| 778 |
if(param[1] < 0) |
| 779 |
{ |
| 780 |
param[1] = 0; |
| 781 |
} |
| 782 |
else |
| 783 |
{ |
| 784 |
if(param[1] > max_value) |
| 785 |
{ |
| 786 |
param[1] = max_value; |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
channel = (unsigned char)param[0]; |
| 791 |
dacValue = (unsigned short)param[1]; |
| 792 |
AD5629R_WriteRegNUpdateAll(channel, dacValue); |
| 793 |
|
| 794 |
if (channel == 15) |
| 795 |
{ |
| 796 |
CONSOLE_Print("channel=all; value=%d\r\n", dacValue); |
| 797 |
} |
| 798 |
else |
| 799 |
{ |
| 800 |
CONSOLE_Print("channel=%d; value=%d\r\n",channel, dacValue); |
| 801 |
} |
| 802 |
} |
| 803 |
else |
| 804 |
{ |
| 805 |
|
| 806 |
DisplayError(9); |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
void SetEnLdacPin(double* param, char paramNo) |
| 819 |
{ |
| 820 |
|
| 821 |
unsigned char channel = 0; |
| 822 |
unsigned char status = 0; |
| 823 |
|
| 824 |
|
| 825 |
if(paramNo >= 2) |
| 826 |
{ |
| 827 |
if(param[0] < 0) |
| 828 |
{ |
| 829 |
param[0] = 0; |
| 830 |
} |
| 831 |
else |
| 832 |
{ |
| 833 |
if(param[0] > 7) |
| 834 |
{ |
| 835 |
param[0] = 7; |
| 836 |
} |
| 837 |
} |
| 838 |
|
| 839 |
if(param[1] < 0) |
| 840 |
{ |
| 841 |
param[1] = 0; |
| 842 |
} |
| 843 |
else |
| 844 |
{ |
| 845 |
if(param[1] > 1) |
| 846 |
{ |
| 847 |
param[1] = 1; |
| 848 |
} |
| 849 |
} |
| 850 |
channel = (unsigned char)param[0]; |
| 851 |
status = (unsigned short)param[1]; |
| 852 |
ldacRegVal &= ~(1 << channel); |
| 853 |
ldacRegVal |= (status == 0) ? 0 : (1 << channel); |
| 854 |
AD5629R_LoadLdacReg(ldacRegVal); |
| 855 |
|
| 856 |
|
| 857 |
if (status == 1) |
| 858 |
{ |
| 859 |
CONSOLE_Print("For channel %d, LDAC pin is disabled. It sees LDAC pin as 0.\r\n",channel); |
| 860 |
} |
| 861 |
else |
| 862 |
{ |
| 863 |
CONSOLE_Print("For channel %d, LDAC pin is enabled.\r\n",channel); |
| 864 |
} |
| 865 |
} |
| 866 |
else |
| 867 |
{ |
| 868 |
|
| 869 |
DisplayError(10); |
| 870 |
} |
| 871 |
} |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
void GetEnLdacPin(double* param, char paramNo) |
| 882 |
{ |
| 883 |
unsigned char channel = 0; |
| 884 |
|
| 885 |
|
| 886 |
if(paramNo >= 1) |
| 887 |
{ |
| 888 |
if(param[0] < 0) |
| 889 |
{ |
| 890 |
param[0] = 0; |
| 891 |
} |
| 892 |
else |
| 893 |
{ |
| 894 |
if(param[0] > 7) |
| 895 |
{ |
| 896 |
param[0] = 7; |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
channel = (unsigned char)param[0]; |
| 901 |
|
| 902 |
if (ldacRegVal & (1 << channel)) |
| 903 |
{ |
| 904 |
CONSOLE_Print("For channel %d, LDAC pin is disabled. It sees LDAC pin as 0.\r\n",channel); |
| 905 |
} |
| 906 |
else |
| 907 |
{ |
| 908 |
CONSOLE_Print("For channel %d, LDAC pin is enabled.\r\n",channel); |
| 909 |
} |
| 910 |
} |
| 911 |
else |
| 912 |
{ |
| 913 |
|
| 914 |
DisplayError(11); |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
void SetClrCode(double* param, char paramNo) |
| 926 |
{ |
| 927 |
unsigned char code = 0; |
| 928 |
|
| 929 |
|
| 930 |
if(paramNo >= 1) |
| 931 |
{ |
| 932 |
if(param[0] < 0) |
| 933 |
{ |
| 934 |
param[0] = 0; |
| 935 |
} |
| 936 |
else |
| 937 |
{ |
| 938 |
if(param[0] > 3) |
| 939 |
{ |
| 940 |
param[0] = 3; |
| 941 |
} |
| 942 |
} |
| 943 |
|
| 944 |
code = (unsigned char)param[0]; |
| 945 |
AD5629R_LoadClearCodeReg(code); |
| 946 |
clrCode = code; |
| 947 |
|
| 948 |
CONSOLE_Print("clearCode=%d\r\n",code); |
| 949 |
} |
| 950 |
else |
| 951 |
{ |
| 952 |
|
| 953 |
DisplayError(12); |
| 954 |
} |
| 955 |
} |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
void GetClrCode(double* param, char paramNo) |
| 965 |
{ |
| 966 |
|
| 967 |
CONSOLE_Print("clearCode=%d\r\n",clrCode); |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
void SetLdacPin(double* param, char paramNo) |
| 978 |
{ |
| 979 |
unsigned char status = 0; |
| 980 |
|
| 981 |
|
| 982 |
if(paramNo >= 1) |
| 983 |
{ |
| 984 |
if(param[0] < 0) |
| 985 |
{ |
| 986 |
param[0] = 0; |
| 987 |
} |
| 988 |
else |
| 989 |
{ |
| 990 |
if(param[0] > 1) |
| 991 |
{ |
| 992 |
param[0] = 1; |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
status = (unsigned char) param[0]; |
| 997 |
|
| 998 |
if (status == 0) |
| 999 |
{ |
| 1000 |
AD5629R_LDAC_LOW |
| 1001 |
ldac = 0; |
| 1002 |
} |
| 1003 |
else |
| 1004 |
{ |
| 1005 |
if (status == 1) |
| 1006 |
{ |
| 1007 |
AD5629R_LDAC_HIGH |
| 1008 |
ldac = 1; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
|
| 1013 |
CONSOLE_Print("LDAC=%d\r\n",status); |
| 1014 |
} |
| 1015 |
else |
| 1016 |
{ |
| 1017 |
|
| 1018 |
DisplayError(14); |
| 1019 |
} |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
void GetLdacPin(double* param, char paramNo) |
| 1030 |
{ |
| 1031 |
|
| 1032 |
CONSOLE_Print("LDAC=%d\r\n",ldac); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
void SetClrPin(double* param, char paramNo) |
| 1043 |
{ |
| 1044 |
unsigned char status = 0; |
| 1045 |
|
| 1046 |
|
| 1047 |
if(paramNo >= 1) |
| 1048 |
{ |
| 1049 |
if(param[0] < 0) |
| 1050 |
{ |
| 1051 |
param[0] = 0; |
| 1052 |
} |
| 1053 |
else |
| 1054 |
{ if(param[0] > 1) |
| 1055 |
{ |
| 1056 |
param[0] = 1; |
| 1057 |
} |
| 1058 |
} |
| 1059 |
|
| 1060 |
status = (unsigned char) param[0]; |
| 1061 |
|
| 1062 |
if (status == 0) |
| 1063 |
{ |
| 1064 |
AD5629R_CLR_LOW; |
| 1065 |
clr = 0; |
| 1066 |
} |
| 1067 |
else |
| 1068 |
{ |
| 1069 |
if (status == 1) |
| 1070 |
{ |
| 1071 |
AD5629R_CLR_HIGH; |
| 1072 |
clr = 1; |
| 1073 |
} |
| 1074 |
} |
| 1075 |
|
| 1076 |
|
| 1077 |
CONSOLE_Print("CLR=%d\r\n",status); |
| 1078 |
} |
| 1079 |
else |
| 1080 |
{ |
| 1081 |
|
| 1082 |
DisplayError(16); |
| 1083 |
} |
| 1084 |
} |
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
void GetClrPin(double* param, char paramNo) |
| 1094 |
{ |
| 1095 |
|
| 1096 |
CONSOLE_Print("CLR=%d\r\n",clr); |
| 1097 |
} |