Carmel (MAXREFDES18#) Code Documentation  V01.00
High Accuracy Analog Current/Voltage Output
 All Data Structures Files Functions Variables Macros Pages
MAXREFDES18.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  ***************************************************************************/
77 #include <stdio.h>
78 #include "platform.h"
79 #include "menu.h"
80 #include "utilities.h"
81 #include "MAXREFDES18.h"
82 
83 #define MAJOR_REVISION 1
84 #define MINOR_REVISION 0
85 
86 // Globals
88 unsigned int g_unSevenSegmentValue=0;
89 char g_sInputString[ INPUT_STRING_MAX_SIZE ]; //This string will hold user input from terminal.
95 XGpio g_xGpioLed;
97 char g_tempString[32];
98 
101 u32 g_unActivePeripheralAddressSPI =XPAR_SPI_0_BASEADDR;
103 unsigned char g_auchPortType[4];
104 
105 u8 font[1024] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x00, NUL
106  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x01, SOH
107  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x02, STX
108  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x03, ETX
109  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x03, EOT
110  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x05, ENQ
111  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x06, ACK
112  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x07, BEL
113  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x08, BS
114  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x09, HT
115  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0A, LF
116  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0B, VT
117  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0C, FF
118  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0D, CR
119  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0E, SO
120  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0F, SI
121  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x10, DLE
122  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x11, DC1
123  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x12, DC2
124  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x13, DC3
125  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x13, DC4
126  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x15, NAK
127  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x16, SYN
128  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x17, ETB
129  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x18, CAN
130  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x19, EM
131  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1A, SUB
132  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1B, ESC
133  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1C, FS
134  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1D, GS
135  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1E, RS
136  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1F, US
137  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x20, space
138  0x00,0x00,0x00,0x5f,0x00,0x00,0x00,0x00, // 0x21, !
139  0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00, // 0x22, "
140  0x64,0x3c,0x26,0x64,0x3c,0x26,0x24,0x00, // 0x23, #
141  0x26,0x49,0x49,0x7f,0x49,0x49,0x32,0x00, // 0x23, $
142  0x42,0x25,0x12,0x08,0x24,0x52,0x21,0x00, // 0x25, %
143  0x20,0x50,0x4e,0x55,0x22,0x58,0x28,0x00, // 0x26, &
144  0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00, // 0x27, '
145  0x00,0x00,0x1c,0x22,0x41,0x00,0x00,0x00, // 0x28, (
146  0x00,0x00,0x00,0x41,0x22,0x1c,0x00,0x00, // 0x29, )
147  0x00,0x15,0x15,0x0e,0x0e,0x15,0x15,0x00, // 0x2A, *
148  0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00, // 0x2B, +
149  0x00,0x00,0x00,0x50,0x30,0x00,0x00,0x00, // 0x2C, ,
150  0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00, // 0x2D, -
151  0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, // 0x2E, .
152  0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00, // 0x2F, /
153  0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, // 0x30, 0
154  0x00,0x00,0x41,0x7f,0x40,0x00,0x00,0x00, // 0x31, 1
155  0x00,0x42,0x61,0x51,0x49,0x6e,0x00,0x00, // 0x32, 2
156  0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00, // 0x33, 3
157  0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x00, // 0x33, 4
158  0x00,0x27,0x49,0x49,0x49,0x71,0x00,0x00, // 0x35, 5
159  0x00,0x3c,0x4a,0x49,0x48,0x70,0x00,0x00, // 0x36, 6
160  0x00,0x43,0x21,0x11,0x0d,0x03,0x00,0x00, // 0x37, 7
161  0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, // 0x38, 8
162  0x00,0x06,0x09,0x49,0x29,0x1e,0x00,0x00, // 0x39, 9
163  0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00, // 0x3A, :
164  0x00,0x00,0x00,0x52,0x30,0x00,0x00,0x00, // 0x3B, //
165  0x00,0x00,0x08,0x14,0x14,0x22,0x00,0x00, // 0x3C, <
166  0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00, // 0x3D, =
167  0x00,0x00,0x22,0x14,0x14,0x08,0x00,0x00, // 0x3E, >
168  0x00,0x02,0x01,0x59,0x05,0x02,0x00,0x00, // 0x3F, ?
169  0x3e,0x41,0x5d,0x55,0x4d,0x51,0x2e,0x00, // 0x40, @
170  0x40,0x7c,0x4a,0x09,0x4a,0x7c,0x40,0x00, // 0x41, A
171  0x41,0x7f,0x49,0x49,0x49,0x49,0x36,0x00, // 0x42, B
172  0x1c,0x22,0x41,0x41,0x41,0x41,0x22,0x00, // 0x43, C
173  0x41,0x7f,0x41,0x41,0x41,0x22,0x1c,0x00, // 0x44, D
174  0x41,0x7f,0x49,0x49,0x5d,0x41,0x63,0x00, // 0x45, E
175  0x41,0x7f,0x49,0x09,0x1d,0x01,0x03,0x00, // 0x46, F
176  0x1c,0x22,0x41,0x49,0x49,0x3a,0x08,0x00, // 0x47, G
177  0x41,0x7f,0x08,0x08,0x08,0x7f,0x41,0x00, // 0x48, H
178  0x00,0x41,0x41,0x7F,0x41,0x41,0x00,0x00, // 0x49, I
179  0x30,0x40,0x41,0x41,0x3F,0x01,0x01,0x00, // 0x4A, J
180  0x41,0x7f,0x08,0x0c,0x12,0x61,0x41,0x00, // 0x4B, K
181  0x41,0x7f,0x41,0x40,0x40,0x40,0x60,0x00, // 0x4C, L
182  0x41,0x7f,0x42,0x0c,0x42,0x7f,0x41,0x00, // 0x4D, M
183  0x41,0x7f,0x42,0x0c,0x11,0x7f,0x01,0x00, // 0x4E, N
184  0x1c,0x22,0x41,0x41,0x41,0x22,0x1c,0x00, // 0x4F, O
185  0x41,0x7f,0x49,0x09,0x09,0x09,0x06,0x00, // 0x50, P
186  0x0c,0x12,0x21,0x21,0x61,0x52,0x4c,0x00, // 0x51, Q
187  0x41,0x7f,0x09,0x09,0x19,0x69,0x46,0x00, // 0x52, R
188  0x66,0x49,0x49,0x49,0x49,0x49,0x33,0x00, // 0x53, S
189  0x03,0x01,0x41,0x7f,0x41,0x01,0x03,0x00, // 0x54, T
190  0x01,0x3f,0x41,0x40,0x41,0x3f,0x01,0x00, // 0x55, U
191  0x01,0x0f,0x31,0x40,0x31,0x0f,0x01,0x00, // 0x56, V
192  0x01,0x1f,0x61,0x14,0x61,0x1f,0x01,0x00, // 0x57, W
193  0x41,0x41,0x36,0x08,0x36,0x41,0x41,0x00, // 0x58, X
194  0x01,0x03,0x44,0x78,0x44,0x03,0x01,0x00, // 0x59, Y
195  0x43,0x61,0x51,0x49,0x45,0x43,0x61,0x00, // 0x5A, Z
196  0x00,0x00,0x7f,0x41,0x41,0x00,0x00,0x00, // 0x5B, [
197  0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x00, // 0x5C,
198  0x00,0x00,0x41,0x41,0x7f,0x00,0x00,0x00, // 0x5D, ]
199  0x00,0x04,0x02,0x01,0x01,0x02,0x04,0x00, // 0x5E, ^
200  0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00, // 0x5F, _
201  0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00, // 0x60, `
202  0x00,0x34,0x4a,0x4a,0x4a,0x3c,0x40,0x00, // 0x61, a
203  0x00,0x41,0x3f,0x48,0x48,0x48,0x30,0x00, // 0x62. b
204  0x00,0x3c,0x42,0x42,0x42,0x24,0x00,0x00, // 0x63, c
205  0x00,0x30,0x48,0x48,0x49,0x3f,0x40,0x00, // 0x63, d
206  0x00,0x3c,0x4a,0x4a,0x4a,0x2c,0x00,0x00, // 0x65, e
207  0x00,0x00,0x48,0x7e,0x49,0x09,0x00,0x00, // 0x66, f
208  0x00,0x26,0x49,0x49,0x49,0x3f,0x01,0x00, // 0x67, g
209  0x41,0x7f,0x48,0x04,0x44,0x78,0x40,0x00, // 0x68, h
210  0x00,0x00,0x44,0x7d,0x40,0x00,0x00,0x00, // 0x69, i
211  0x00,0x00,0x40,0x44,0x3d,0x00,0x00,0x00, // 0x6A, j
212  0x41,0x7f,0x10,0x18,0x24,0x42,0x42,0x00, // 0x6B, k
213  0x00,0x40,0x41,0x7f,0x40,0x40,0x00,0x00, // 0x6C, l
214  0x42,0x7e,0x02,0x7c,0x02,0x7e,0x40,0x00, // 0x6D, m
215  0x42,0x7e,0x44,0x02,0x42,0x7c,0x40,0x00, // 0x6E, n
216  0x00,0x3c,0x42,0x42,0x42,0x3c,0x00,0x00, // 0x6F, o
217  0x00,0x41,0x7f,0x49,0x09,0x09,0x06,0x00, // 0x70, p
218  0x00,0x06,0x09,0x09,0x49,0x7f,0x41,0x00, // 0x71, q
219  0x00,0x42,0x7e,0x44,0x02,0x02,0x04,0x00, // 0x72, r
220  0x00,0x64,0x4a,0x4a,0x4a,0x36,0x00,0x00, // 0x73, s
221  0x00,0x04,0x3f,0x44,0x44,0x20,0x00,0x00, // 0x73, t
222  0x00,0x02,0x3e,0x40,0x40,0x22,0x7e,0x40, // 0x75, u
223  0x02,0x0e,0x32,0x40,0x32,0x0e,0x02,0x00, // 0x76, v
224  0x02,0x1e,0x62,0x18,0x62,0x1e,0x02,0x00, // 0x77, w
225  0x42,0x62,0x14,0x08,0x14,0x62,0x42,0x00, // 0x78, x
226  0x01,0x43,0x45,0x38,0x05,0x03,0x01,0x00, // 0x79, y
227  0x00,0x46,0x62,0x52,0x4a,0x46,0x62,0x00, // 0x7A, z
228  0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00, // 0x7B, {
229  0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00, // 0x7C, |
230  0x00,0x00,0x00,0x41,0x36,0x08,0x00,0x00, // 0x7D, }
231  0x00,0x18,0x08,0x08,0x10,0x10,0x18,0x00, // 0x7E, ~
232  0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55 // 0x7F, DEL
233  };
234 
235 int main()
247 {
248  // Variables for the main() function
249  u8 uchInput=0;
250  int nMenuState = MODE_MENU;
251  char tempString[256];
252  u8 uchMOSIBuffer[3];
253  u8 uchMISOBuffer[3];
254  int DAC_CODE = 0;
255 
256  XUartLite uartPortA,uartPortB,uartPortC,uartPortD;
257 
258  // Xilinx provided utility to initialize the hardware/firmware drivers and enable/disable cache
259  init_platform();
260 
261  // Clear the Hyperterminal screen by sending printf("\033[2J");
262  menu_cls();
263 
264  // Initialize the UARTs on the Zedboard PMOD a..d
265  // Note that after this initialization, these variables uartPortA,B,C,D are no longer used
266  // All send and receive calls to the UARTS are made directly to their baseaddress
267  XUartLite_Initialize(&uartPortA,XPAR_AXI_UARTLITE_0_DEVICE_ID);
268  XUartLite_ResetFifos(&uartPortA);
269  XUartLite_Initialize(&uartPortB,XPAR_AXI_UARTLITE_1_DEVICE_ID);
270  XUartLite_ResetFifos(&uartPortB);
271  XUartLite_Initialize(&uartPortC,XPAR_AXI_UARTLITE_2_DEVICE_ID);
272  XUartLite_ResetFifos(&uartPortC);
273  XUartLite_Initialize(&uartPortD,XPAR_AXI_UARTLITE_3_DEVICE_ID);
274  XUartLite_ResetFifos(&uartPortD);
275  delay(100);
276 
277  // Toggle the LEDs so that the user knows the board is awake
278  XGpio_Initialize(&g_xGpioLed, XPAR_AXI_GPIO_LED_DEVICE_ID);
279  XGpio_SetDataDirection(&g_xGpioLed, 1, 0x00000000); // Set the LED peripheral to outputs
281 
282  // Initialize the OLED Data structure, the underlying hardware, ...
283  // ...and pass a pointer to the active 8x8 pixel font
285 
286  // Print Welcome Message on OLED
287  sprintf(tempString,"MAXIM CARMEL");
288  printfToOLED(0,0,tempString);
289  sprintf(tempString,"REFERENCE DESIGN");
290  printfToOLED(0,1,tempString);
291  sprintf(tempString,"Version %02d.%02d\r\n",MAJOR_REVISION,MINOR_REVISION);
292  printfToOLED(0,2,tempString);
293 
294  // Initialize the GPIO connected to PMOD Ports A,B,C,D
295  XGpio_Initialize(&g_xGpioPmodPortA, XPAR_AXI_GPIO_0_DEVICE_ID);
296  XGpio_Initialize(&g_xGpioPmodPortB, XPAR_AXI_GPIO_1_DEVICE_ID);
297  XGpio_Initialize(&g_xGpioPmodPortC, XPAR_AXI_GPIO_2_DEVICE_ID);
298  XGpio_Initialize(&g_xGpioPmodPortD, XPAR_AXI_GPIO_3_DEVICE_ID);
299  XGpio_SetDataDirection(&g_xGpioPmodPortA, 1, 0x00000000); // Set the GPIO1 to all be outputs
300  XGpio_SetDataDirection(&g_xGpioPmodPortB, 1, 0x00000000); // Set the GPIO1 to all be outputs
301  XGpio_SetDataDirection(&g_xGpioPmodPortC, 1, 0x00000000); // Set the GPIO1 to all be outputs
302  XGpio_SetDataDirection(&g_xGpioPmodPortD, 1, 0x00000000); // Set the GPIO1 to all be outputs
303 
304  // Inialize the GPIO that drives the mux/select bits on the PMOD port multiplexer
305  XGpio_Initialize(&g_xGpioPmodPortMuxIO, XPAR_AXI_GPIO_PMODPORTMUX_DEVICE_ID);
306  XGpio_SetDataDirection(&g_xGpioPmodPortMuxIO, 1, 0x00); // Set the GPIO2 direction to outputs
307 
308  // Initialize the ports 0..3 (A..D) with the appropriate technology
309  // PMOD_PORT_TYPE_UART, PMOD_PORT_TYPE_SPI, PMOD_PORT_TYPE_GPIO, PMOD_PORT_TYPE_I2C
314 
315  // Configure the PMOD Port Multiplexers for the appropriate PMOD interfaces (ports a,b,c,d)
317 
318  // Clear the Screen, and then display the big Maxim banner for about 2 seconds
319  menu_cls();
321 
322  printf("Maxim Carmel (MAXREFDES18#) for the ZedBoard\r\n");
323  printf("Revision v%02d.%02d\r\n",MAJOR_REVISION,MINOR_REVISION);
324 
325 
326  // write the MAX5316 configuration register to set it in normal operation mode.
327  // R3:R0=0100, D15:D0=0b0010 1000 0000 0000, +0b0000.
328  uchMOSIBuffer[0]=0x42;
329  uchMOSIBuffer[1]=0x80;
330  uchMOSIBuffer[2]=0x00;
331  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 3, 0, 2);
332 
333  delay(ABOUT_ONE_SECOND * 3);
334 
335  /* The main menu loop runs infinitely to display an output mode or range select menu.
336  */
337 
338  while(1)
339  {
340  switch(nMenuState)
341  {
342  case MODE_MENU:
344  nMenuState = WAIT_KEYPRESS;
345  do{
347  printf("%c\r\n",uchInput+48);
348  if(uchInput<=1)
349  {
350  if(uchInput==0)
351  nMenuState = CURRENT_RANGE_MENU;
352  else
353  nMenuState = VOLTAGE_RANGE_MENU;
354  }
355  }while(uchInput>1);
356  break;
357 
358  // current modes.
359  case CURRENT_RANGE_MENU:
361  nMenuState = WAIT_KEYPRESS;
362  do{
364  printf("%c\r\n",uchInput+48);
365  if(uchInput<=3)
366  {
367  if(uchInput==0)
368  nMenuState = CURRENT_RANGE_20_20_MENU;
369  else if(uchInput==1)
370  nMenuState = CURRENT_RANGE_0_20_MENU;
371  else if(uchInput==2)
372  nMenuState = CURRENT_RANGE_4_20_MENU;
373  else
374  nMenuState = MODE_MENU;
375  }
376  }while(uchInput>3);
377  break;
378 
380  nMenuState = WAIT_KEYPRESS;
381 
382  printf("Mode 1: Bipolar current +/-20mA.\r\n");
383  printf("IdealIout = 0.5 * (VAIN - 0.5 * VREFIN)/Rsense.\r\n");
384  printf("Where Rsense = 42.2OHM for 20%% OVERRANGE, Rsense = 48.7OHM for 5%% OVERRANGE.\r\n");
385  printf("VAIN = 4.096V * DAC_CODE/65536.\r\n");
386  printf("VREFIN = 4.096V.\r\n");
387 
389 
390  // 1. configure the MAX15500. DIN[10], DIN[2:0], reserved, default to 0.
391  // DIN[13:11]=001, mode DIN[9:7]=001, DIN[6:4]=VBOTH[2:0], default to 101 = +/-20V. DIN[3]= thermal protection on/off.
392  uchMOSIBuffer[0]=0x23;
393  uchMOSIBuffer[1]=0x60;
394  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 2, 0, 1);
395 
396  // 2. write MAX5316 DIN register. 0x0000
397  // R3:R0=0001, D15:D0=16-bit straight binary data, +0b0000.
398  uchMOSIBuffer[0]=0x10 + ((DAC_CODE >> 12) & 0xF);
399  uchMOSIBuffer[1]=(DAC_CODE >> 4) & 0xFF;
400  uchMOSIBuffer[2]=(DAC_CODE << 4) & 0xF0;
401 
402  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 3, 0, 2);
403 
404  nMenuState = CURRENT_RANGE_MENU;
405  break;
407  nMenuState = WAIT_KEYPRESS;
408 
409  printf("Mode 2: Unipolar current 0 to 20mA.\r\n");
410  printf("IdealIout = 0.2625 * (VAIN - 0.05 * VREFIN)/Rsense.\r\n");
411  printf("Where Rsense = 42.2OHM for 20%% OVERRANGE, Rsense = 48.7OHM for 5%% OVERRANGE.\r\n");
412  printf("VAIN = 4.096V * DAC_CODE/65536.\r\n");
413  printf("VREFIN = 4.096V.\r\n");
414 
416 
417  // 1. configure the MAX15500. DIN[10], DIN[2:0], reserved, default to 0.
418  // DIN[13:11]=001, mode DIN[9:7]=010, DIN[6:4]=VBOTH[2:0], default to 101 = +/-20V. DIN[3]= thermal protection on/off.
419  uchMOSIBuffer[0]=0x25;
420  uchMOSIBuffer[1]=0x60;
421  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 2, 0, 1);
422 
423  // 2. write MAX5316 DIN register. 0x0000
424  // R3:R0=0001, D15:D0=16-bit straight binary data, +0b0000.
425  uchMOSIBuffer[0]=0x10 + ((DAC_CODE >> 12) & 0xF);
426  uchMOSIBuffer[1]=(DAC_CODE >> 4) & 0xFF;
427  uchMOSIBuffer[2]=(DAC_CODE << 4) & 0xF0;
428 
429  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 3, 0, 2);
430 
431  nMenuState = CURRENT_RANGE_MENU;
432  break;
434  nMenuState = WAIT_KEYPRESS;
435 
436  printf("Mode 3: Unipolar current 4 to 20mA.\r\n");
437  printf("IdealIout = 0.2625 * (VAIN - 0.05 * VREFIN)/Rsense.\r\n");
438  printf("Where Rsense = 42.2OHM for 20%% OVERRANGE, Rsense = 48.7OHM for 5%% OVERRANGE.\r\n");
439  printf("VAIN = 4.096V * DAC_CODE/65536.\r\n");
440  printf("VREFIN = 4.096V.\r\n");
441 
443 
444  // 1. configure the MAX15500. DIN[10], DIN[2:0], reserved, default to 0.
445  // DIN[13:11]=001, mode DIN[9:7]=011, DIN[6:4]=VBOTH[2:0], default to 101 = +/-20V. DIN[3]= thermal protection on/off.
446  uchMOSIBuffer[0]=0x27;
447  uchMOSIBuffer[1]=0x60;
448  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 2, 0, 1);
449 
450  // 2. write MAX5316 DIN register. 0x0000
451  // R3:R0=0001, D15:D0=16-bit straight binary data, +0b0000.
452  uchMOSIBuffer[0]=0x10 + ((DAC_CODE >> 12) & 0xF);
453  uchMOSIBuffer[1]=(DAC_CODE >> 4) & 0xFF;
454  uchMOSIBuffer[2]=(DAC_CODE << 4) & 0xF0;
455 
456  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 3, 0, 2);
457 
458  nMenuState = CURRENT_RANGE_MENU;
459  break;
460 
461  // voltage modes.
462  case VOLTAGE_RANGE_MENU:
464  nMenuState = WAIT_KEYPRESS;
465  do{
467  printf("%c\r\n",uchInput+48);
468  if(uchInput<=3)
469  {
470  if(uchInput==0)
471  nMenuState = VOLTAGE_RANGE_10_10_MENU;
472  else if(uchInput==1)
473  nMenuState = VOLTAGE_RANGE_0_10_MENU;
474  else if(uchInput==2)
475  nMenuState = VOLTAGE_RANGE_0_5_MENU;
476  else
477  nMenuState = MODE_MENU;
478  }
479  }while(uchInput>3);
480  break;
481 
483  nMenuState = WAIT_KEYPRESS;
484 
485  printf("Mode 5: Bipolar voltage +/-10V.\r\n");
486  printf("IdealVout = IdealGain * (VAIN - 0.5 * VREFIN).\r\n");
487  printf("Where IdealGain = 6 for 20%% OVERRANGE, IdealGain = 5.25 for 5%% OVERRANGE.\r\n");
488  printf("VAIN = 4.096V * DAC_CODE/65536.\r\n");
489  printf("VREFIN = 4.096V.\r\n");
490 
492 
493  // 1. configure the MAX15500. DIN[10], DIN[2:0], reserved, default to 0.
494  // DIN[13:11]=001, mode DIN[9:7]=101, DIN[6:4]=VBOTH[2:0], default to 101 = +/-20V. DIN[3]= thermal protection on/off.
495  uchMOSIBuffer[0]=0x2B;
496  uchMOSIBuffer[1]=0x60;
497  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 2, 0, 1);
498 
499  // 2. write MAX5316 DIN register. 0x0000
500  // R3:R0=0001, D15:D0=16-bit straight binary data, +0b0000.
501  uchMOSIBuffer[0]=0x10 + ((DAC_CODE >> 12) & 0xF);
502  uchMOSIBuffer[1]=(DAC_CODE >> 4) & 0xFF;
503  uchMOSIBuffer[2]=(DAC_CODE << 4) & 0xF0;
504 
505  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 3, 0, 2);
506 
507  nMenuState = VOLTAGE_RANGE_MENU;
508  break;
509 
511  nMenuState = WAIT_KEYPRESS;
512 
513  printf("Mode 6: Unipolar voltage 0 to 10V.\r\n");
514  printf("IdealVout = IdealGain * (VAIN - 0.05 * VREFIN).\r\n");
515  printf("Where IdealGain = 3.125 for 20%% OVERRANGE, IdealGain = 2.75 for 5%% OVERRANGE.\r\n");
516  printf("VAIN = 4.096V * DAC_CODE/65536.\r\n");
517  printf("VREFIN = 4.096V.\r\n");
518 
520 
521  // 1. configure the MAX15500. DIN[10], DIN[2:0], reserved, default to 0.
522  // DIN[13:11]=001, mode DIN[9:7]=110, DIN[6:4]=VBOTH[2:0], default to 101 = +/-20V. DIN[3]= thermal protection on/off.
523  uchMOSIBuffer[0]=0x2D;
524  uchMOSIBuffer[1]=0x60;
525  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 2, 0, 1);
526 
527  // 2. write MAX5316 DIN register. 0x0000
528  // R3:R0=0001, D15:D0=16-bit straight binary data, +0b0000.
529  uchMOSIBuffer[0]=0x10 + ((DAC_CODE >> 12) & 0xF);
530  uchMOSIBuffer[1]=(DAC_CODE >> 4) & 0xFF;
531  uchMOSIBuffer[2]=(DAC_CODE << 4) & 0xF0;
532 
533  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 3, 0, 2);
534 
535  nMenuState = VOLTAGE_RANGE_MENU;
536  break;
537 
539  nMenuState = WAIT_KEYPRESS;
540 
541  printf("Mode 7: Unipolar voltage 0 to 5V.\r\n");
542  printf("IdealVout = IdealGain * (VAIN - 0.05 * VREFIN).\r\n");
543  printf("Where IdealGain = 1.5625 for 20%% OVERRANGE, IdealGain = 1.375 for 5%% OVERRANGE.\r\n");
544  printf("VAIN = 4.096V * DAC_CODE/65536.\r\n");
545  printf("VREFIN = 4.096V.\r\n");
546 
548 
549  // 1. configure the MAX15500. DIN[10], DIN[2:0], reserved, default to 0.
550  // DIN[13:11]=001, mode DIN[9:7]=111, DIN[6:4]=VBOTH[2:0], default to 101 = +/-20V. DIN[3]= thermal protection on/off.
551  uchMOSIBuffer[0]=0x2F;
552  uchMOSIBuffer[1]=0x60;
553  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 2, 0, 1);
554 
555  // 2. write MAX5316 DIN register. 0x0000
556  // R3:R0=0001, D15:D0=16-bit straight binary data, +0b0000.
557  uchMOSIBuffer[0]=0x10 + ((DAC_CODE >> 12) & 0xF);
558  uchMOSIBuffer[1]=(DAC_CODE >> 4) & 0xFF;
559  uchMOSIBuffer[2]=(DAC_CODE << 4) & 0xF0;
560 
561  SpiRW(g_unActivePeripheralAddressSPI, 1, 0, uchMOSIBuffer, uchMISOBuffer, 3, 0, 2);
562 
563  nMenuState = VOLTAGE_RANGE_MENU;
564  break;
565  }
566  }
568  return 0;
569 }
570 
571 
572 
573 
574 
575 
576 
577 
578 
579 
580 
581 
582 
583 
584 
585 
586 
587 
588 
589 
590 
591 
592 
593 
594 
595 
596 
597 
598 
599 
600 
601 
602 
603 
604 
605 
606 
607 
608 
609 
610 
611 
612 
613 
614