Petaluma (MAXREFDES30#) Code Documentation  V01.00
16-Bit, 8-Ch, +/-10V input, Simultaneous-Sampling Analog Front End
 All Data Structures Files Functions Variables Macros Pages
MAXREFDES30.c
Go to the documentation of this file.
1 
29 /*
30  * Copyright (C) 2012 Maxim Integrated Products, Inc., All Rights Reserved.
31  *
32  * Permission is hereby granted, free of charge, to any person obtaining a
33  * copy of this software and associated documentation files (the "Software"),
34  * to deal in the Software without restriction, including without limitation
35  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
36  * and/or sell copies of the Software, and to permit persons to whom the
37  * Software is furnished to do so, subject to the following conditions:
38  *
39  * The above copyright notice and this permission notice shall be included
40  * in all copies or substantial portions of the Software.
41  *
42  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
43  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45  * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
46  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
47  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
48  * OTHER DEALINGS IN THE SOFTWARE.
49  *
50  * Except as contained in this notice, the name of Maxim Integrated Products
51  * shall not be used except as stated in the Maxim Integrated Products
52  * Branding Policy.
53  *
54  * The mere transfer of this software does not imply any licenses
55  * of trade secrets, proprietary technology, copyrights, patents,
56  * trademarks, maskwork rights, or any other form of intellectual
57  * property whatsoever. Maxim Integrated Products retains all ownership rights.
58  *
59  ***************************************************************************/
76 #include "xparameters.h" /* EDK generated parameters */
77 #include "stdio.h"
78 #include "platform.h"
79 #include "menu.h"
80 #include "utilities.h"
82 #include "MAXREFDES30.h"
83 #include "axi_max11046.h"
84 
85 #define MAJOR_REVISION 01
86 #define MINOR_REVISION 00
87 
88 
89 // Globals
90 char g_sInputString[ INPUT_STRING_MAX_SIZE ]; //This string will hold user input from terminal.
91  XGpio g_xGpioLed;
93 char g_tempString[32];
94 
95 u8 font[1024] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x00, NUL
96  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x01, SOH
97  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x02, STX
98  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x03, ETX
99  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x03, EOT
100  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x05, ENQ
101  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x06, ACK
102  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x07, BEL
103  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x08, BS
104  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x09, HT
105  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0A, LF
106  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0B, VT
107  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0C, FF
108  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0D, CR
109  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0E, SO
110  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0F, SI
111  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x10, DLE
112  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x11, DC1
113  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x12, DC2
114  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x13, DC3
115  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x13, DC4
116  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x15, NAK
117  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x16, SYN
118  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x17, ETB
119  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x18, CAN
120  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x19, EM
121  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1A, SUB
122  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1B, ESC
123  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1C, FS
124  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1D, GS
125  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1E, RS
126  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1F, US
127  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x20, space
128  0x00,0x00,0x00,0x5f,0x00,0x00,0x00,0x00, // 0x21, !
129  0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00, // 0x22, "
130  0x64,0x3c,0x26,0x64,0x3c,0x26,0x24,0x00, // 0x23, #
131  0x26,0x49,0x49,0x7f,0x49,0x49,0x32,0x00, // 0x23, $
132  0x42,0x25,0x12,0x08,0x24,0x52,0x21,0x00, // 0x25, %
133  0x20,0x50,0x4e,0x55,0x22,0x58,0x28,0x00, // 0x26, &
134  0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00, // 0x27, '
135  0x00,0x00,0x1c,0x22,0x41,0x00,0x00,0x00, // 0x28, (
136  0x00,0x00,0x00,0x41,0x22,0x1c,0x00,0x00, // 0x29, )
137  0x00,0x15,0x15,0x0e,0x0e,0x15,0x15,0x00, // 0x2A, *
138  0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00, // 0x2B, +
139  0x00,0x00,0x00,0x50,0x30,0x00,0x00,0x00, // 0x2C, ,
140  0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00, // 0x2D, -
141  0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, // 0x2E, .
142  0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00, // 0x2F, /
143  0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, // 0x30, 0
144  0x00,0x00,0x41,0x7f,0x40,0x00,0x00,0x00, // 0x31, 1
145  0x00,0x42,0x61,0x51,0x49,0x6e,0x00,0x00, // 0x32, 2
146  0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00, // 0x33, 3
147  0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x00, // 0x33, 4
148  0x00,0x27,0x49,0x49,0x49,0x71,0x00,0x00, // 0x35, 5
149  0x00,0x3c,0x4a,0x49,0x48,0x70,0x00,0x00, // 0x36, 6
150  0x00,0x43,0x21,0x11,0x0d,0x03,0x00,0x00, // 0x37, 7
151  0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, // 0x38, 8
152  0x00,0x06,0x09,0x49,0x29,0x1e,0x00,0x00, // 0x39, 9
153  0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00, // 0x3A, :
154  0x00,0x00,0x00,0x52,0x30,0x00,0x00,0x00, // 0x3B, //
155  0x00,0x00,0x08,0x14,0x14,0x22,0x00,0x00, // 0x3C, <
156  0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00, // 0x3D, =
157  0x00,0x00,0x22,0x14,0x14,0x08,0x00,0x00, // 0x3E, >
158  0x00,0x02,0x01,0x59,0x05,0x02,0x00,0x00, // 0x3F, ?
159  0x3e,0x41,0x5d,0x55,0x4d,0x51,0x2e,0x00, // 0x40, @
160  0x40,0x7c,0x4a,0x09,0x4a,0x7c,0x40,0x00, // 0x41, A
161  0x41,0x7f,0x49,0x49,0x49,0x49,0x36,0x00, // 0x42, B
162  0x1c,0x22,0x41,0x41,0x41,0x41,0x22,0x00, // 0x43, C
163  0x41,0x7f,0x41,0x41,0x41,0x22,0x1c,0x00, // 0x44, D
164  0x41,0x7f,0x49,0x49,0x5d,0x41,0x63,0x00, // 0x45, E
165  0x41,0x7f,0x49,0x09,0x1d,0x01,0x03,0x00, // 0x46, F
166  0x1c,0x22,0x41,0x49,0x49,0x3a,0x08,0x00, // 0x47, G
167  0x41,0x7f,0x08,0x08,0x08,0x7f,0x41,0x00, // 0x48, H
168  0x00,0x41,0x41,0x7F,0x41,0x41,0x00,0x00, // 0x49, I
169  0x30,0x40,0x41,0x41,0x3F,0x01,0x01,0x00, // 0x4A, J
170  0x41,0x7f,0x08,0x0c,0x12,0x61,0x41,0x00, // 0x4B, K
171  0x41,0x7f,0x41,0x40,0x40,0x40,0x60,0x00, // 0x4C, L
172  0x41,0x7f,0x42,0x0c,0x42,0x7f,0x41,0x00, // 0x4D, M
173  0x41,0x7f,0x42,0x0c,0x11,0x7f,0x01,0x00, // 0x4E, N
174  0x1c,0x22,0x41,0x41,0x41,0x22,0x1c,0x00, // 0x4F, O
175  0x41,0x7f,0x49,0x09,0x09,0x09,0x06,0x00, // 0x50, P
176  0x0c,0x12,0x21,0x21,0x61,0x52,0x4c,0x00, // 0x51, Q
177  0x41,0x7f,0x09,0x09,0x19,0x69,0x46,0x00, // 0x52, R
178  0x66,0x49,0x49,0x49,0x49,0x49,0x33,0x00, // 0x53, S
179  0x03,0x01,0x41,0x7f,0x41,0x01,0x03,0x00, // 0x54, T
180  0x01,0x3f,0x41,0x40,0x41,0x3f,0x01,0x00, // 0x55, U
181  0x01,0x0f,0x31,0x40,0x31,0x0f,0x01,0x00, // 0x56, V
182  0x01,0x1f,0x61,0x14,0x61,0x1f,0x01,0x00, // 0x57, W
183  0x41,0x41,0x36,0x08,0x36,0x41,0x41,0x00, // 0x58, X
184  0x01,0x03,0x44,0x78,0x44,0x03,0x01,0x00, // 0x59, Y
185  0x43,0x61,0x51,0x49,0x45,0x43,0x61,0x00, // 0x5A, Z
186  0x00,0x00,0x7f,0x41,0x41,0x00,0x00,0x00, // 0x5B, [
187  0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x00, // 0x5C,
188  0x00,0x00,0x41,0x41,0x7f,0x00,0x00,0x00, // 0x5D, ]
189  0x00,0x04,0x02,0x01,0x01,0x02,0x04,0x00, // 0x5E, ^
190  0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00, // 0x5F, _
191  0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00, // 0x60, `
192  0x00,0x34,0x4a,0x4a,0x4a,0x3c,0x40,0x00, // 0x61, a
193  0x00,0x41,0x3f,0x48,0x48,0x48,0x30,0x00, // 0x62. b
194  0x00,0x3c,0x42,0x42,0x42,0x24,0x00,0x00, // 0x63, c
195  0x00,0x30,0x48,0x48,0x49,0x3f,0x40,0x00, // 0x63, d
196  0x00,0x3c,0x4a,0x4a,0x4a,0x2c,0x00,0x00, // 0x65, e
197  0x00,0x00,0x48,0x7e,0x49,0x09,0x00,0x00, // 0x66, f
198  0x00,0x26,0x49,0x49,0x49,0x3f,0x01,0x00, // 0x67, g
199  0x41,0x7f,0x48,0x04,0x44,0x78,0x40,0x00, // 0x68, h
200  0x00,0x00,0x44,0x7d,0x40,0x00,0x00,0x00, // 0x69, i
201  0x00,0x00,0x40,0x44,0x3d,0x00,0x00,0x00, // 0x6A, j
202  0x41,0x7f,0x10,0x18,0x24,0x42,0x42,0x00, // 0x6B, k
203  0x00,0x40,0x41,0x7f,0x40,0x40,0x00,0x00, // 0x6C, l
204  0x42,0x7e,0x02,0x7c,0x02,0x7e,0x40,0x00, // 0x6D, m
205  0x42,0x7e,0x44,0x02,0x42,0x7c,0x40,0x00, // 0x6E, n
206  0x00,0x3c,0x42,0x42,0x42,0x3c,0x00,0x00, // 0x6F, o
207  0x00,0x41,0x7f,0x49,0x09,0x09,0x06,0x00, // 0x70, p
208  0x00,0x06,0x09,0x09,0x49,0x7f,0x41,0x00, // 0x71, q
209  0x00,0x42,0x7e,0x44,0x02,0x02,0x04,0x00, // 0x72, r
210  0x00,0x64,0x4a,0x4a,0x4a,0x36,0x00,0x00, // 0x73, s
211  0x00,0x04,0x3f,0x44,0x44,0x20,0x00,0x00, // 0x73, t
212  0x00,0x02,0x3e,0x40,0x40,0x22,0x7e,0x40, // 0x75, u
213  0x02,0x0e,0x32,0x40,0x32,0x0e,0x02,0x00, // 0x76, v
214  0x02,0x1e,0x62,0x18,0x62,0x1e,0x02,0x00, // 0x77, w
215  0x42,0x62,0x14,0x08,0x14,0x62,0x42,0x00, // 0x78, x
216  0x01,0x43,0x45,0x38,0x05,0x03,0x01,0x00, // 0x79, y
217  0x00,0x46,0x62,0x52,0x4a,0x46,0x62,0x00, // 0x7A, z
218  0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00, // 0x7B, {
219  0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00, // 0x7C, |
220  0x00,0x00,0x00,0x41,0x36,0x08,0x00,0x00, // 0x7D, }
221  0x00,0x18,0x08,0x08,0x10,0x10,0x18,0x00, // 0x7E, ~
222  0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55 // 0x7F, DEL
223  };
224 
225 u32 g_unSampleSize = 65536;
227 
228 
229 int main(void)
240 {
241  // Variables for the main() function
242  u8 uchInput=0;
243  int nMenuState=0; // Go to Channel Select Menu First
244 
245  u16 auSamplesCh0[1048576]; //stores the samples
246  u16 auSamplesCh1[1048576]; //stores the samples
247  u16 auSamplesCh2[1048576]; //stores the samples
248  u16 auSamplesCh3[1048576]; //stores the samples
249  u16 auSamplesCh4[1048576]; //stores the samples
250  u16 auSamplesCh5[1048576]; //stores the samples
251  u16 auSamplesCh6[1048576]; //stores the samples
252  u16 auSamplesCh7[1048576]; //stores the samples
253  u32 unNumberOfSamplesReceived;
254 
255  char tempString[30];
256 
257  // Xilinx provided utility to initialize the hardware/firmware drivers and enable/disable cache
258  init_platform();
259 
260  // Clear the Hyperterminal screen by sending printf("\033[2J");
261  menu_cls();
262 
263  // Toggle the LEDs so that the user knows the board is awake
264  XGpio_Initialize(&g_xGpioLed, XPAR_AXI_GPIO_LED_DEVICE_ID);
265  XGpio_SetDataDirection(&g_xGpioLed, 1, 0x00000000); // Set the LED peripheral to outputs
267 
268  // Initialize the OLED Data structure, the underlying hardware, ...
269  // ...and pass a pointer to the active 8x8 pixel font
271 
272  // Print Welcome Message on OLED
274  sprintf(tempString,"MAXIM INTEGRATED");
275  printfToOLED(0,0,tempString);
276  sprintf(tempString,"REFERENCE DESIGN");
277  printfToOLED(0,1,tempString);
278  sprintf(tempString,"Revision %02d.%02d\r\n",MAJOR_REVISION,MINOR_REVISION);
279  printfToOLED(0,2,tempString);
280  sprintf(tempString, " ");
281  printfToOLED(0,3,tempString);
282 
283  // Clear the Screen, and then display the big Maxim banner for about 2 seconds
284  menu_cls();
286  printf("Maxim Petaluma (MAXREFDES30#) for the ZedBoard\r\n");
287  printf("Revision v%d.%d\r\n",MAJOR_REVISION,MINOR_REVISION);
288 
289  delay(ABOUT_ONE_SECOND * 3);
290 
291  /* The main menu loop runs infinitely to display an output similar to the following:
292  *
293  * Press a number to select sampling mode:
294  * {0} Continuous Sampling
295  * {1} Block Sampling
296  *
297  >>
298 
299  The main menu is printed to the screen, and then a blocking call to retrieve a single keypress from the UART is issued.
300  The result of that keypress is used to select the sampling mode
301  */
302  while(1)
303  {
304  int nSelectedMode;
305  int nSelectedChannel;
306  switch(nMenuState)
307  {
308  case MAIN_MENU:
309  menu_cls();
311  do{
313  printf("%c",uchInput);
314  if(uchInput<=1)
315  {
316  nMenuState = MENU_CHANNEL;
317  if(uchInput==0)
318  {
319  nSelectedMode = START_CONTINUOUS_SAMPLING;
320  }
321  else
322  {
323  nSelectedMode = MENU_SAMPLE_SPEED;
324  }
325  }
326  }while(uchInput>1);
327  break;
328 
329  case MENU_CHANNEL:
330  menu_cls();
332  do{
334  printf("%c",uchInput);
335  if(uchInput<=8)
336  {
337  nMenuState = nSelectedMode;
338  nSelectedChannel=uchInput;
339  }
340  }while(uchInput>8);
341  break;
342 
343  case MENU_SAMPLE_SPEED:
344  menu_cls();
346  do{
348  printf("%c",uchInput);
349  if(uchInput<=5)
350  {
351  g_nSampleRate=uchInput;
352  }
353  }while(uchInput>5);
354  nMenuState = MENU_SAMPLE_SIZE;
355  break;
356 
357  case MENU_SAMPLE_SIZE:
358  menu_cls();
360  do{
362  printf("%c",uchInput);
363  if(uchInput<=3)
364  {
365  if(uchInput==0)
366  g_unSampleSize=65536;
367  else if(uchInput==1)
368  g_unSampleSize=131072;
369  else if(uchInput==2)
370  g_unSampleSize=524288;
371  else
372  g_unSampleSize=1048576;
373  }
374  }while(uchInput>3);
375  nMenuState = START_BLOCK_SAMPLING;
376  break;
377 
379  menu_cls();
380  continuous_sampling(nSelectedChannel);
381  nMenuState=MAIN_MENU;
382  break;
383 
385  menu_cls();
386  printf("Press the ESC key to stop sampling\n\n");
387  printf("Sampling...\n");
388  unNumberOfSamplesReceived=start_sampling(g_unSampleSize, g_nSampleRate, auSamplesCh0, auSamplesCh1, auSamplesCh2, auSamplesCh3, auSamplesCh4, auSamplesCh5, auSamplesCh6, auSamplesCh7);
389  printf("Done sampling. Data are stored in the \"Samples\" array\n");
390  printf("Do you want to read the sampled data? (Y/N) \n>>");
391  do{
392 
394  printf("%c",uchInput);
395  nMenuState=MAIN_MENU;
396  if(uchInput=='y' || uchInput=='Y')
397  {
398  u32 i;
399  menu_cls();
400  printf("Press the ESC key to stop reading back the data\n\n");
402  if(nSelectedChannel<8)
403  {
404  u16 *auSamples;
405  if(nSelectedChannel==0)
406  auSamples=auSamplesCh0;
407  else if(nSelectedChannel==1)
408  auSamples=auSamplesCh1;
409  else if(nSelectedChannel==2)
410  auSamples=auSamplesCh2;
411  else if(nSelectedChannel==3)
412  auSamples=auSamplesCh3;
413  else if(nSelectedChannel==4)
414  auSamples=auSamplesCh4;
415  else if(nSelectedChannel==5)
416  auSamples=auSamplesCh5;
417  else if(nSelectedChannel==6)
418  auSamples=auSamplesCh6;
419  else if(nSelectedChannel==7)
420  auSamples=auSamplesCh7;
421  printf("Channel %i\n", nSelectedChannel);
422  for(i=0; i<unNumberOfSamplesReceived; i++)
423  {
424  if(uchInput==0x1B)
425  break;
426  if((Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x2C) & 0x02) == 0)
427  {
428  uchInput = Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x30); // read the FIFO (only the LSB is valid).
429  if(uchInput==0x1B)
430  break;
431  }
432  printf("%i\n", auSamples[i]);
433  }
434  }
435  else
436  {
437  printf("Ch 0, Ch 1, Ch 2, Ch 3, Ch 4, Ch 5, Ch 6, Ch 7\n");
438  for(i=0; i<unNumberOfSamplesReceived; i++)
439  {
440  if(uchInput==0x1B)
441  break;
442  if((Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x2C) & 0x02) == 0)
443  {
444  uchInput = Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x30); // read the FIFO (only the LSB is valid).
445  if(uchInput==0x1B)
446  break;
447  }
448  printf("%i, %i, %i, %i, %i, %i, %i, %i\n", auSamplesCh0[i], auSamplesCh1[i], auSamplesCh2[i], auSamplesCh3[i], auSamplesCh4[i], auSamplesCh5[i], auSamplesCh6[i], auSamplesCh7[i]);
449  }
450  }
451 
452  if(i!=unNumberOfSamplesReceived) //if the Escape key is pressed before the for loop is finished
453  break; //go back to the main menu
454  printf("End of samples. Press any key to go back to the main menu\n");
455  nMenuState=MAIN_MENU;
457  break;
458  }
459  }while(uchInput!='n' && uchInput!='y' && uchInput!='Y' && uchInput!='N');
460 
461  break;
462 
463  default:
464  printf("Invalid Keypress, please try again\r\n");
465  delay(ABOUT_ONE_SECOND * 5);
466  nMenuState = MAIN_MENU;
467  break;
468  }
469  }
470 
472  return 0;
473 }