Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC1633B.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1633B Demonstration Board.
3 LTC2933: Programable Hex Voltage Supervisor with EEPROM
4 
5 @verbatim
6 
7  Setup:
8  Power the demo board through the Linduino connector (12-pin adapter required).
9 
10  Set the Linduino terminal baud rate to 115200 and select the newline terminator.
11 
12 @endverbatim
13 
14 http://www.linear.com/product/LTC2933
15 
16 http://www.linear.com/demo/DC1633B
17 
18 
19 Copyright 2018(c) Analog Devices, Inc.
20 
21 All rights reserved.
22 
23 Redistribution and use in source and binary forms, with or without
24 modification, are permitted provided that the following conditions are met:
25  - Redistributions of source code must retain the above copyright
26  notice, this list of conditions and the following disclaimer.
27  - Redistributions in binary form must reproduce the above copyright
28  notice, this list of conditions and the following disclaimer in
29  the documentation and/or other materials provided with the
30  distribution.
31  - Neither the name of Analog Devices, Inc. nor the names of its
32  contributors may be used to endorse or promote products derived
33  from this software without specific prior written permission.
34  - The use of this software may or may not infringe the patent rights
35  of one or more patent holders. This license does not release you
36  from the requirement that you obtain separate licenses from these
37  patent holders to use this software.
38  - Use of the software either in source or binary form, must be run
39  on or directly connected to an Analog Devices Inc. component.
40 
41 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
42 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
43 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
45 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
47 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 */
52 
53 /*! @file
54  @ingroup LTC2933
55 */
56 
57 #include <Arduino.h>
58 #include <stdint.h>
59 #include "Linduino.h"
60 #include "UserInterface.h"
61 #include "LT_I2CBus.h"
62 #include "Wire.h"
63 #include "LT_SMBusNoPec.h"
64 #include "LTC2933.h"
65 
66 // LTC2637 DAC on the DC1633B board
67 #define DC1633_DAC_ADDRESS 0x22 //pin-strapped address for DAC
68 
69 //LTC2933 I2C address on the board (selectable by a jumper)
70 #define LTC2933_I2C_ADDRESS LTC2933_I2C_GLOBAL_ADDRESS
71 
72 // Global variables
73 static uint8_t ltc2933_i2c_address;
74 static uint8_t dc1633_dac_address;
75 static LT_SMBus *smbus = new LT_SMBusNoPec();
76 
77 //! Initialize Linduino
78 //! @return void
79 void setup()
80 {
81  Serial.begin(115200); //! Initialize the serial port to the PC
82  print_title();
85  print_prompt();
86 }
87 
88 //! Repeats Linduino loop
89 //! @return void
90 void loop()
91 {
92  uint8_t user_command;
93  uint8_t *addresses = NULL;
94  uint16_t res;
95 
96  if (Serial.available()) //! Checks for user input
97  {
98  user_command = read_int(); //! Reads the user command
99  if (user_command != 'm')
100  Serial.println(user_command);
101 
102  switch (user_command) //! Prints the appropriate submenu
103  {
104  case 0:
105  break;
106  case 1:
107  //! write all LTC2933 registers with demo-board default settings
108  //! all channels except 1 expect 2.0v from the DAC
110  break;
111  case 2:
112  //! read the LTC2933 STATUS_WORD register
114  Serial.println(res, HEX);
115  break;
116  case 3:
117  //! read all LTC2933 registers
119  break;
120  case 4:
121  //! write to the LTC2637 DACs on the DC1633 board to interesting voltages
122  //! other than the 2.0v DAC defaults
129  break;
130  case 5:
131  //! write all LTC2933 registers with more interesting voltage settings
133  break;
134  case 6:
135  // margin the supplies to the 20% high side
136  // write to the LTC2637 DACs on the DC1633 board
143  break;
144  case 7:
145  //! write the LTC2933 CLEAR_ALERT
147  break;
148  case 8:
149  addresses = smbus->probe(0);
150  while (*addresses != 0)
151  {
152  Serial.print(F("ADDR 0x"));
153  Serial.println(*addresses++, HEX);
154  }
155  break;
156  default:
157  Serial.println(F("Incorrect Option"));
158  break;
159  }
160  print_prompt();
161  }
162 }
163 
164 // Function Definitions
165 
166 //! Prints the title block when program first starts.
168 {
169  Serial.print(F("\n*****************************************************************\n"));
170  Serial.print(F("* DC1633B Demonstration Program *\n"));
171  Serial.print(F("* *\n"));
172  Serial.print(F("* This program demonstrates how to send and receive data from *\n"));
173  Serial.print(F("* the DC1633B demo board. *\n"));
174  Serial.print(F("* *\n"));
175  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
176  Serial.print(F("* *\n"));
177  Serial.print(F("*****************************************************************\n"));
178 }
179 
180 //! Prints main menu.
182 {
183  Serial.print(F(" 1-Write LTC2933 registers with default settings\n"));
184  Serial.print(F(" 2-Read Status (STATUS_WORD)\n"));
185  Serial.print(F(" 3-Read All Registers\n"));
186  Serial.print(F(" 4-Set DAC voltages on Vn pins to interesting values\n"));
187  Serial.print(F(" 5-Change LTC2933 voltage thresholds to match interesting DAC voltages\n"));
188  Serial.print(F(" 6-Set DAC voltages on Vn pins to +20% high values\n"));
189  Serial.print(F(" 7-Clear LTC2933 ALERTB\n"));
190  Serial.print(F(" 8-Bus Probe\n"));
191  Serial.print(F("\nEnter a command:"));
192 }
193 
194 //! Prints a warning if the demo board is not detected.
196 {
197  Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
198 }
199 
200 
201 //! Return 1 if the LTC2933 is write-protected
202 // 0 otherwise
204 {
205  uint16_t res;
206 
207  res = smbus->readWord(ltc2933_i2c_address, LTC2933_STATUS_WORD);
208 
209  //b[0] is the write-protect bit
210  return ((res&0x0001) == 0x0001) ? 1 : 0;
211 }
212 
213 //! Read all registers from RAM
215 {
216  uint16_t res;
217  res = smbus->readWord(ltc2933_i2c_address, LTC2933_WRITE_PROTECT);
218  Serial.print(F("\n LTC2933_WRITE_PROTECT:"));
219  Serial.println(res, HEX);
220 
221  res = smbus->readWord(ltc2933_i2c_address, LTC2933_GPI_CONFIG);
222  Serial.print(F("\n LTC2933_GPI_CONFIG: "));
223  Serial.println(res, HEX);
224 
225  res = smbus->readWord(ltc2933_i2c_address, LTC2933_GPIO1_CONFIG);
226  Serial.print(F("\n LTC2933_GPIO1_CONFIG: "));
227  Serial.println(res, HEX);
228 
229  res = smbus->readWord(ltc2933_i2c_address, LTC2933_GPIO2_3_CONFIG);
230  Serial.print(F("\n LTC2933_GPIO2_3_CONFIG: "));
231  Serial.println(res, HEX);
232 
233  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V1_THR);
234  Serial.print(F("\n LTC2933_V1_THR: "));
235  Serial.println(res, HEX);
236 
237  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V2_THR);
238  Serial.print(F("\n LTC2933_V2_THR: "));
239  Serial.println(res, HEX);
240 
241  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V3_THR);
242  Serial.print(F("\n LTC2933_V3_THR: "));
243  Serial.println(res, HEX);
244 
245  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V4_THR);
246  Serial.print(F("\n LTC2933_V4_THR: "));
247  Serial.println(res, HEX);
248 
249  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V5_THR);
250  Serial.print(F("\n LTC2933_V5_THR: "));
251  Serial.println(res, HEX);
252 
253  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V6_THR);
254  Serial.print(F("\n LTC2933_V6_THR: "));
255  Serial.println(res, HEX);
256 
257  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V1_CONFIG);
258  Serial.print(F("\n LTC2933_V1_CONFIG: "));
259  Serial.println(res, HEX);
260 
261  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V2_CONFIG);
262  Serial.print(F("\n LTC2933_V2_CONFIG: "));
263  Serial.println(res, HEX);
264 
265  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V3_CONFIG);
266  Serial.print(F("\n LTC2933_V3_CONFIG: "));
267  Serial.println(res, HEX);
268 
269  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V4_CONFIG);
270  Serial.print(F("\n LTC2933_V4_CONFIG: "));
271  Serial.println(res, HEX);
272 
273  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V5_CONFIG);
274  Serial.print(F("\n LTC2933_V5_CONFIG: "));
275  Serial.println(res, HEX);
276 
277  res = smbus->readWord(ltc2933_i2c_address, LTC2933_V6_CONFIG);
278  Serial.print(F("\n LTC2933_V6_CONFIG: "));
279  Serial.println(res, HEX);
280 
281  res = smbus->readWord(ltc2933_i2c_address, LTC2933_HISTORY_WORD);
282  Serial.print(F("\n LTC2933_HISTORY_WORD: "));
283  Serial.println(res, HEX);
284 
285  res = smbus->readWord(ltc2933_i2c_address, LTC2933_BACKUP_WORD);
286  Serial.print(F("\n LTC2933_BACKUP_WORD: "));
287  Serial.println(res, HEX);
288 
289  res = smbus->readWord(ltc2933_i2c_address, LTC2933_STATUS_WORD);
290  Serial.print(F("\n LTC2933_STATUS_WORD: "));
291  Serial.println(res, HEX);
292  Serial.print(F("\n"));
293 
294 }
295 
296 //! Load demo-board default settings into RAM
298 {
299  if (ltc2933_is_write_protected(ltc2933_i2c_address) != 1)
300  {
301  smbus->writeWord(ltc2933_i2c_address, LTC2933_WRITE_PROTECT, 0xAAA8);
302  smbus->writeWord(ltc2933_i2c_address, LTC2933_GPI_CONFIG, 0x1040);
303  smbus->writeWord(ltc2933_i2c_address, LTC2933_GPIO1_CONFIG, 0x002E);
304  smbus->writeWord(ltc2933_i2c_address, LTC2933_GPIO2_3_CONFIG, 0x2E07);
305  smbus->writeWord(ltc2933_i2c_address, LTC2933_V1_THR, 0x412D); // ov = 5.5, uv = 4.5
306  smbus->writeWord(ltc2933_i2c_address, LTC2933_V2_THR, 0xAF87); // ov = 2.2, uv = 1.8
307  smbus->writeWord(ltc2933_i2c_address, LTC2933_V3_THR, 0xAF87); // ov = 2.2, uv = 1.8
308  smbus->writeWord(ltc2933_i2c_address, LTC2933_V4_THR, 0xAF87); // ov = 2.2, uv = 1.8
309  smbus->writeWord(ltc2933_i2c_address, LTC2933_V5_THR, 0xAF87); // ov = 2.2, uv = 1.8
310  smbus->writeWord(ltc2933_i2c_address, LTC2933_V6_THR, 0xAF87); // ov = 2.2, uv = 1.8
311  smbus->writeWord(ltc2933_i2c_address, LTC2933_V1_CONFIG, 0x009C); // high range
312  smbus->writeWord(ltc2933_i2c_address, LTC2933_V2_CONFIG, 0x019C); // low range
313  smbus->writeWord(ltc2933_i2c_address, LTC2933_V3_CONFIG, 0x019C); // low range
314  smbus->writeWord(ltc2933_i2c_address, LTC2933_V4_CONFIG, 0x019C); // low range
315  smbus->writeWord(ltc2933_i2c_address, LTC2933_V5_CONFIG, 0x019C); // low range
316  smbus->writeWord(ltc2933_i2c_address, LTC2933_V6_CONFIG, 0x019C); // low range
317  }
318  else
319  {
320  // error, LTC2933 is write-protected
321  Serial.println(F("\nERROR: LTC2933 is write-protected. Cannot write to registers"));
322  }
323 }
324 
325 //! Load different voltage threshold settings into RAM
327 {
328  if (ltc2933_is_write_protected(ltc2933_i2c_address) != 1)
329  {
330  smbus->writeWord(ltc2933_i2c_address, LTC2933_WRITE_PROTECT, 0xAAA8);
331  smbus->writeWord(ltc2933_i2c_address, LTC2933_GPI_CONFIG, 0x1040);
332  smbus->writeWord(ltc2933_i2c_address, LTC2933_GPIO1_CONFIG, 0x002E);
333  smbus->writeWord(ltc2933_i2c_address, LTC2933_GPIO2_3_CONFIG, 0x2E07);
334  smbus->writeWord(ltc2933_i2c_address, LTC2933_V1_THR, 0x412D); // ov = 5.5, uv = 4.5
335  smbus->writeWord(ltc2933_i2c_address, LTC2933_V2_THR, 0x554B); // ov = 2.6, uv = 2.4
336  smbus->writeWord(ltc2933_i2c_address, LTC2933_V3_THR, 0x917D); // ov = 1.9, uv = 1.7
337  smbus->writeWord(ltc2933_i2c_address, LTC2933_V4_THR, 0x735F); // ov = 1.6, uv = 1.4
338  smbus->writeWord(ltc2933_i2c_address, LTC2933_V5_THR, 0x5541); // ov = 1.3, uv = 1.1
339  smbus->writeWord(ltc2933_i2c_address, LTC2933_V6_THR, 0x3C32); // ov = 1.05, uv = 0.95
340  smbus->writeWord(ltc2933_i2c_address, LTC2933_V1_CONFIG, 0x009C); // high range
341  smbus->writeWord(ltc2933_i2c_address, LTC2933_V2_CONFIG, 0x009C); // medium range
342  smbus->writeWord(ltc2933_i2c_address, LTC2933_V3_CONFIG, 0x019C); // low range
343  smbus->writeWord(ltc2933_i2c_address, LTC2933_V4_CONFIG, 0x019C); // low range
344  smbus->writeWord(ltc2933_i2c_address, LTC2933_V5_CONFIG, 0x019C); // low range
345  smbus->writeWord(ltc2933_i2c_address, LTC2933_V6_CONFIG, 0x019C); // low range
346  }
347  else
348  {
349  // error, LTC2933 is write-protected
350  Serial.println(F("\nERROR: LTC2933 is write-protected. Cannot write to registers"));
351  }
352 }
353 
354 //! Clear ALERTB
356 {
357  smbus->writeWord(ltc2933_i2c_address, LTC2933_CLEAR_HISTORY, 0x0000);
358 }
359 
360 
361 //! program the DAC on the DC1633B demo board to a voltage
362 // refer to the LTC2637 datasheet
363 void dc1633_write_dac_voltage(uint8_t dac_address, int channel, float voltage)
364 {
365  uint8_t *data = (uint8_t *)malloc(3*sizeof(uint8_t));
366  uint8_t cmd, ch_addr;
367  uint16_t v_data;
368  float v;
369 
370  // pack the data bytes with the necessary bits
371  // channel numbers 0 - 7 correspond to letters A - H in the datasheet
372  if ((channel < 8) && (channel >= 0))
373  {
374  ch_addr = (uint8_t)channel;
375  }
376  else
377  {
378  //address all channels
379  ch_addr = 0x0F;
380  }
381  cmd = 0x30; // the write to and update command
382  data[0] = cmd | ch_addr;
383 
384  if ((voltage > 0) && (voltage < 4.096))
385  {
386  v = (voltage/4.096);
387  v_data = (uint16_t)(v*4096);
388  }
389  else
390  {
391  Serial.println(F("\nERROR: Voltage out of DAC range"));
392  }
393  data[1] = (uint8_t)(v_data >> 4); // most significant bits
394  data[2] = (uint8_t)(v_data << 4); // least significant bits
395 
396  //write the command and data to the DAC
397  Wire.beginTransmission(dac_address);
398  Wire.write(data[0]);
399  Wire.write(data[1]);
400  Wire.write(data[2]);
401  Wire.endTransmission(1);
402 
403  free(data);
404  return;
405 
406 }
#define LTC2933_V1_THR
Definition: LTC2933.h:75
#define LTC2933_HISTORY_WORD
Definition: LTC2933.h:88
#define LTC2933_V5_THR
Definition: LTC2933.h:79
static void ltc2933_demo_board_demo_thresholds(uint8_t ltc2933_i2c_address)
Load different voltage threshold settings into RAM.
Definition: DC1633B.ino:326
unsigned char user_command
#define LTC2933_CLEAR_HISTORY
Definition: LTC2933.h:92
#define LTC2933_V4_CONFIG
Definition: LTC2933.h:84
static void print_prompt()
Prints main menu.
Definition: DC1633B.ino:181
Header File for Linduino Libraries and Demo Code.
static void dc1633_write_dac_voltage(uint8_t dac_address, int channel, float voltage)
program the DAC on the DC1633B demo board to a voltage
Definition: DC1633B.ino:363
static void setup()
Initialize Linduino.
Definition: DC1633B.ino:79
static uint8_t dc1633_dac_address
Definition: DC1633B.ino:74
#define LTC2933_V1_CONFIG
Definition: LTC2933.h:81
static uint8_t channel
LTC2305 Channel selection.
Definition: DC1444A.ino:127
Header for LTC2933: Programable Hex Voltage Supervisor with EEPROM.
static void ltc2933_read_registers(uint8_t ltc2933_i2c_address)
Read all registers from RAM.
Definition: DC1633B.ino:214
virtual void writeWord(uint8_t address, uint8_t command, uint16_t data)=0
SMBus write word command.
#define LTC2933_V2_CONFIG
Definition: LTC2933.h:82
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
#define LTC2933_STATUS_WORD
Definition: LTC2933.h:96
#define LTC2933_V4_THR
Definition: LTC2933.h:78
#define LTC2933_V6_CONFIG
Definition: LTC2933.h:86
static void loop()
Repeats Linduino loop.
Definition: DC1633B.ino:90
#define LTC2933_GPIO2_3_CONFIG
Definition: LTC2933.h:74
LT_I2CBus: Routines to communicate to I2C by Wire Library.
#define LTC2933_V5_CONFIG
Definition: LTC2933.h:85
#define LTC2933_WRITE_PROTECT
Definition: LTC2933.h:71
#define LTC2933_V2_THR
Definition: LTC2933.h:76
static LT_SMBus * smbus
Definition: DC1633B.ino:75
#define LTC2933_I2C_ADDRESS
Definition: DC1633B.ino:70
static void print_title()
Prints the title block when program first starts.
Definition: DC1633B.ino:167
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: DC1633B.ino:195
static void ltc2933_demo_board_defaults(uint8_t ltc2933_i2c_address)
Load demo-board default settings into RAM.
Definition: DC1633B.ino:297
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
#define LTC2933_V3_THR
Definition: LTC2933.h:77
#define DC1633_DAC_ADDRESS
Definition: DC1633B.ino:67
LTC SMBus Support: Implementation for a shared SMBus layer.
static void ltc2933_clear_alertb(uint8_t ltc2933_i2c_address)
Clear ALERTB.
Definition: DC1633B.ino:355
int32_t read_int()
#define LTC2933_GPIO1_CONFIG
Definition: LTC2933.h:73
#define LTC2933_BACKUP_WORD
Definition: LTC2933.h:95
static float voltage
Definition: DC2289AA.ino:71
#define LTC2933_V3_CONFIG
Definition: LTC2933.h:83
#define LTC2933_GPI_CONFIG
Definition: LTC2933.h:72
static int ltc2933_is_write_protected(uint8_t ltc2933_i2c_address)
Return 1 if the LTC2933 is write-protected.
Definition: DC1633B.ino:203
virtual uint16_t readWord(uint8_t address, uint8_t command)=0
SMBus read word command.
static uint8_t ltc2933_i2c_address
Definition: DC1633B.ino:73
#define LTC2933_V6_THR
Definition: LTC2933.h:80