| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC2423A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2423A Demonstration Board.
3 LTM9100: Anyside™ High Voltage Isolated Switch Controller with I²C Command and Telemetry
4
5 @verbatim
6
7 NOTES
8 Setup:
9 Set the terminal baud rate to 115200 and select the newline terminator.
10
11 USER INPUT DATA FORMAT:
12 decimal : 1024
13 hex : 0x400
14 octal : 02000 (leading 0 "zero")
15 binary : B10000000000
16 float : 1024.0
17
18 @endverbatim
19
20 http://www.linear.com/product/LTM9100
21
22 http://www.linear.com/product/LTC9100#demoboards
23
24
25 Copyright 2018(c) Analog Devices, Inc.
26
27 All rights reserved.
28
29 Redistribution and use in source and binary forms, with or without
30 modification, are permitted provided that the following conditions are met:
31 - Redistributions of source code must retain the above copyright
32 notice, this list of conditions and the following disclaimer.
33 - Redistributions in binary form must reproduce the above copyright
34 notice, this list of conditions and the following disclaimer in
35 the documentation and/or other materials provided with the
36 distribution.
37 - Neither the name of Analog Devices, Inc. nor the names of its
38 contributors may be used to endorse or promote products derived
39 from this software without specific prior written permission.
40 - The use of this software may or may not infringe the patent rights
41 of one or more patent holders. This license does not release you
42 from the requirement that you obtain separate licenses from these
43 patent holders to use this software.
44 - Use of the software either in source or binary form, must be run
45 on or directly connected to an Analog Devices Inc. component.
46
47 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
48 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
49 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
51 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
53 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
54 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
55 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 */
58
59 /*! @file
60 @ingroup LTM9100
61 */
62
63 #include <Arduino.h>
64 #include <stdint.h>
65 #include "Linduino.h"
66 #include "UserInterface.h"
67 #include "LT_I2C.h"
68 #include "QuikEval_EEPROM.h"
69 #include "LTM9100.h"
70
71 float sense_resistor = 0.008; //default resistance in ohms
72 float adin_gain = 0.035; //default
73 float adin2_gain = 0.035; //default
74 uint8_t i2c_address = 0x10; //default
75
76 //! Initialize Linduino
77 void setup()
78 {
79 //Port initialization
80 DDRD = DDRD | B00111100; // Sets data direction of Digital Pins 0-7 (Logical OR to not interfere with Rx and Tx)
81 PORTD = B00000000; // Initializes Digital Pins 0-7 to LOW
82 DDRB = B00011111; // Sets data direction of Digital Pins 8-13
83 PORTB = B00000001; // Initializes Digital Pin 8 HIGH and 9-13 to LOW, Pin 8 is I2C Linduino select bit
84 i2c_enable(); // Initializes Linduino I2C port.
85 Serial.begin(115200); // Initialize the serial port to the PC
86 print_title();
87 print_prompt();
88 }
89
90 //! Repeats Linduino loop
91 void loop()
92 {
93 int8_t ack=0;
94 uint8_t user_command;
95 uint8_t data;
96 uint8_t user_register;
97
98 if (Serial.available())
99 {
100 user_command = read_int(); //! Reads the user command
101 Serial.println(user_command); // Print user command
102
103 //! Reads or writes to a LTM9100 and prints result.
104 switch (user_command)
105 {
106 case 1:
107 // Read every register and print it's data.
108 ack |= LTM9100_print_all_registers(i2c_address);
109 break;
110 case 2:
111 // Read a single register and print it's data.
112 Serial.print(F("\nAddress (in hex with '0x' prefix) of register to read: "));
113 user_register = read_int();
114 Serial.print("0x");
115 Serial.println(user_register, HEX);
116 if (!valid_register(user_register, reg_read_list, sizeof(reg_read_list)))
117 {
118 Serial.println(F(" Invalid input."));
119 break;
120 }
121 ack |= LTM9100_register_read(i2c_address, user_register, &data);
122 if (!ack)
123 {
124 Serial.print("Register data: 0x");
125 Serial.println(data, HEX);
126 }
127 break;
128 case 3:
129 // Write a byte to a chosen register.
130 Serial.print(F("\nAddress (in hex with '0x' prefix) of register to write: "));
131 user_register = read_int();
132 Serial.print("0x");
133 Serial.println(user_register, HEX);
134 if (!valid_register(user_register, reg_write_list, sizeof(reg_write_list)))
135 {
136 Serial.println(F(" Invalid input."));
137 break;
138 }
139 Serial.print(F("Data (in hex with '0x' prefix) to write: "));
140 data = read_int();
141 Serial.println(data, HEX);
142 ack |= LTM9100_register_write(i2c_address, user_register, data);
143 if (!ack)
144 {
145 Serial.print("0x");
146 Serial.print(data, HEX);
147 Serial.print(" written to register 0x");
148 Serial.println(user_register, HEX);
149 }
150 break;
151 case 4:
152 // Set a single bit within a chosen register.
153 Serial.print(F("\nAddress (in hex with '0x' prefix) of register: "));
154 user_register = read_int();
155 Serial.print("0x");
156 Serial.println(user_register, HEX);
157 if (!valid_register(user_register, reg_write_list, sizeof(reg_write_list)))
158 {
159 Serial.println(F(" Invalid input."));
160 break;
161 }
162 Serial.print(F("Bit position (0-7) to set: "));
163 data = read_int();
164 if (data < 0 || data > 7)
165 {
166 Serial.println(F(" Invalid input."));
167 break;
168 }
169 Serial.println(data, DEC);
170 ack |= LTM9100_bit_set(i2c_address, user_register, data);
171 if (!ack)
172 {
173 Serial.print("Bit set. Register data is now 0x");
174 ack |= LTM9100_register_read(i2c_address, user_register, &data);
175 Serial.println(data, HEX);
176 }
177 break;
178 case 5:
179 // Clear a single bit within a chosen register.
180 Serial.print(F("\nAddress (in hex with '0x' prefix) of register: "));
181 user_register = read_int();
182 Serial.print("0x");
183 Serial.println(user_register, HEX);
184 if (!valid_register(user_register, reg_write_list, sizeof(reg_write_list)))
185 {
186 Serial.println(F(" Invalid input."));
187 break;
188 }
189 Serial.print(F("Bit position (0-7) to clear: "));
190 data = read_int();
191 if (data < 0 || data > 7)
192 {
193 Serial.println(F("Invalid input."));
194 break;
195 }
196 Serial.println(data, DEC);
197 ack |= LTM9100_bit_clear(i2c_address, user_register, data);
198 if (!ack)
199 {
200 Serial.print("Bit cleared. Register data is now 0x");
201 ack |= LTM9100_register_read(i2c_address, user_register, &data);
202 Serial.println(data, HEX);
203 }
204 break;
205 case 6:
206 // Write a byte to a chosen register via the Mass Write I2C address.
207 Serial.print(F("\nAddress (in hex with '0x' prefix) of register to write: "));
208 user_register = read_int();
209 Serial.print("0x");
210 Serial.println(user_register, HEX);
211 if (!valid_register(user_register, reg_write_list, sizeof(reg_write_list)))
212 {
213 Serial.println(F(" Invalid input."));
214 break;
215 }
216 Serial.print(F("Data (in hex with '0x' prefix) to write: "));
217 data = read_int();
218 Serial.println(data, HEX);
219 ack |= LTM9100_register_write(0x1F, user_register, data);
220 if (!ack)
221 {
222 Serial.print("0x");
223 Serial.print(data, HEX);
224 Serial.print(" written to register 0x");
225 Serial.println(user_register, HEX);
226 }
227 break;
228 case 7:
229 ack |= menu_read_status(); // Print status menu
230 break;
231 case 8:
232 ack |= menu_read_write_faults_alerts(false); // Print Faults menu
233 break;
234 case 9:
235 ack |= menu_read_write_faults_alerts(true); // Print Alert setting menu
236 break;
237 case 10:
238 ack |= menu_read_write_controls(); // Print Controls menu
239 break;
240 case 11:
241 ack |= menu_read_write_adc_params(); // Print ADC menu
242 break;
243 case 12:
244 ack |= LTM9100_continuous_read_all_registers(i2c_address);
245 break;
246 }
247 if (ack != 0)
248 {
249 Serial.print(F("Error: No Acknowledge. \n"));
250 }
251 print_prompt();
252 }
253 }
254
255 // Function Definitions
256
257 //! Prints a warning if the demo board is not detected.
258 void print_warning_prompt()
259 {
260 Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
261 }
262
263 //! Prints the title block when program first starts.
264 void print_title()
265 {
266 Serial.print(F("\n*****************************************************************\n"));
267 Serial.print(F("* LTM9100 Demonstration Program *\n"));
268 Serial.print(F("* *\n"));
269 Serial.print(F("* This program demonstrates sending and receiving data from *\n"));
270 Serial.print(F("* the LTM9100 via I2C. *\n"));
271 Serial.print(F("* *\n"));
272 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
273 Serial.print(F("* *\n"));
274 Serial.print(F("*****************************************************************\n"));
275 }
276
277 // Prints main menu.
278 void print_prompt()
279 {
280 //! Displays the Read/Write Registers menu
281 Serial.print(F("\nRead/Write Registers\n\n"));
282 Serial.print(F(" 1-Read All Registers\n"));
283 Serial.print(F(" 2-Read Single Register\n"));
284 Serial.print(F(" 3-Write Single Register\n"));
285 Serial.print(F(" 4-Set Bit\n"));
286 Serial.print(F(" 5-Clear Bit\n"));
287 Serial.print(F(" 6-Write Register to Mass Write Address\n"));
288 Serial.println(F(" 7-Read Status"));
289 Serial.println(F(" 8-Read/Write Faults"));
290 Serial.println(F(" 9-Read/Write Alerts"));
291 Serial.println(F(" 10-Read/Write Controls"));
292 Serial.println(F(" 11-Read/Write ADC parameters"));
293 Serial.println(F(" 12-Continuously Read Registers"));
294 Serial.print(F("\nEnter a command: "));
295 }
296
297 int8_t menu_read_status()
298 {
299 int8_t ack=0;
300 uint8_t user_command;
301 uint8_t data;
302 uint8_t user_register = LTM_9100_STATUS_A_REG;
303 uint8_t user_bit;
304 do
305 {
306 //! Displays the Read Status menu
307 Serial.print(F("\nRead Status\n\n"));
308 Serial.print(F(" 1-Gate Status\n"));
309 Serial.print(F(" 2-PG Input Pin Status\n"));
310 Serial.print(F(" 3-FET Status\n"));
311 Serial.print(F(" 4-Overcurrent Condition\n"));
312 Serial.print(F(" 5-Undervoltage Condition\n"));
313 Serial.print(F(" 6-Overvoltage Condition\n"));
314 Serial.print(F(" m-Main Menu\n"));
315 Serial.print(F("\nEnter a command: "));
316
317 user_command = read_int(); //! Reads the user command
318 if (user_command == 'm') // Print m if it is entered
319 Serial.print(F("m\n"));
320 else
321 Serial.println(user_command); // Print user command
322
323 //! Reads LTM9100 and prints result.
324 switch (user_command)
325 {
326 case 1:
327 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_STATUS_GATE, &data);
328 Serial.print(F("Gate State: "));
329 (data)?Serial.println(F("On")):Serial.println(F("Off"));
330 break;
331 case 2:
332 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_STATUS_PGI, &data);
333 Serial.print(F("PG Input State: "));
334 (data)?Serial.println(F("High")):Serial.println(F("Low"));
335 break;
336 case 3:
337 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_STATUS_FET, &data);
338 Serial.print(F("FET State: "));
339 (data)?Serial.println(F("Short")):Serial.println(F("No Short"));
340 break;
341 case 4:
342 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_STATUS_OC, &data);
343 Serial.print(F("Overcurrent: "));
344 (data)?Serial.println(F("Yes")):Serial.println(F("No"));
345 break;
346 case 5:
347 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_STATUS_UV, &data);
348 Serial.print(F("Undervoltage: "));
349 (data)?Serial.println(F("Yes")):Serial.println(F("No"));
350 break;
351 case 6:
352 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_STATUS_OV, &data);
353 Serial.print(F("Overvoltage: "));
354 (data)?Serial.println(F("Yes")):Serial.println(F("No"));
355 break;
356 default:
357 if (user_command != 'm')
358 Serial.println("Invalid Selection");
359 break;
360 }
361
362 }
363 while ((user_command != 'm') && (ack != 1));
364 return(ack);
365 }
366
367 static int8_t ask_clear_set_bit(uint8_t i2c_address, uint8_t register_address, uint8_t bit_number)
368 {
369 int8_t ack = 0;
370 uint8_t user_bit;
371 Serial.println(F("0=Clear/Disable, 1=Set/Enable:"));
372 user_bit = read_int();
373 if (user_bit > 1)
374 Serial.println(F(" Invalid input."));
375 else
376 ack |= (user_bit)?LTM9100_bit_set(i2c_address, register_address, bit_number):LTM9100_bit_clear(i2c_address, register_address, bit_number);
377
378 return ack;
379 }
380
381 int8_t menu_read_write_faults_alerts(bool alerts)
382 {
383 int8_t ack=0;
384 uint8_t user_command;
385 uint8_t data;
386 uint8_t user_register = (alerts)?LTM_9100_ALERT_C_REG:LTM_9100_FAULT_B_REG;
387
388 do
389 {
390 if (!alerts) //! Displays the Read/Write Faults menu
391 {
392 Serial.print(F("\nRead/Write Faults\n\n"));
393 Serial.print(F(" 1-Read PGIO_HIGH\n"));
394 Serial.print(F(" 2-Read FET_FAULT\n"));
395 Serial.print(F(" 3-Read OC_FAULT\n"));
396 Serial.print(F(" 4-Read UV_FAULT\n"));
397 Serial.print(F(" 5-Read OV_FAULT\n"));
398 Serial.print(F(" 6-Clear/Set PGIO_HIGH\n"));
399 Serial.print(F(" 7-Clear/Set FET_FAULT\n"));
400 Serial.print(F(" 8-Clear/Set OC_FAULT\n"));
401 Serial.print(F(" 9-Clear/Set UV_FAULT\n"));
402 Serial.print(F(" 10-Clear/Set OV_FAULT\n"));
403 }
404 else //! Displays the Read/Write Alerts menu
405 {
406 Serial.print(F("\nRead/Write Alerts\n\n"));
407 Serial.print(F(" 1-Read PGIO_OUT\n"));
408 Serial.print(F(" 2-Read FET_ALERT\n"));
409 Serial.print(F(" 3-Read OC_ALERT\n"));
410 Serial.print(F(" 4-Read UV_ALERT\n"));
411 Serial.print(F(" 5-Read OV_ALERT\n"));
412 Serial.print(F(" 6-Disable/Enable PGIO_OUT\n"));
413 Serial.print(F(" 7-Disable/Enable FET_ALERT\n"));
414 Serial.print(F(" 8-Disable/Enable OC_ALERT\n"));
415 Serial.print(F(" 9-Disable/Enable UV_ALERT\n"));
416 Serial.print(F(" 10-Disable/Enable OV_ALERT\n"));
417 }
418 Serial.print(F(" m-Main Menu\n"));
419 Serial.print(F("\nEnter a command: "));
420
421 user_command = read_int(); //! Reads the user command
422 if (user_command == 'm') // Print m if it is entered
423 Serial.print(F("m\n"));
424 else
425 Serial.println(user_command); // Print user command
426
427 //! Reads or writes to a LTM9100 and prints result.
428 switch (user_command)
429 {
430 case 1:
431 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_FAULT_PGI, &data);
432 Serial.print(F("PGIO: "));
433 (data)?Serial.println(F("Yes")):Serial.println(F("No"));
434 break;
435 case 2:
436 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_FAULT_FET, &data);
437 Serial.print(F("FET Short Detected: "));
438 (data)?Serial.println(F("Fault")):Serial.println(F("No Fault"));
439 break;
440 case 3:
441 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_FAULT_OC, &data);
442 Serial.print(F("Overcurrent: "));
443 (data)?Serial.println(F("Fault")):Serial.println(F("No Fault"));
444 break;
445 case 4:
446 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_FAULT_UV, &data);
447 Serial.print(F("Undervoltage: "));
448 (data)?Serial.println(F("Fault")):Serial.println(F("No Fault"));
449 break;
450 case 5:
451 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_FAULT_OV, &data);
452 Serial.print(F("Overvoltage: "));
453 (data)?Serial.println(F("Fault")):Serial.println(F("No Fault"));
454 break;
455 case 6:
456 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_FAULT_PGI);
457 break;
458 case 7:
459 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_FAULT_FET);
460 break;
461 case 8:
462 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_FAULT_OC);
463 break;
464 case 9:
465 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_FAULT_UV);
466 break;
467 case 10:
468 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_FAULT_OV);
469 break;
470 default:
471 if (user_command != 'm')
472 Serial.println("Invalid Selection");
473 break;
474 }
475
476 }
477 while ((user_command != 'm') && (ack != 1));
478 return(ack);
479 }
480
481 int8_t menu_read_write_controls()
482 {
483 int8_t ack=0;
484 uint8_t user_command;
485 uint8_t data;
486 uint8_t user_register = LTM_9100_CTRL_D_REG;
487 uint8_t user_bit;
488
489 do
490 {
491 //! Displays the Read/Write Controls menu
492 Serial.print(F("\nRead/Write Controls\n\n"));
493 Serial.print(F(" 1-Read PGIO_CONFIG\n"));
494 Serial.print(F(" 2-Read ADC_WRITE\n"));
495 Serial.print(F(" 3-Read GATE_CTRL\n"));
496 Serial.print(F(" 4-Read OC_AUTO\n"));
497 Serial.print(F(" 5-Read UV_AUTO\n"));
498 Serial.print(F(" 6-Read OV_AUTO\n"));
499 Serial.print(F(" 7-Disable/Enable PGIO_CONFIG\n"));
500 Serial.print(F(" 8-Disable/Enable ADC_WRITE\n"));
501 Serial.print(F(" 9-Disable/Enable GATE_CTRL\n"));
502 Serial.print(F(" 10-Disable/Enable OC_AUTO\n"));
503 Serial.print(F(" 11-Disable/Enable UV_AUTO\n"));
504 Serial.print(F(" 12-Disable/Enable OV_AUTO\n"));
505 Serial.print(F(" m-Main Menu\n"));
506 Serial.print(F("\nEnter a command: "));
507
508 user_command = read_int(); //! Reads the user command
509 if (user_command == 'm') // Print m if it is entered
510 Serial.print(F("m\n"));
511 else
512 Serial.println(user_command); // Print user command
513
514 //! Reads or writes to a LTM9100 and prints result.
515 switch (user_command)
516 {
517 case 1:
518 ack |= LTM9100_register_read(i2c_address, user_register, &data);
519 data &= LTM_9100_CTRL_PGIO_CFG_MASK;
520 Serial.print(F("PGIO Config: "));
521 if (~data & 0x40)
522 Serial.println(F("Power Good, Open Drain"));
523 else if (data & 0x80)
524 Serial.println(F("General Purpose Input"));
525 else
526 Serial.println(F("General Purpose Output"));
527 break;
528 case 2:
529 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_CTRL_ADC_WRITE, &data);
530 Serial.print(F("ADC write: "));
531 (data)?Serial.println(F("Enabled")):Serial.println(F("Disabled"));
532 case 3:
533 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_CTRL_GATE_CTRL, &data);
534 Serial.print(F("Gate State: "));
535 (data)?Serial.println(F("Enabled")):Serial.println(F("Disabled"));
536 break;
537 break;
538 case 4:
539 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_CTRL_OC, &data);
540 Serial.print(F("Overcurrent: "));
541 (data)?Serial.println(F("Enabled")):Serial.println(F("Disabled"));
542 break;
543 case 5:
544 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_CTRL_UV, &data);
545 Serial.print(F("Undervoltage: "));
546 (data)?Serial.println(F("Enabled")):Serial.println(F("Disabled"));
547 break;
548 case 6:
549 ack |= LTM9100_bit_read(i2c_address, user_register, LTM_9100_CTRL_OV, &data);
550 Serial.print(F("Overvoltage: "));
551 (data)?Serial.println(F("Enabled")):Serial.println(F("Disabled"));
552 break;
553 case 7:
554 Serial.println(F("0,2=Power Good, 1=General Purpose Output, 3=General Purpose Input:"));
555 user_bit = read_int();
556 if (user_bit > 3)
557 Serial.println(F(" Invalid input."));
558 else
559 {
560 ack |= LTM9100_register_read(i2c_address, user_register, &data);
561 data &= ~LTM_9100_CTRL_PGIO_CFG_MASK;
562 data |= user_bit<<LTM_9100_CTRL_PGIO_CFG;
563 LTM9100_register_write(i2c_address, user_register, data);
564 }
565 break;
566 case 8:
567 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_CTRL_ADC_WRITE );
568 break;
569 case 9:
570 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_CTRL_GATE_CTRL);
571 break;
572 case 10:
573 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_CTRL_OC);
574 break;
575 case 11:
576 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_CTRL_UV);
577 break;
578 case 12:
579 ack |= ask_clear_set_bit(i2c_address, user_register, LTM_9100_CTRL_OV);
580 break;
581 default:
582 if (user_command != 'm')
583 Serial.println("Invalid Selection");
584 break;
585 }
586
587 }
588 while ((user_command != 'm') && (ack != 1));
589 return(ack);
590 }
591
592 static void set_adc_scaling_factor(float *data)
593 {
594 Serial.print(F("Current value: "));
595 Serial.println(*data, 4);
596 Serial.print(F("Enter new value: "));
597 *data = read_float();
598 Serial.println("");
599 }
600
601 int8_t menu_read_write_adc_params()
602 {
603 int8_t ack=0;
604 uint8_t user_command;
605 float data;
606
607 do
608 {
609 //! Displays the Read/Write ADC menu
610 Serial.print(F("\nRead/Write ADCs \n\n"));
611 Serial.print(F(" 1-Read ADC Current Sense Voltage\n"));
612 Serial.print(F(" 2-Read ADIN Voltage\n"));
613 Serial.print(F(" 3-Read ADIN2 Voltage or Temperature\n"));
614 Serial.print(F(" 4-Configure Current Sense Resistor(ohms)\n"));
615 Serial.print(F(" 5-Configure ADIN Gain(defaults: 0.035[A], 0.006[B])\n"));
616 Serial.print(F(" 6-Configure ADIN2 Gain(defaults: 0.035[A], 0.006[B], or 0.004V/Kelvin[A/B])\n"));
617 Serial.print(F(" m-Main Menu\n"));
618 Serial.print(F("\nEnter a command: "));
619
620 user_command = read_int(); //! Reads the user command
621 if (user_command == 'm') // Print m if it is entered
622 Serial.print(F("m\n"));
623 else
624 {
625 Serial.println(user_command); // Print user command
626 }
627
628 //! Reads or writes to a LTM9100 and prints result.
629 switch (user_command)
630 {
631 case 1:
632 ack |= LTM9100_adc_read(i2c_address, LTM_9100_SENSE_E_REG, &data);
633 break;
634 case 2:
635 ack |= LTM9100_adc_read(i2c_address, LTM_9100_ADIN_I_REG, &data);
636 break;
637 case 3:
638 ack |= LTM9100_adc_read(i2c_address, LTM_9100_ADIN2_G_REG, &data);
639 break;
640 case 4:
641 set_adc_scaling_factor(&sense_resistor);
642 break;
643 case 5:
644 set_adc_scaling_factor(&adin_gain);
645 break;
646 case 6:
647 set_adc_scaling_factor(&adin2_gain);
648 break;
649 default:
650 if (user_command != 'm')
651 Serial.println("Invalid Selection");
652 break;
653 }
654
655 }
656 while ((user_command != 'm') && (ack != 1));
657 return(ack);
658 }
659
i2c_address
static uint8_t i2c_address
Definition: DC2423A.ino:74
adin_gain
static float adin_gain
Definition: DC2423A.ino:72
sense_resistor
static float sense_resistor
Definition: DC2423A.ino:71
LTM_9100_CTRL_D_REG
#define LTM_9100_CTRL_D_REG
Definition: LTM9100.h:62
LTM_9100_FAULT_UV
#define LTM_9100_FAULT_UV
Definition: LTM9100.h:80
LTM_9100_STATUS_A_REG
#define LTM_9100_STATUS_A_REG
Definition: LTM9100.h:59
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
print_prompt
static void print_prompt()
Definition: DC2423A.ino:278
LTM_9100_FAULT_PGI
#define LTM_9100_FAULT_PGI
Definition: LTM9100.h:77
LTM9100_bit_clear
int8_t LTM9100_bit_clear(uint8_t i2c_address, uint8_t register_address, uint8_t bit_number)
Clears any bit inside the LTM9100 using the standard I2C repeated start format.
Definition: LTM9100.cpp:133
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTM_9100_CTRL_ADC_WRITE
#define LTM_9100_CTRL_ADC_WRITE
Definition: LTM9100.h:91
LTM_9100_FAULT_B_REG
#define LTM_9100_FAULT_B_REG
Definition: LTM9100.h:60
loop
static void loop()
Repeats Linduino loop.
Definition: DC2423A.ino:91
LTM9100_bit_set
int8_t LTM9100_bit_set(uint8_t i2c_address, uint8_t register_address, uint8_t bit_number)
Sets any bit inside the LTM9100 using the standard I2C repeated start format.
Definition: LTM9100.cpp:120
ask_clear_set_bit
static int8_t ask_clear_set_bit(uint8_t i2c_address, uint8_t register_address, uint8_t bit_number)
Definition: DC2423A.ino:367
LTM_9100_STATUS_FET
#define LTM_9100_STATUS_FET
Definition: LTM9100.h:72
LTM9100_bit_read
int8_t LTM9100_bit_read(uint8_t i2c_address, uint8_t register_address, uint8_t bit_number, uint8_t *register_data)
Read the bit specified by bit_number from the LTM9100.
Definition: LTM9100.cpp:146
LTM_9100_SENSE_E_REG
#define LTM_9100_SENSE_E_REG
Definition: LTM9100.h:63
i2c_enable
void i2c_enable()
i2c_enable or quikeval_I2C_init must be called before using any of the other I2C routines.
Definition: LT_I2C.cpp:414
LTM_9100_CTRL_OV
#define LTM_9100_CTRL_OV
Definition: LTM9100.h:95
LTM9100_register_read
int8_t LTM9100_register_read(uint8_t i2c_address, uint8_t register_address, uint8_t *register_data)
Reads an 8-bit register from the LTM9100 using the standard repeated start format.
Definition: LTM9100.cpp:72
LTM_9100_CTRL_OC
#define LTM_9100_CTRL_OC
Definition: LTM9100.h:93
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
menu_read_write_controls
static int8_t menu_read_write_controls()
Definition: DC2423A.ino:481
LTM_9100_CTRL_PGIO_CFG
#define LTM_9100_CTRL_PGIO_CFG
Definition: LTM9100.h:89
set_adc_scaling_factor
static void set_adc_scaling_factor(float *data)
Definition: DC2423A.ino:592
LTM_9100_CTRL_UV
#define LTM_9100_CTRL_UV
Definition: LTM9100.h:94
LTM_9100_FAULT_FET
#define LTM_9100_FAULT_FET
Definition: LTM9100.h:78
reg_read_list
uint8_t reg_read_list[10]
Definition: LTM9100.cpp:68
QuikEval_EEPROM.h
QuikEval EEPROM Library.
LTM_9100_STATUS_OC
#define LTM_9100_STATUS_OC
Definition: LTM9100.h:73
LTM_9100_FAULT_OC
#define LTM_9100_FAULT_OC
Definition: LTM9100.h:79
LTM9100_register_write
int8_t LTM9100_register_write(uint8_t i2c_address, uint8_t register_address, uint8_t register_data)
Writes to an 8-bit register inside the LTM9100 using the standard I2C repeated start format...
Definition: LTM9100.cpp:112
LTM_9100_STATUS_PGI
#define LTM_9100_STATUS_PGI
Definition: LTM9100.h:71
LTM_9100_STATUS_UV
#define LTM_9100_STATUS_UV
Definition: LTM9100.h:74
valid_register
boolean valid_register(uint8_t user_register, uint8_t register_array[], uint8_t array_length)
Check if user_register is a valid register for the LTM9100.
Definition: LTM9100.cpp:212
LTM_9100_CTRL_PGIO_CFG_MASK
#define LTM_9100_CTRL_PGIO_CFG_MASK
Definition: LTM9100.h:90
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
adin2_gain
static float adin2_gain
Definition: DC2423A.ino:73
LTM_9100_STATUS_GATE
#define LTM_9100_STATUS_GATE
Definition: LTM9100.h:70
LTM9100_continuous_read_all_registers
int8_t LTM9100_continuous_read_all_registers(uint8_t i2c_address)
Read all LTM9100 registers and output to the serial console every second until a key press is detecte...
Definition: LTM9100.cpp:188
menu_read_status
static int8_t menu_read_status()
Definition: DC2423A.ino:297
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTM_9100_ADIN_I_REG
#define LTM_9100_ADIN_I_REG
Definition: LTM9100.h:67
read_float
float read_float()
Definition: UserInterface.cpp:78
reg_write_list
uint8_t reg_write_list[9]
Definition: LTM9100.cpp:69
LTM_9100_ADIN2_G_REG
#define LTM_9100_ADIN2_G_REG
Definition: LTM9100.h:65
LTM_9100_CTRL_GATE_CTRL
#define LTM_9100_CTRL_GATE_CTRL
Definition: LTM9100.h:92
LTM_9100_STATUS_OV
#define LTM_9100_STATUS_OV
Definition: LTM9100.h:75
LTM_9100_FAULT_OV
#define LTM_9100_FAULT_OV
Definition: LTM9100.h:81
LTM9100_print_all_registers
int8_t LTM9100_print_all_registers(uint8_t i2c_address)
Read all LTM9100 registers and output to the serial console.
Definition: LTM9100.cpp:163
menu_read_write_faults_alerts
static int8_t menu_read_write_faults_alerts(bool alerts)
Definition: DC2423A.ino:381
LTM9100.h
LTM9100: Anyside™ High Voltage Isolated Switch Controller with I²C Command and Telemetry.
LTM_9100_ALERT_C_REG
#define LTM_9100_ALERT_C_REG
Definition: LTM9100.h:61
print_warning_prompt
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: DC2423A.ino:258
LTM9100_adc_read
int8_t LTM9100_adc_read(uint8_t i2c_address, uint8_t base_address, float *register_data)
Read the specified ADC value (SENSE, ADIN, ADIN2) and output in human readable format to the serial c...
Definition: LTM9100.cpp:80
menu_read_write_adc_params
static int8_t menu_read_write_adc_params()
Definition: DC2423A.ino:601
setup
static void setup()
Initialize Linduino.
Definition: DC2423A.ino:77
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC2423A.ino:264