Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_commands/AD9833/Command.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file Commanad.c
3 * @brief Implementation of the commands given by user through UART for AD9833.
4 * @author Lucian Sin ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2013(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
31 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 ******************************************************************************/
41
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include "Command.h"
46 #include "Console.h"
47 #include "ad9833.h"
48
49 /******************************************************************************/
50 /************************ Constants Definitions *******************************/
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 = "output=",
62 .description = "Selects the type of output.",
63 .acceptedValue = "Accepted values:\r\n\
64 \tFor AD9833 & AD9837: \r\n\
65 \t0 - Sinusoid.(default)\r\n\
66 \t1 - Triangle.\r\n\
67 \t2 - DAC Data MSB/2.\r\n\
68 \t3 - DAC Data MSB.\r\n\
69 \tFor AD9834 & AD9838: \r\n\
70 \t0 - Sinusoid.(default)\r\n\
71 \t1 - Triangle.",
72 .example = "To select the triangle output, type: output=1",
73 },
74 [2] = {
75 .name = "output?",
76 .description = "Displays the type of output.",
77 .acceptedValue = "",
78 .example = "",
79 },
80 [3] = {
81 .name = "loadFreqReg=",
82 .description = "Loads a frequency value in one selected register.",
83 .acceptedValue = "Accepted values:\r\n\
84 \tRegister number:\r\n\
85 \t0 - Frequency Register 0.\r\n\
86 \t1 - Frequency Register 1.\r\n\
87 \tValue:\r\n\
88 \tAD9833: 0 .. 12 500 000 - the frequency value in Hz.\r\n\
89 \tAD9834: 0 .. 37 500 000 - the frequency value in Hz.\r\n\
90 \tAD9837 & AD9838: 0 .. 8 000 000 - the frequency value in Hz.",
91 .example = "To load a frequency of 10KHz to register 0, type: \
92 loadFreqReg=0 10000",
93 },
94 [4] = {
95 .name = "freqRegVal?",
96 .description = "Displays the value from one selected frequency register.",
97 .acceptedValue = "Accepted values:\r\n\
98 \tRegister number:\r\n\
99 \t0 - Frequency Register 0.\r\n\
100 \t1 - Frequency Register 1.",
101 .example = "To display the value from frequency register 1, type: freqReg?1",
102 },
103 [5] = {
104 .name = "loadPhaseReg=",
105 .description = "Loads a phase value in one selected register.",
106 .acceptedValue = "Accepted values:\r\n\
107 \tRegister number:\r\n\
108 \t0 - Phase Register 0.\r\n\
109 \t1 - Phase Register 1.\r\n\
110 \tValue: 0 .. 2PI - the phase value in radians.",
111 .example = "To load a phase of 3.141 to register 0, type: \
112 loadPhaseReg=0 3.141",
113 },
114 [6] = {
115 .name = "phaseRegVal?",
116 .description = "Displays the value from one selected phase register.",
117 .acceptedValue = "Accepted values:\r\n\
118 \tRegister number:\r\n\
119 \t0 - Phase Register 0.\r\n\
120 \t1 - Phase Register 1.",
121 .example = "To display the value from phase register 1, type: phaseReg?1",
122 },
123 [7] = {
124 .name = "freqRegNo=",
125 .description = "Select the frequency register to be used.",
126 .acceptedValue = "Accepted values:\r\n\
127 \tRegister number:\r\n\
128 \t0 - Frequency Register 0.\r\n\
129 \t1 - Frequency Register 1.",
130 .example = "To select frequency register 0, type: freqRegNo=0",
131 },
132 [8] = {
133 .name = "freqRegNo?",
134 .description = "Displays the selected frequency register.",
135 .acceptedValue = "",
136 .example = "",
137 },
138 [9] = {
139 .name = "phaseRegNo=",
140 .description = "Select the phase register to be used.",
141 .acceptedValue = "Accepted values:\r\n\
142 \tRegister number:\r\n\
143 \t0 - Phase Register 0.\r\n\
144 \t1 - Phase Register 1.",
145 .example = "To select phase register 1, type: freqRegNo=1",
146 },
147 [10] = {
148 .name = "phaseRegNo?",
149 .description = "Displays the selected phase register.",
150 .acceptedValue = "",
151 .example = "",
152 },
153 [11] = {
154 .name = "sleepMode=",
155 .description = "Select one sleep mode.",
156 .acceptedValue = "Accepted values:\r\n\
157 \tSleep mode:\r\n\
158 \tSoft method(all devices):\r\n\
159 \t0 - No power-down.(default)\r\n\
160 \t1 - DAC powered down.\r\n\
161 \t2 - Internal clock disabled.\r\n\
162 \t3 - DAC powered down and Internal clock disabled.\r\n\
163 \tHard method(AD9834 & AD9838):\r\n\
164 \t0 - No power-down.(default)\r\n\
165 \t1 - DAC powered down.",
166 .example = "To select DAC powered down, type: sleepMode=1",
167 },
168 [12] = {
169 .name = "sleepMode?",
170 .description = "Displays the selected sleep mode.",
171 .acceptedValue = "",
172 .example = "",
173 },
174 [13] = {
175 .name = "program=",
176 .description = "Sets the programming method (only for AD9834 & \
177 AD9838).",
178 .acceptedValue ="Accepted values:\r\n\
179 \tMethod:\r\n\
180 \t0 - Soft programming method.(default)\r\n\
181 \t1 - Hard programming method.",
182 .example = "To set the hardware programming method, type:program=1",
183 },
184 [14] = {
185 .name = "program?",
186 .description = "Displays the programming method.",
187 .acceptedValue = "",
188 .example = "",
189 },
190 [15] = {
191 .name = "logicOut=",
192 .description = "Sets the logic output type (only for AD9834 & AD9838).",
193 .acceptedValue = "Accepted values:\r\n\
194 \tLogic output type:\r\n\
195 \t0 - High impedance.(default)\r\n\
196 \t1 - DAC data MSB/2.\r\n\
197 \t2 - DAC data MSB.\r\n\
198 \t3 - Comparator.",
199 .example = "To set the output logic type to DAC data MBS, type:logicOut=2",
200 },
201 [16] = {
202 .name = "logicOut?",
203 .description = "Displays the logic output type (only for AD9834 & \
204 AD9838).",
205 .acceptedValue = "",
206 .example = "",
207 },
208 };
209
210
211 const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info));
212 float PHASE_MAX = 6.28318530f;
213
214 /******************************************************************************/
215 /************************ Variables Definitions *******************************/
216 /******************************************************************************/
217 cmdFunction cmdFunctions[] = {GetHelp, SetOutput, GetOutput, LoadFreqReg,
218 GetFreqRegVal, LoadPhaseReg, GetPhaseRegVal,
219 SelFreqRegNo, GetFreqRegNo, SelPhaseRegNo,
220 GetPhaseRegNo, SetSleepMode, GetSleepMode,
221 SetProgram, GetProgram, SetLogicOut, GetLogicOut};
222 /* Variables holding information about the device */
223 unsigned char freqRegNo = 0; // Frequency Register value for soft programming
224 unsigned char fselPin = 0; // Frequency Bit value for hard programming
225 unsigned long freqReg[2] = {0, 0}; // Values from both Frequency Registers
226 unsigned char phaseRegNo = 0; // Phase Register value for soft programming
227 unsigned char pselPin = 0; // Phase Bit value for hard programming
228 float phaseReg[2] = {0, 0}; // Values from both Phase Registers
229 unsigned char sleepMode = 0; // Sleep Mode Register value for soft programming
230 unsigned char sleepPin = 0; // Sleep Bit value for hard programming
231 unsigned char output = 0; // Output type
232 unsigned long max_freq_out = 0; // Max output frequency for a device type
233 unsigned char program = 0; // Programming method
234 unsigned char logicOut = 0; // Logic output type
235
236 AD9833_type deviceType;
237
238 /***************************************************************************//**
239 * @brief Internal function for displaying all the command with its description.
240 *
241 * @return None.
242 *******************************************************************************/
243 void DisplayCmdList()
244 {
245 unsigned char displayCmd;
246
247 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
248 {
249 CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \
250 (char*)cmdList[displayCmd].description);
251 }
252 }
253
254 /***************************************************************************//**
255 * @brief Displays error message.
256 *
257 * @return None.
258 *******************************************************************************/
259 void DisplayError(unsigned char funcNo)
260 {
261 /* Display error messages */
262 CONSOLE_Print("Invalid parameter!\r\n");
263 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \
264 (char*)cmdList[funcNo].description, \
265 (char*)cmdList[funcNo].acceptedValue);
266 CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example);
267 }
268
269 /***************************************************************************//**
270 * @brief Sets the current device type.
271 *
272 * @return None.
273 *******************************************************************************/
274 void DoDeviceLock(void)
275 {
276 char device = 0;
277 char deviceLocked = -1;
278
279 while(deviceLocked < 0)
280 {
281 CONSOLE_Print("Please specify your device.\r\n\
282 For AD9833 type: 0\r\n\
283 For AD9834 type: 1\r\n\
284 For AD9837 type: 2\r\n\
285 For AD9838 type: 3\r\n\
286 ");
287 CONSOLE_GetCommand(&device);
288 if((device >= 0x30) && (device <= 0x33))
289 {
290 deviceLocked = 1;
291 switch(device)
292 {
293 case 0x30 :
294 {
295 deviceType = ID_AD9833;
296 max_freq_out = 25000000 / 2;
297 break;
298 }
299 case 0x31 :
300 {
301 deviceType = ID_AD9834;
302 max_freq_out = 75000000 / 2;
303 break;
304 }
305 case 0x32 :
306 {
307 deviceType = ID_AD9837;
308 max_freq_out = 16000000 / 2;
309 break;
310 }
311 case 0x33 :
312 {
313 deviceType = ID_AD9838;
314 max_freq_out = 16000000 / 2;
315 break;
316 }
317 }
318 }
319 else
320 {
321 CONSOLE_Print("Please type the number corresponding for \
322 your device!\r\n");
323 }
324 }
325 }
326
327 /***************************************************************************//**
328 * @brief Initializes the device.
329 *
330 * @return - The result of the initialization.
331 * Example: ERROR - the device was not initialized or the device
332 * is not present.
333 * SUCCES - the device was initialized and the device
334 * is present.
335 *******************************************************************************/
336 char DoDeviceInit(void)
337 {
338 DoDeviceLock();
339
340 if(AD9833_Init(deviceType) == 0)
341 {
342 CONSOLE_Print("Device OK\r\n");
343 DisplayCmdList();
344 return SUCCESS;
345 }
346 else
347 {
348 CONSOLE_Print("Device Error\r\n");
349 return ERROR;
350 }
351 }
352
353 /***************************************************************************//**
354 * @brief Displays all available commands.
355 *
356 * @return None.
357 *******************************************************************************/
358 void GetHelp(double* param, char paramNo) // "help?" command
359 {
360 unsigned char displayCmd;
361
362 CONSOLE_Print("Available commands:\r\n");
363 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
364 {
365 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name,
366 (char*)cmdList[displayCmd].description,
367 (char*)cmdList[displayCmd].acceptedValue);
368 }
369 }
370
371 /***************************************************************************//**
372 * @brief Selects the type of output.
373 *
374 * @param param[0] - type of output
375 * Example AD9833&AD9837: 0 - Sinusoid.
376 * 1 - Triangle.
377 * 2 - DAC Data MSB/2.
378 * 3 - DAC Data MSB.
379 * Example AD9834&AD9838: 0 - Sinusoid.
380 * 1 - Triangle.
381 *
382 * @return None.
383 *******************************************************************************/
384 void SetOutput(double* param, char paramNo) // "output=" command
385 {
386 char result = 0;
387
388 /* Check if the parameter is valid */
389 if(paramNo >= 1)
390 {
391 if(param[0] < 0)
392 {
393 param[0] = 0;
394 }
395 if ((deviceType == ID_AD9833) || (deviceType == ID_AD9837))
396 {
397 if(param[0] > 3)
398 {
399 param[0] = 3;
400 }
401 }
402 else
403 {
404 if ((deviceType == ID_AD9834) || (deviceType == ID_AD9838))
405 {
406 if(param[0] > 1)
407 {
408 param[0] = 1;
409 }
410 }
411 }
412 output = (unsigned char)param[0];
413 /* Set the type of output. */
414 result = AD9833_OutMode(output);
415 /* Send feedback to user */
416 if (result == 0)
417 {
418 GetOutput(NULL, 0);
419 }
420 else
421 {
422 CONSOLE_Print("Triangle output not supported by this configuration.\
423 You must disable\r\n the logic output and then choose the triangle output.\r\n");
424 output = 0;
425 }
426 }
427 else
428 {
429 /* Display error messages */
430 DisplayError(1);
431 }
432 }
433
434 /***************************************************************************//**
435 * @brief Displays the type of output.
436 *
437 * @return None.
438 *******************************************************************************/
439 void GetOutput(double* param, char paramNo) // "output?" command
440 {
441 /* Send feedback to user */
442 CONSOLE_Print("%s%d\r\n",(char*)cmdList[1].name,output);
443 }
444
445 /***************************************************************************//**
446 * @brief Loads a frequency value in one selected register.
447 *
448 * @param param[0] - register number. (0 / 1)
449 * param[1] - frequency value in Hz. (0 .. 12 500 000)
450 *
451 * @return None.
452 *******************************************************************************/
453 void LoadFreqReg(double* param, char paramNo) // "loadFreqReg=" command
454 {
455 unsigned char regNo = 0;
456 /* Check if the parameters are valid */
457 if(paramNo >= 2)
458 {
459 if(param[0] < 0)
460 {
461 param[0] = 0;
462 }
463 if(param[0] > 1)
464 {
465 param[0] = 1;
466 }
467 regNo = (unsigned char)param[0];
468
469 if(param[1] < 0)
470 {
471 param[1] = 0;
472 }
473 if(param[1] > max_freq_out)
474 {
475 param[1] = max_freq_out;
476 }
477 freqReg[regNo] = (unsigned long)param[1];
478 /* Set the desired frequency value to selected register. */
479 AD9833_SetFreq(regNo, freqReg[regNo]);
480 /* Send feedback to user */
481 CONSOLE_Print("register=%d; frequency=%d [Hz]\r\n",regNo,freqReg[regNo]);
482 }
483 else
484 {
485 /* Display error messages */
486 DisplayError(3);
487 }
488 }
489
490 /***************************************************************************//**
491 * @brief Displays the value from one selected frequency register.
492 *
493 * @param param[0] - register number. (0 / 1)
494 *
495 * @return None.
496 *******************************************************************************/
497 void GetFreqRegVal(double* param, char paramNo) // "freqRegVal?" command
498 {
499 unsigned char regNo = 0;
500 /* Check if the parameter is valid */
501 if(paramNo >= 1)
502 {
503 if(param[0] < 0)
504 {
505 param[0] = 0;
506 }
507 if(param[0] > 1)
508 {
509 param[0] = 1;
510 }
511 regNo = (unsigned char)param[0];
512 /* Send feedback to user */
513 CONSOLE_Print("register=%d; frequency=%d [Hz]\r\n",regNo,freqReg[regNo]);
514 }
515 else
516 {
517 /* Display error messages */
518 DisplayError(4);
519 }
520 }
521
522 /***************************************************************************//**
523 * @brief Loads a phase value in one selected register.
524 *
525 * @param param[0] - register number. (0 / 1)
526 * param[1] - phase value in degrees. (0 .. 2PI)
527 *
528 * @return None.
529 *******************************************************************************/
530 void LoadPhaseReg(double* param, char paramNo) // "LoadPhaseReg=" command
531 {
532 unsigned char regNo = 0;
533 /* Check if the parameters are valid */
534 if(paramNo >= 2)
535 {
536 if(param[0] < 0)
537 {
538 param[0] = 0;
539 }
540 if(param[0] > 1)
541 {
542 param[0] = 1;
543 }
544 regNo = (unsigned char)param[0];
545
546 if(param[1] < 0)
547 {
548 param[1] = 0;
549 }
550 if(param[1] > PHASE_MAX)
551 {
552 param[1] = PHASE_MAX;
553 }
554 phaseReg[regNo] = (float)param[1];
555 /* Set the desired phase value to selected register. */
556 AD9833_SetPhase(regNo, phaseReg[regNo]);
557 /* Send feedback to user */
558 CONSOLE_Print("register=%d; phase=%.3f [radians]\r\n",regNo,phaseReg[regNo]);
559 }
560 else
561 {
562 /* Display error messages */
563 DisplayError(5);
564 }
565 }
566
567 /***************************************************************************//**
568 * @brief Displays the value from one selected phase register.
569 *
570 * @param param[0] - register number. (0 / 1)
571 *
572 * @return None.
573 *******************************************************************************/
574 void GetPhaseRegVal(double* param, char paramNo) // "phaseRegVal?" command
575 {
576 unsigned char regNo = 0;
577 /* Check if the parameter is valid */
578 if(paramNo >= 1)
579 {
580 if(param[0] < 0)
581 {
582 param[0] = 0;
583 }
584 if(param[0] > 1)
585 {
586 param[0] = 1;
587 }
588 regNo = (unsigned char)param[0];
589 /* Send feedback to user */
590 CONSOLE_Print("register=%d; phase=%.3f [radians]\r\n",regNo,phaseReg[regNo]);
591 }
592 else
593 {
594 /* Display error messages */
595 DisplayError(6);
596 }
597 }
598
599 /***************************************************************************//**
600 * @brief Select the frequency register to be used.
601 *
602 * @param param[0] - register number. (0 / 1)
603 *
604 * @return None.
605 *******************************************************************************/
606 void SelFreqRegNo(double* param, char paramNo) // "freqRegNo=" command
607 {
608 unsigned char freq = 0;
609
610 /* Check if the parameter is valid */
611 if(paramNo >= 1)
612 {
613 if(param[0] < 0)
614 {
615 param[0] = 0;
616 }
617 if(param[0] > 1)
618 {
619 param[0] = 1;
620 }
621 freq = (unsigned char)param[0];
622 /* Make the selection of frequency register. */
623 AD9833_SelectFreqReg(freq);
624 if (program == 1)
625 {
626 fselPin = freq;
627 }
628 else
629 {
630 if (program == 0)
631 {
632 freqRegNo = freq;
633 }
634 }
635 /* Send feedback to user */
636 GetFreqRegNo(NULL, 0);
637 }
638 else
639 {
640 /* Display error messages */
641 DisplayError(7);
642 }
643 }
644
645 /***************************************************************************//**
646 * @brief Displays the selected frequency register.
647 *
648 * @return None.
649 *******************************************************************************/
650 void GetFreqRegNo(double* param, char paramNo) // "freqRegNo?" command
651 {
652 /* Send feedback to user */
653 if (program == 0)
654 {
655 CONSOLE_Print("%s%d\r\n",(char*)cmdList[7].name,freqRegNo);
656 }
657 else
658 {
659 if (program == 1)
660 {
661 CONSOLE_Print("%s%d\r\n",(char*)cmdList[7].name,fselPin);
662 }
663 }
664 }
665
666 /***************************************************************************//**
667 * @brief Select the phase register to be used.
668 *
669 * @param param[0] - register number. (0 / 1)
670 *
671 * @return None.
672 *******************************************************************************/
673 void SelPhaseRegNo(double* param, char paramNo) // "phaseRegNo=" command
674 {
675 unsigned char phase = 0;
676
677 /* Check if the parameter is valid */
678 if(paramNo >= 1)
679 {
680 if(param[0] < 0)
681 {
682 param[0] = 0;
683 }
684 if(param[0] > 1)
685 {
686 param[0] = 1;
687 }
688 phase = (unsigned char)param[0];
689 /* Make the selection of the phase register */
690 AD9833_SelectPhaseReg(phase);
691 if (program == 1)
692 {
693 pselPin = phase;
694 }
695 else
696 {
697 if (program == 0)
698 {
699 phaseRegNo = phase;
700 }
701 }
702 /* Send feedback to user */
703 GetPhaseRegNo(NULL, 0);
704 }
705 else
706 {
707 /* Display error messages */
708 DisplayError(9);
709 }
710 }
711
712 /***************************************************************************//**
713 * @brief Displays the selected phase register.
714 *
715 * @return None.
716 *******************************************************************************/
717 void GetPhaseRegNo(double* param, char paramNo) // "phaseRegNo?" command
718 {
719 /* Send feedback to user */
720 if (program == 0)
721 {
722 CONSOLE_Print("%s%d\r\n",(char*)cmdList[9].name,phaseRegNo);
723 }
724 else
725 {
726 if (program == 1)
727 {
728 CONSOLE_Print("%s%d\r\n",(char*)cmdList[9].name,pselPin);
729 }
730 }
731 }
732
733 /***************************************************************************//**
734 * @brief Select one sleep mode.
735 *
736 * @param param[0] - type of sleep
737 * Example soft method(all devices):
738 * 0 - No power-down.
739 * 1 - DAC powered down.
740 * 2 - Internal clock disabled.
741 * 3 - DAC powered down and Internal
742 * clock disabled.
743 * Example hard method(AD9834 & AD9838):
744 * 0 - No power-down.
745 * 1 - DAC powered down.
746 *
747 * @return None.
748 *******************************************************************************/
749 void SetSleepMode(double* param, char paramNo) // "sleepMode=" command
750 {
751 unsigned char sleep = 0;
752
753 /* Check if the parameter is valid */
754 if(paramNo >= 1)
755 {
756 if(param[0] < 0)
757 {
758 param[0] = 0;
759 }
760 if(param[0] > 3)
761 {
762 param[0] = 3;
763 }
764 sleep = (unsigned char)param[0];
765 /* Set the selected sleep mode. */
766 AD9833_SleepMode(sleep);
767 if (program == 1)
768 {
769 if ((sleep == 0) || (sleep == 1))
770 {
771 sleepPin = sleep;
772 }
773 }
774 else
775 {
776 if (program == 0)
777 {
778 sleepMode = sleep;
779 }
780 }
781 /* Send feedback to user */
782 GetSleepMode(NULL, 0);
783 }
784 else
785 {
786 /* Display error messages */
787 DisplayError(11);
788 }
789 }
790
791 /***************************************************************************//**
792 * @brief Displays the selected sleep mode.
793 *
794 * @return None.
795 *******************************************************************************/
796 void GetSleepMode(double* param, char paramNo) // "sleepMode?" command
797 {
798 /* Send feedback to user */
799 if (program == 0)
800 {
801 CONSOLE_Print("%s%d\r\n",(char*)cmdList[11].name,sleepMode);
802 }
803 else
804 {
805 if (program == 1)
806 {
807 CONSOLE_Print("%s%d\r\n",(char*)cmdList[11].name,sleepPin);
808 }
809 }
810 }
811
812 /***************************************************************************//**
813 * @brief Sets the programming method. (only for AD9834 & AD9838)
814 *
815 * @param param[0] - method.
816 * Example: 0 - software method.
817 * 1 - hardware method.
818 *
819 * @return None.
820 *******************************************************************************/
821 void SetProgram(double* param, char paramNo) // "program=" command
822 {
823 /* Verify the device */
824 if ((deviceType == ID_AD9834) || (deviceType == ID_AD9838))
825 {
826 /* Check if the parameter is valid */
827 if(paramNo >= 1)
828 {
829 if(param[0] < 0)
830 {
831 param[0] = 0;
832 }
833 if(param[0] > 1)
834 {
835 param[0] = 1;
836 }
837 program = (unsigned char)param[0];
838 /* Set the selected sleep mode. */
839 AD9834_SelectProgMethod(program);
840 /* Send feedback to user */
841 GetProgram(NULL, 0);
842 }
843 else
844 {
845 /* Display error messages */
846 DisplayError(13);
847 }
848 }
849 else
850 {
851 CONSOLE_Print("Function not compatible with this device.\r\n");
852 }
853 }
854
855 /***************************************************************************//**
856 * @brief Displays the programming method.
857 *
858 * @return None.
859 *******************************************************************************/
860 void GetProgram(double* param, char paramNo) // "program?" command
861 {
862 /* Send feedback to user */
863 CONSOLE_Print("%s%d\r\n",(char*)cmdList[13].name,program);
864 }
865
866 /***************************************************************************//**
867 * @brief Sets the logic output type. (only for AD9834 & AD9838)
868 *
869 * @param param[0] - logic output type.
870 * Example: 0 - High impedance.
871 * 1 - DAC data MSB/2.
872 * 2 - DAC data MSB.
873 * 3 - Comparator.
874 *
875 * @return None.
876 *******************************************************************************/
877 void SetLogicOut(double* param, char paramNo) // "logicOut=" command
878 {
879 /* Verify the device */
880 if ((deviceType == ID_AD9834) || (deviceType == ID_AD9838))
881 {
882 /* Check if the parameter is valid */
883 if(paramNo >= 1)
884 {
885 if(param[0] < 0)
886 {
887 param[0] = 0;
888 }
889 if(param[0] > 3)
890 {
891 param[0] = 3;
892 }
893 logicOut = (unsigned char)param[0];
894
895 switch(logicOut)
896 {
897 case 0: // High impedance
898 AD9834_LogicOutput(0,0,0);
899 break;
900 case 1: // DAC data MSB/2
901 AD9834_LogicOutput(1,0,0);
902 output = 0;
903 break;
904 case 2: // DAC data MSB
905 AD9834_LogicOutput(1,0,1);
906 output = 0;
907 break;
908 case 3: // Comparator
909 AD9834_LogicOutput(1,1,1);
910 output = 0;
911 break;
912 default: // Do nothing
913 break;
914 }
915 /* Send feedback to user */
916 CONSOLE_Print("%s%d\r\n",(char*)cmdList[15].name,logicOut);
917 }
918 else
919 {
920 /* Display error messages */
921 DisplayError(15);
922 }
923 }
924 else
925 {
926 CONSOLE_Print("Function not compatible with this device.\r\n");
927 }
928 }
929
930 /***************************************************************************//**
931 * @brief Displays the logic output type. (only for AD9834 & AD9838)
932 *
933 * @return None.
934 *******************************************************************************/
935 void GetLogicOut(double* param, char paramNo) // "logicOut?" command
936 {
937 if ((deviceType == ID_AD9834) || (deviceType == ID_AD9838))
938 {
939 /* Send feedback to user */
940 CONSOLE_Print("%s%d\r\n",(char*)cmdList[15].name,logicOut);
941 }
942 else
943 {
944 CONSOLE_Print("Function not compatible with this device.\r\n");
945 }
946 }