Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/Pmods/PmodDA4/AD5628.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD5628.c
3 * @brief Driver File for AD5628 Driver.
4 * @author ATofan ([email protected])
5 ********************************************************************************
6 * Copyright 2012(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 ********************************************************************************
40 * SVN Revision: $WCREV$
41 *******************************************************************************/
42
43 /*****************************************************************************/
44 /***************************** Include Files *********************************/
45 /*****************************************************************************/
46 #include <stdio.h>
47 #include "xparameters.h"
48 #include "xil_io.h"
49 #include "AD5628.h"
50 #include "system_config.h"
51
52 volatile int rxData = 0;
53 volatile int timeStepValue = 0xFD050F81;
54 volatile int dacStepValue = 0x1555;
55 volatile int dacStep = 0x0F;
56 volatile char dacTop = 0;
57 volatile char dacBot = 1;
58 volatile char dacSelected = 1;
59
60 extern u32 (*SPI_Init)(u32, char, char, char);
61 extern u32 (*SPI_TransferData)(u32, char, char*, char, char*, char);
62
63 /******************************************************************************
64 * @brief Displays Main Menu.
65 *
66 * @param None.
67 *
68 * @return None.
69 ******************************************************************************/
70 void AD5628_DisplayMainMenu(void)
71 {
72 xil_printf("\n\rPmod-DA4 Demo Program\n\r");
73 xil_printf("Available modes: \n\r");
74 xil_printf(" [f] Fixed Value\n\r");
75 xil_printf(" [w] Waveform Generation\n\r");
76 xil_printf(" [p] Programmable Ramp Signal Generator\n\r");
77 xil_printf(" [m] Stop the program and display this menu\n\r");
78 xil_printf("Press key to select the desired mode:\n\r");
79 }
80
81 /******************************************************************************
82 * @brief Displays Menu.
83 *
84 * @param None.
85 *
86 * @return None.
87 ******************************************************************************/
88 void AD5628_DisplayMenu(void)
89 {
90 xil_printf("\n\rAvailable modes: \n\r");
91 xil_printf(" [f] Fixed Value\n\r");
92 xil_printf(" [w] Waveform Generation\n\r");
93 xil_printf(" [p] Programmable Ramp Signal Generator\n\r");
94 xil_printf(" [m] Stop the program and display this menu\n\r");
95 xil_printf("Press key to select the desired mode:\n\r");
96 rxData = 0;
97 }
98
99 /******************************************************************************
100 * @brief Displays Fixed Value Mode Menu.
101 *
102 * @param None.
103 *
104 * @return None.
105 ******************************************************************************/
106 void AD5628_DisplayFixedMenu(void)
107 {
108 xil_printf("\n\r>Fixed Value Mode Selected\n\r");
109 xil_printf("Press [s] to select DAC\n\r");
110 xil_printf("Press [q] to return to Main Menu\n\r");
111 }
112
113 /******************************************************************************
114 * @brief Displays DAC Selection Menu.
115 *
116 * @param None.
117 *
118 * @return None.
119 ******************************************************************************/
120 void AD5628_DisplayDacMenu(void)
121 {
122 xil_printf("\n\r>DAC Selection");
123 xil_printf("\n\rPlease select which DAC you wish to update:\n\r");
124 xil_printf(" 1. DAC A\n\r");
125 xil_printf(" 2. DAC B\n\r");
126 xil_printf(" 3. DAC C\n\r");
127 xil_printf(" 4. DAC D\n\r");
128 xil_printf(" 5. DAC E\n\r");
129 xil_printf(" 6. DAC F\n\r");
130 xil_printf(" 7. DAC G\n\r");
131 xil_printf(" 8. DAC H\n\r");
132 xil_printf(" 9. ALL DACs\n\r");
133 }
134
135 /******************************************************************************
136 * @brief Displays Waveform Generation ModeMenu.
137 *
138 * @param None.
139 *
140 * @return None.
141 ******************************************************************************/
142 void AD5628_DisplayWaveMenu(void)
143 {
144
145 xil_printf("Please select between the following waveforms:\n\r");
146 xil_printf(" 1. Square Waveform\n\r");
147 xil_printf(" 2. Triangle Waveform\n\r");
148 xil_printf(" 3. Sawtooth Waveform\n\r");
149 xil_printf(" 4. Sine Waveform\n\r");
150 xil_printf(" s. Select DAC\n\r");
151 xil_printf(" q. Return to Main Menu\n\r");
152 }
153
154 /******************************************************************************
155 * @brief Displays Programmable Ramp Mode Menu.
156 *
157 * @param None.
158 *
159 * @return None.
160 ******************************************************************************/
161 void AD5628_DisplayProgRampMenu(void)
162 {
163 xil_printf("\n\rPlease select between the following options:\n\r");
164 xil_printf(" [t] Enter time step\n\r");
165 xil_printf(" [i] Enter increment size\n\r");
166 xil_printf(" [d] Select DAC\n\r");
167 xil_printf(" [r] Run Ramp Signal Generator\n\r");
168 xil_printf("Press [q] to return to Main Menu\n\r");
169 }
170
171 /******************************************************************************
172 * @brief Sets the Internal Reference on.
173 *
174 * @param None.
175 *
176 * @return None.
177 ******************************************************************************/
178 void AD5628_RefON(void)
179 {
180 int txData = 0;
181 char txBuffer[4] = {0, 0, 0, 0};
182 char rxBuffer[4] = {0, 0, 0, 0};
183
184 txData = (SetUpRefReg << CommandDef) |
185 (1 << 0);
186
187 txBuffer[0] = (txData & 0xFF000000) >> 24;
188 txBuffer[1] = (txData & 0x00FF0000) >> 16;
189 txBuffer[2] = (txData & 0x0000FF00) >> 8;
190 txBuffer[3] = (txData & 0x000000FF);
191
192 SPI_TransferData(SPI_BASEADDR, 4, txBuffer, 4, rxBuffer, 1);
193 }
194
195 /******************************************************************************
196 * @brief Sets the internal reference off.
197 *
198 * @param None.
199 *
200 * @return None.
201 ******************************************************************************/
202 void AD5628_RefOFF(void)
203 {
204 int txData = 0;
205 char txBuffer[4] = {0, 0, 0, 0};
206 char rxBuffer[4] = {0, 0, 0, 0};
207
208 txData = (SetUpRefReg << CommandDef) |
209 (0 << 0);
210
211 txBuffer[0] = (txData & 0xFF000000) >> 24;
212 txBuffer[1] = (txData & 0x00FF0000) >> 16;
213 txBuffer[2] = (txData & 0x0000FF00) >> 8;
214 txBuffer[3] = (txData & 0x000000FF);
215
216 SPI_TransferData(SPI_BASEADDR, 4, txBuffer, 4, rxBuffer, 1);
217 }
218
219 /******************************************************************************
220 * @brief Updates the DAC.
221 *
222 * @param n - Select which DAC to Update.
223 *
224 * @param data - Value to be updated
225 *
226 * @return None.
227 ******************************************************************************/
228 void AD5628_WriteUpdateDac(int n, int data)
229 {
230 int txData = 0;
231 char txBuffer[4] = {0, 0, 0, 0};
232 char rxBuffer[4] = {0, 0, 0, 0};
233
234 txData = (WriteUpdateDACn << CommandDef) |
235 (n << AddressCom) |
236 (data << DataBits);
237
238 txBuffer[0] = (txData & 0xFF000000) >> 24;
239 txBuffer[1] = (txData & 0x00FF0000) >> 16;
240 txBuffer[2] = (txData & 0x0000FF00) >> 8;
241 txBuffer[3] = (txData & 0x000000FF);
242
243 SPI_TransferData(SPI_BASEADDR, 4, txBuffer, 4, rxBuffer, 1);
244 }
245
246 /******************************************************************************
247 * @brief Fixed Value Mode.
248 *
249 * @param None.
250 *
251 * @return None.
252 ******************************************************************************/
253 void AD5628_FixedValue(void)
254 {
255 char rx = 's';
256 char c[3] = "000";
257 char *c_ptr;
258 int i = 0;
259 char cnt = 0;
260 char valid = 0;
261 char dacSel = 0;
262 int value = 0;
263
264 // Disable interrupts in order to use normal polling
265 DisableInterrupts(UART_INTERRUPT);
266
267 AD5628_DisplayFixedMenu();
268
269 while(rx != 'q')
270 {
271 cnt = 0;
272 i = 0;
273 valid = 0;
274 value = 0;
275 c_ptr = c;
276
277 if(rx == 's')
278 {
279 xil_printf("\n\r");
280 AD5628_DisplayDacMenu();
281 // Check if data is available on UART
282 rx = UartReadChar();
283 if(rx != 'q')
284 {
285 if(rx == '9')
286 {
287 dacSel = 0x0F;
288 }
289 else
290 {
291 dacSel = (rx - 0x31);
292 }
293
294 switch(dacSel)
295 {
296 case 0:
297 xil_printf("\n\r>You have chosen to update ");
298 xil_printf("DAC A.\n\r");
299 break;
300 case 1:
301 xil_printf("\n\r>You have chosen to update ");
302 xil_printf("DAC B.\n\r");
303 break;
304 case 2:
305 xil_printf("\n\r>You have chosen to update ");
306 xil_printf("DAC C.\n\r");
307 break;
308 case 3:
309 xil_printf("\n\r>You have chosen to update ");
310 xil_printf("DAC D.\n\r");
311 break;
312 case 4:
313 xil_printf("\n\r>You have chosen to update ");
314 xil_printf("DAC E.\n\r");
315 break;
316 case 5:
317 xil_printf("\n\r>You have chosen to update ");
318 xil_printf("DAC F.\n\r");
319 break;
320 case 6:
321 xil_printf("\n\r>You have chosen to update ");
322 xil_printf("DAC G.\n\r");
323 break;
324 case 7:
325 xil_printf("\n\r>You have chosen to update ");
326 xil_printf("DAC H.\n\r");
327 break;
328 case 15:
329 xil_printf("\n\r>You have chosen to update ");
330 xil_printf("All DACs.\n\r");
331 break;
332 case ('s'-0x31):
333 i=5;
334 valid = 0;
335 break;
336 default:
337 xil_printf("Wrong option!");
338 rx = 's';
339 i=5;
340 valid = 0;
341 break;
342 }
343 }
344 else
345 {
346 i = 5;
347 valid = 0;
348 }
349 }
350
351 if(i == 0)
352 {
353 xil_printf("\n\rPlease enter a value between 0x000 and 0xFFF: 0x");
354 }
355 // Maximum number of received characters will be 5 (e.g. F F F 0x0D 0x0A)
356 while(i < 5)
357 {
358 // Check if data is available on UART
359 rx = UartReadChar();
360 xil_printf("%c", rx);
361 // Check if pressed key is [Enter]
362 if(rx == 0x0D)
363 {
364 i = 4;
365 }
366 else if(rx == 0x0A)
367 {
368 i = 4;
369 }
370 else if(rx == 'q')
371 {
372 i = 5;
373 valid = 0;
374 }
375 else if(rx == 's')
376 {
377 i = 5;
378 valid = 0;
379 }
380 else if(((rx > 0x00)&&(rx < 0x30))|| // Not 0 - 9
381 ((rx > 0x39)&&(rx < 0x41))|| // Not A - F
382 ((rx > 0x46)&&(rx < 0x61))|| // Not a - f
383 (rx > 0x66))
384 {
385 xil_printf("\n\rCharacters entered must be HEX values (0 to 9 and A B C D E F)");
386 i = 5;
387 valid = 0;
388 }
389 else
390 {
391 *c_ptr++ = rx;
392 cnt = cnt + 1;
393 valid = 1;
394 }
395 if(cnt == 3)
396 {
397 i = 5;
398 }
399 i++;
400 }
401
402 // Translate from ASCII to hex
403 for(i = 0; i < cnt; i++)
404 {
405 if(c[i] > 0x60)
406 {
407 value = value * 16 + (c[i] - 0x57);
408 }
409 else if(c[i] > 0x39)
410 {
411 value = value * 16 + (c[i] - 0x37);
412 }
413 else
414 {
415 value = value * 16 + (c[i] - 0x30);
416 }
417 }
418
419 if(valid == 1)
420 {
421 AD5628_WriteUpdateDac(dacSel, value);
422 xil_printf("\n\r>DAC Output modified\n\r");
423 }
424 }
425 rxData = 'm';
426 // Enable interrupts
427 EnableInterrupts(UART_INTERRUPT);
428 xil_printf("\n\r\n\r>Returning to Menu\n\r");
429 }
430
431 /******************************************************************************
432 * @brief Waveform Generation Mode.
433 *
434 * @param None.
435 *
436 * @return None.
437 ******************************************************************************/
438 void AD5628_WaveGen(void)
439 {
440 int prevRxData = 0;
441 int i = 0;
442 char valid = 1;
443 char rx = 's';
444 char dacSel = 0;
445 int repeat = 1;
446
447
448 //AD5628_DisplayWaveMenu();
449 rxData = 's';
450
451 xil_printf("\n\r>Waveform Generation Mode Selected\n\r");
452 while(valid)
453 {
454 repeat = 1;
455 switch(rxData)
456 {
457 case '1':
458 AD5628_WriteUpdateDac(dacSel, (squaretable[i] << 4));
459 i+=1;
460 break;
461 case '2':
462 AD5628_WriteUpdateDac(dacSel, (triangletable[i] << 4));
463 i+=1;
464 break;
465 case '3':
466 AD5628_WriteUpdateDac(dacSel, (sawtable[i] << 4));
467 i+=1;
468 break;
469 case '4':
470 AD5628_WriteUpdateDac(dacSel, (sinetable[i] << 4));
471 i+=1;
472 break;
473 case 's':
474 break;
475 case 'q':
476 xil_printf("\n\r>Returning to Menu...\n\r");
477 valid = 0;
478 rxData = 'm';
479 break;
480 case 'm':
481 break;
482 default:
483
484 break;
485 }
486
487 if(rxData != prevRxData)
488 {
489 prevRxData = rxData;
490 switch(rxData)
491 {
492 case '1':
493 xil_printf("\n\r>Square waveform selected\n\r");
494 break;
495 case '2':
496 xil_printf("\n\r>Triangle waveform selected\n\r");
497 break;
498 case '3':
499 xil_printf("\n\r>Sawtooth waveform selected\n\r");
500 break;
501 case '4':
502 xil_printf("\n\r>Sine waveform selected\n\r");
503 break;
504 case 's':
505 while (repeat == 1)
506 {
507 AD5628_DisplayDacMenu();
508 DisableInterrupts(UART_INTERRUPT);
509 // Check if data is available on UART
510 rx = UartReadChar();
511 if(rx != 'q')
512 {
513 if(rx == '9')
514 {
515 dacSel = 0x0F;
516 }
517 else
518 {
519 dacSel = (rx - 0x31);
520 }
521 repeat = 0;
522 switch(dacSel)
523 {
524 case 0:
525 xil_printf("\n\r>You have chosen to update ");
526 xil_printf("DAC A.\n\r");
527 break;
528 case 1:
529 xil_printf("\n\r>You have chosen to update ");
530 xil_printf("DAC B.\n\r");
531 break;
532 case 2:
533 xil_printf("\n\r>You have chosen to update ");
534 xil_printf("DAC C.\n\r");
535 break;
536 case 3:
537 xil_printf("\n\r>You have chosen to update ");
538 xil_printf("DAC D.\n\r");
539 break;
540 case 4:
541 xil_printf("\n\r>You have chosen to update ");
542 xil_printf("DAC E.\n\r");
543 break;
544 case 5:
545 xil_printf("\n\r>You have chosen to update ");
546 xil_printf("DAC F.\n\r");
547 break;
548 case 6:
549 xil_printf("\n\r>You have chosen to update ");
550 xil_printf("DAC G.\n\r");
551 break;
552 case 7:
553 xil_printf("\n\r>You have chosen to update ");
554 xil_printf("DAC H.\n\r");
555 break;
556 case 15:
557 xil_printf("\n\r>You have chosen to update ");
558 xil_printf("All DACs.\n\r");
559 break;
560 default:
561 xil_printf("Wrong option!\n\r");
562 //xil_printf("\n\r>Returning to DAC Selection...\n\r");
563 repeat = 1;
564 break;
565 }
566 }
567 else
568 {
569 valid = 0;
570 }
571 if ( (((dacSel >= 0) && (dacSel <= 7)) || (dacSel == 15)) && (valid != 0) )
572 {
573 AD5628_DisplayWaveMenu();
574 xil_printf("Press [1] to [4] in order to select the desired output, or [q] to exit\n\r");
575 }
576 EnableInterrupts(UART_INTERRUPT);
577 }
578 break;
579 case 'q':
580 xil_printf("\n\r>Returning to Menu...\n\r");
581 valid = 0;
582 rxData = 'm';
583 break;
584 default:
585 if (valid != 0)
586 {
587 xil_printf("Wrong option!\n\r");
588 AD5628_DisplayWaveMenu();
589 xil_printf("Press [1] to [4] in order to select the desired output, or [q] to exit\n\r");
590 }
591 break;
592 }
593 }
594 if(i > 255)
595 {
596 i = 0;
597 }
598 }
599
600 }
601
602 /******************************************************************************
603 * @brief Enters Time Step Value Set Mode.
604 *
605 * @param None.
606 *
607 * @return None.
608 ******************************************************************************/
609 void AD5628_EnterTimeStep(void)
610 {
611 char rx = 0;
612 char c[4] = "0000";
613 char *c_ptr;
614 int i = 0;
615 char cnt = 0;
616 char valid = 0;
617 int value = 0;
618 int topValue = 4294967295;
619
620 // Disable interrupts in order to use normal polling
621 DisableInterrupts(UART_INTERRUPT);
622
623 while(valid == 0)
624 {
625 c_ptr = c;
626 i = 0;
627 cnt = 0;
628 value = 0;
629
630 xil_printf("\n\rPlease enter a value between 100 and 5000 [ms]: ");
631
632 // Maximum number of received characters will be 6 (e.g. 5 0 0 0 0x0D 0x0A)
633 while(i < 6)
634 {
635 // Check if data is available on UART
636 rx = UartReadChar();
637 xil_printf("%c", rx);
638 // Check if pressed key is [Enter]
639 if(rx == 0x0D)
640 {
641 i = 5;
642 }
643 else if(rx == 0x0A)
644 {
645 i = 5;
646 }
647 else if(((rx > 0x00)&&(rx < 0x30))||(rx > 0x39))
648 {
649 xil_printf("\n\rCharacters must be digits [0] to [9]\n\r");
650 i = 6;
651 valid = 0;
652 }
653 else
654 {
655 *c_ptr ++= rx;
656 cnt++;
657 valid = 1;
658 }
659
660 if(cnt == 4)
661 {
662 i = 6;
663 }
664 i++;
665 }
666 xil_printf("\n\r");
667 // Translate from ASCII to dec
668 for(i = 0; i < cnt; i++)
669 {
670 value = value * 10 + (c[i] - 0x30);
671 }
672
673 if((value > 5000)||(value < 100))
674 {
675 xil_printf("\n\r> Incorrect value entered. Value must be between 100 and 5000.\n\r");
676 valid = 0;
677 }
678 }
679
680 if(valid == 1)
681 {
682 if(USE_PS7 == 1){
683 timeStepValue = ((float)6781 / 1000) * value + 1;
684 }
685 else{
686 timeStepValue = (topValue - (value * 100000)) + 2;
687 }
688 }
689
690 rxData ='p';
691 }
692
693 /******************************************************************************
694 * @brief Enters Increment Step Value Set Mode.
695 *
696 * @param None.
697 *
698 * @return None.
699 ******************************************************************************/
700 void AD5628_EnterIncrStep(void)
701 {
702 char rx = 0;
703 char c[3] = "000";
704 char *c_ptr;
705 int i = 0;
706 char cnt = 0;
707 char valid = 0;
708 int value = 0;
709
710 // Disable interrupts in order to use normal polling
711 DisableInterrupts(UART_INTERRUPT);
712
713 xil_printf("\n\rPlease enter a value between 0x000 and 0xFFF: 0x");
714
715 c_ptr = c;
716
717 // Maximum number of received characters will be 5 (e.g. 5 0 F 0x0D 0x0A)
718 while(i < 5)
719 {
720 // Check if data is available on UART
721 rx = UartReadChar();
722 xil_printf("%c", rx);
723 // Check if pressed key is [Enter]
724 if(rx == 0x0D)
725 {
726 i = 4;
727 }
728 else if(rx == 0x0A)
729 {
730 i = 4;
731 }
732 else if(((rx > 0x00)&&(rx < 0x30))|| // Not 0 - 9
733 ((rx > 0x39)&&(rx < 0x41))|| // Not A - F
734 ((rx > 0x46)&&(rx < 0x61))|| // Not a - f
735 (rx > 0x66))
736 {
737 xil_printf("\n\rCharacters entered must be HEX values (0 to 9 and A B C D E F)");
738 i = 5;
739 valid = 0;
740 }
741 else
742 {
743 *c_ptr ++= rx;
744 cnt++;
745 valid = 1;
746 }
747
748 if(cnt == 3)
749 {
750 i = 5;
751 }
752 i++;
753 }
754 xil_printf("\n\r");
755 // Translate from ASCII to dec
756 for(i = 0; i < cnt; i++)
757 {
758 if(c[i] > 0x60)
759 {
760 value = value * 16 + (c[i] - 0x57);
761 }
762 else if(c[i] > 0x39)
763 {
764 value = value * 16 + (c[i] - 0x37);
765 }
766 else
767 {
768 value = value * 16 + (c[i] - 0x30);
769 }
770 }
771
772 if(valid == 1)
773 {
774 dacStepValue = value;
775 xil_printf(">Incremented size modified to 0x%x", dacStepValue);
776 xil_printf("\n\r");
777 }
778
779
780 rxData ='p';
781 }
782
783 /******************************************************************************
784 * @brief Runs Programmable Ramp Generation Mode.
785 *
786 * @param None.
787 *
788 * @return None.
789 ******************************************************************************/
790 void AD5628_RunProgRamp(void)
791 {
792 xil_printf("\n\r>Running. Press [q] to return to the Main Menu\n\r");
793
794 EnableInterrupts(UART_INTERRUPT);
795
796 // Start Timer
797 StartTimer();
798
799 while(rxData != 'q')
800 {
801 }
802
803 // Stop Timer
804 StopTimer();
805
806 DisableInterrupts(UART_INTERRUPT);
807 rxData ='m';
808 }
809
810 /******************************************************************************
811 * @brief Runs Programmable Ramp Generation Mode DAC Selection Menu.
812 *
813 * @param None.
814 *
815 * @return None.
816 ******************************************************************************/
817 void AD5628_RampDacSel(void)
818 {
819 char rx = 0x00;
820
821
822 do
823 {
824 AD5628_DisplayDacMenu();
825 // Check if data is available on UART
826 rx = UartReadChar();
827 if(rx != 'q')
828 {
829 if(rx == '9')
830 {
831 dacSelected = 0x0F;
832 }
833 else
834 {
835 dacSelected = (rx - 0x31);
836 }
837
838 switch(dacSelected)
839 {
840 case 0:
841 xil_printf("\n\r>You have chosen to update ");
842 xil_printf("DAC A.\n\r");
843 break;
844 case 1:
845 xil_printf("\n\r>You have chosen to update ");
846 xil_printf("DAC B.\n\r");
847 break;
848 case 2:
849 xil_printf("\n\r>You have chosen to update ");
850 xil_printf("DAC C.\n\r");
851 break;
852 case 3:
853 xil_printf("\n\r>You have chosen to update ");
854 xil_printf("DAC D.\n\r");
855 break;
856 case 4:
857 xil_printf("\n\r>You have chosen to update ");
858 xil_printf("DAC E.\n\r");
859 break;
860 case 5:
861 xil_printf("\n\r>You have chosen to update ");
862 xil_printf("DAC F.\n\r");
863 break;
864 case 6:
865 xil_printf("\n\r>You have chosen to update ");
866 xil_printf("DAC G.\n\r");
867 break;
868 case 7:
869 xil_printf("\n\r>You have chosen to update ");
870 xil_printf("DAC H.\n\r");
871 break;
872 case 15:
873 xil_printf("\n\r>You have chosen to update ");
874 xil_printf("All DACs.\n\r");
875 break;
876 default:
877 xil_printf("\n\rWrong option!\n\r");
878
879 break;
880 }
881 }
882 }
883 while (!(((dacSelected >=0) && (dacSelected <=7)) || (dacSelected == 15)));
884
885 }
886
887 /******************************************************************************
888 * @brief Runs Programmable Ramp Generation Mode Main Menu.
889 *
890 * @param None.
891 *
892 * @return None.
893 ******************************************************************************/
894 void AD5628_ProgRamp(void)
895 {
896 DisableInterrupts(UART_INTERRUPT);
897 AD5628_DisplayProgRampMenu();
898
899 // Check if data is available on the UART
900 rxData = UartReadChar();
901
902 switch(rxData)
903 {
904 case 't':
905 AD5628_EnterTimeStep();
906 break;
907 case 'i':
908 AD5628_EnterIncrStep();
909 break;
910 case 'd':
911 AD5628_RampDacSel();
912 break;
913 case 'r':
914 AD5628_RunProgRamp();
915 break;
916 case 'q':
917 xil_printf("\n\r>Returning to Menu...\n\r");
918 rxData = 'm';
919 break;
920 default:
921 xil_printf("\n\rWrong option!");
922 rxData = 0;
923 break;
924 }
925
926 if(rxData != 'm')
927 {
928 rxData = 'p';
929 }
930
931 EnableInterrupts(UART_INTERRUPT);
932
933 }
934
935 /******************************************************************************
936 * @brief Timer interrupt function. Loads new data into DAC at desired time step
937 *
938 * @param None.
939 *
940 * @return None.
941 ******************************************************************************/
942 void ADITimerIntrFunction(void)
943 {
944 int prevDacStep = dacStep;
945 LoadTimer(timeStepValue);
946 // Increase output data value
947 if(dacBot == 1)
948 {
949 dacStep = dacStep + dacStepValue;
950 }
951 else if(dacTop == 1)
952 {
953 dacStep = dacStep - dacStepValue;
954 }
955 if((dacStep > 0xFFF) && (dacTop == 0))
956 {
957 dacTop = 1;
958 dacBot = 0;
959 }
960 if((dacStep < 0x000) && (dacBot == 0))
961 {
962 dacTop = 0;
963 dacBot = 1;
964 }
965 if(dacStep > 0xFFF)
966 {
967 dacStep = 0xFFF;
968 }
969 if(dacStep < 0x000)
970 {
971 dacStep = 0x000;
972 }
973
974 if(dacStep != prevDacStep)
975 {
976 AD5628_WriteUpdateDac(dacSelected, dacStep);
977 }
978
979 if(USE_PS7 == 0)
980 {
981 // Clear Interrupts
982 Xil_Out32(TIMER_BASEADDR + 0x00, 0x00000100);
983 // Start Timer
984 StartTimer();
985 }
986 }
987
988 /******************************************************************************
989 * @brief Demo application for AD5541A
990 *
991 * @param None.
992 *
993 * @return None.
994 ******************************************************************************/
995 void DemoProgram(void)
996 {
997 AD5628_DisplayMainMenu();
998
999 while(1)
1000 {
1001 switch(rxData)
1002 {
1003 case 'f':
1004 AD5628_FixedValue();
1005 break;
1006 case 'w':
1007 AD5628_WaveGen();
1008 break;
1009 case 'p':
1010 AD5628_ProgRamp();
1011 break;
1012 case 'm':
1013 AD5628_DisplayMenu();
1014 break;
1015 case 0:
1016 break;
1017 default:
1018 xil_printf("\n\rWrong option! Please select one of the options below.");
1019 AD5628_DisplayMenu();
1020 break;
1021 }
1022 }
1023 }