Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2155A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2155A Demonstartion Board
3 LTC3886: Power Management Solution for Application Processors
4 
5 @verbatim
6 
7 NOTES
8  Setup:
9  Set the terminal baud rate to 115200 and select the newline terminator.
10 
11 @endverbatim
12 
13 http://www.linear.com/product/LTC3886
14 
15 http://www.linear.com/product/LTC3886#demoboards
16 
17 
18 Copyright 2018(c) Analog Devices, Inc.
19 
20 All rights reserved.
21 
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24  - Redistributions of source code must retain the above copyright
25  notice, this list of conditions and the following disclaimer.
26  - Redistributions in binary form must reproduce the above copyright
27  notice, this list of conditions and the following disclaimer in
28  the documentation and/or other materials provided with the
29  distribution.
30  - Neither the name of Analog Devices, Inc. nor the names of its
31  contributors may be used to endorse or promote products derived
32  from this software without specific prior written permission.
33  - The use of this software may or may not infringe the patent rights
34  of one or more patent holders. This license does not release you
35  from the requirement that you obtain separate licenses from these
36  patent holders to use this software.
37  - Use of the software either in source or binary form, must be run
38  on or directly connected to an Analog Devices Inc. component.
39 
40 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
41 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
42 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
44 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
46 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 */
51 
52 /*! @file
53  @ingroup LTC3886
54 */
55 
56 
57 #include <Arduino.h>
58 #include <stdint.h>
59 #include "UserInterface.h"
60 #include "Linduino.h"
61 #include <LT_I2CBus.h>
62 #include <LT_PMBus.h>
63 #include <LT_PMBusMath.h>
64 #include <LT_SMBus.h>
65 #include <LT_SMBusBase.h>
66 #include <LT_SMBusGroup.h>
67 #include <LT_SMBusNoPec.h>
68 #include <LT_SMBusPec.h>
69 #include <LT_Wire.h>
70 
71 #define LTC3886_I2C_ADDRESS 0x4F
72 #define MFR_PWM_COMP 0xD3 // PMBus command for setting the compensation network gm and Rth
73 #define PAGE 0x00 // PMBus command for selecting output
74 #define CH_0 0x00
75 #define CH_1 0x01
76 
77 #define ITH_MAX 62
78 #define GM_MAX 5.73
79 
80 
81 // Global variables
82 static uint8_t ltc3886_i2c_address;
84 
85 static uint8_t channel; // current output channel
86 static uint8_t ith; // current ith hex value
87 static uint8_t gm; // current gm hex value
88 static uint8_t comp_config; // data byte for setting gm and Rth
89 static float ith_dec; // decimal representaiton of ith
90 static float gm_dec; // decimal represnetaiton of gm
91 
92 // Arrays of ith and gm values make it easy to transfer between decimal and hex
93 static float ith_vals[] = {0, .25, .5, .75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 7, 8, 9, 11, 13, 15, 17, 20, 24, 28, 32, 38, 46, 54, 62};
94 static float gm_vals[] = {1, 1.68, 2.35, 3.02, 3.69, 4.36, 5.04, 5.73};
95 static uint8_t ith_vals_hex[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
96 static uint8_t gm_vals_hex[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
97 
98 
99 //! Initialize Linduino
100 void setup()
101 {
102  Serial.begin(115200); //! Initialize the serial port to the PC
103  print_title();
105  channel = CH_0; // Initialize to CH0
107  print_prompt();
108 }
109 
110 //! Repeats Linduino loop
111 void loop()
112 {
113  uint8_t user_select; // The user's choice of the three menu options
114  float user_value; // data value user inputs, either for gm or Rth
115  if (Serial.available())
116  {
117  user_select = read_int();
118  switch (user_select)
119  {
120  case 1: // Change gm
121  Serial.print(F("\nEnter desired gm (1-5.73), this will be rounded to nearest legal value:\n"));
122  user_value = read_float();
123 
124  gm_dec = gm_nearest_legal_value(user_value); // Snap given decimal gm value to nearest actual gm decimal value
125  gm = gm_decimal2hex(gm_dec); // Convert decimal gm to hex
126 
127  comp_config = (gm << 5) | ith; // Update comp_config with new gm value. Must bitshift gm left by 5. See page 74 of 3886 datasheet for details.
129 
131  print_prompt();
132  break;
133  case 2: // Change ith
134  Serial.print(F("\nEnter desired ith (0-62), this will be rounded to nearest legal value:\n"));
135  user_value = read_float();
136 
137  ith_dec = ith_nearest_legal_value(user_value); // Snap given decimal ith value to nearest actual ith decimal value
138  ith = ith_decimal2hex(ith_dec); // Convert decimal ith to hex
139 
140  comp_config = (gm << 5) | ith; // Update comp_config with new ith value. Must bitshift gm left by 5. See page 74 of 3886 datasheet for details.
142 
144  print_prompt();
145  break;
146  case 3: // Toggle Channel
147  if (channel == 0)
148  {
150  channel = CH_1;
151  }
152  else
153  {
155  channel = CH_0;
156  }
157 
158  Serial.println();
160  print_prompt();
161  break;
162  }
163  }
164 }
165 
166 
167 // Function Definitions
168 
169 //! Prints the title block when program first starts.
170 //! @return void
172 {
173  Serial.print(F("\n*****************************************************************\n"));
174  Serial.print(F("* LTC3886 Adjustable Compensation Program *\n"));
175  Serial.print(F("* *\n"));
176  Serial.print(F("* This is an example program for adjusting LTC3886 compensation.*\n"));
177  Serial.print(F("* *\n"));
178  Serial.print(F("*****************************************************************\n"));
179 }
180 
181 //! Prints main menu.
182 //! @return void
184 {
185  Serial.print(F("\n 1-Adjust gm\n"));
186  Serial.print(F(" 2-Adjust ith\n"));
187  Serial.print(F(" 3-Switch Channel"));
188 }
189 
190 //! Prints current compensation configuration and saves ith, gm, and configuration hex values.
191 //! @return void
193 {
195 
196  ith = 0x1F & comp_config; // Extract ith via bit-wise AND with 5 LSD
197  gm = (0xE0 & comp_config) >> 5; // Extract ith via bit-wise AND with 3 MSD. Bit shift right by 5.
198  ith_dec = ith_hex2decimal(ith); // Update ith hex value
199  gm_dec = gm_hex2decimal(gm); // Update gm hex value
200 
201  Serial.print(F("\nCH"));
202  Serial.print(channel, DEC);
203  Serial.print(F(" "));
204  Serial.print(F("Configuration, (gm, ith): ("));
205  Serial.print(gm_dec);
206  Serial.print(F(", "));
207  Serial.print(ith_dec);
208  Serial.print(F(")"));
209 }
210 
211 
212 //! Rounds decimal input ith to nearest legal decimal value.
213 //! @return double
215 {
216  for (int i=0; i<(sizeof(ith_vals)/4)-1; i++)
217  {
218  float cutoff = ith_vals[i] + (ith_vals[i+1] - ith_vals[i])/2;
219  if (ith < cutoff)
220  {
221  return ith_vals[i];
222  }
223  }
224  return ITH_MAX;
225 }
226 
227 //! Rounds decimal input gm to nearest legal decimal value.
228 //! @return double
230 {
231  for (int i=0; i<(sizeof(gm_vals)/4)-1; i++)
232  {
233  float cutoff = gm_vals[i] + (gm_vals[i+1] - gm_vals[i])/2;
234  if (gm < cutoff)
235  {
236  return gm_vals[i];
237  }
238  }
239  return GM_MAX;
240 }
241 
242 //! Converts ith demo circuit hex value to its decimal equivalent.
243 //! @return double
244 float ith_hex2decimal(uint8_t ith)
245 {
246  for (int i=0; i<sizeof(ith_vals_hex); i++)
247  {
248  if (ith_vals_hex[i]==ith)
249  {
250  return ith_vals[i];
251  }
252  }
253 }
254 
255 //! Converts gm demo circuit hex value to its decimal equivalent.
256 //! @return double
257 float gm_hex2decimal(uint8_t gm)
258 {
259  for (int i=0; i<sizeof(gm_vals_hex); i++)
260  {
261  if (gm_vals_hex[i]==gm)
262  {
263  return gm_vals[i];
264  }
265  }
266 }
267 
268 //! Converts ith decimal value to the demo circuit hex equivalent.
269 //! @return uint8_t
270 uint8_t ith_decimal2hex(float ith)
271 {
272  for (int i=0; i<sizeof(ith_vals); i++)
273  {
274  if (abs(ith_vals[i]-ith) < .1) // Epsilon of .1 selected to prevent equality check of floating numbers
275  {
276  return ith_vals_hex[i];
277  }
278  }
279 }
280 
281 //! Converts gm decimal value to the demo circuit hex equivalent.
282 //! @return uint8_t
283 uint8_t gm_decimal2hex(float gm)
284 {
285  for (int i=0; i<sizeof(gm_vals); i++)
286  {
287  if (abs(gm_vals[i]-gm) < .1) // Epsilon of .1 selected to prevent equality check of floating numbers
288  {
289  return gm_vals_hex[i];
290  }
291  }
292 }
293 
#define PAGE
Definition: DC2155A.ino:73
LTC SMBus Support: API for a shared SMBus layer.
static float gm_hex2decimal(uint8_t gm)
Converts gm demo circuit hex value to its decimal equivalent.
Definition: DC2155A.ino:257
static uint8_t gm_decimal2hex(float gm)
Converts gm decimal value to the demo circuit hex equivalent.
Definition: DC2155A.ino:283
static void loop()
Repeats Linduino loop.
Definition: DC2155A.ino:111
LTC SMBus Support: Implementation for a shared SMBus layer.
LTC SMBus Support: Implementation for a shared SMBus layer.
static float ith_dec
Definition: DC2155A.ino:89
#define MFR_PWM_COMP
Definition: DC2155A.ino:72
#define CH_0
Definition: DC2155A.ino:74
Header File for Linduino Libraries and Demo Code.
void writeByte(uint8_t address, uint8_t command, uint8_t data)
SMBus write byte command.
static float gm_nearest_legal_value(float gm)
Rounds decimal input gm to nearest legal decimal value.
Definition: DC2155A.ino:229
static void print_prompt()
Prints main menu.
Definition: DC2155A.ino:183
#define GM_MAX
Definition: DC2155A.ino:78
#define LTC3886_I2C_ADDRESS
Definition: DC2155A.ino:71
static float ith_nearest_legal_value(float ith)
Rounds decimal input ith to nearest legal decimal value.
Definition: DC2155A.ino:214
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
static void print_title()
Prints the title block when program first starts.
Definition: DC2155A.ino:171
#define CH_1
Definition: DC2155A.ino:75
LT_I2CBus: Routines to communicate to I2C by Wire Library.
static void print_comp_config()
Prints current compensation configuration and saves ith, gm, and configuration hex values...
Definition: DC2155A.ino:192
uint8_t readByte(uint8_t address, uint8_t command)
SMBus read byte command.
static void setup()
Initialize Linduino.
Definition: DC2155A.ino:100
static uint8_t channel
Definition: DC2155A.ino:85
static uint8_t ltc3886_i2c_address
Definition: DC2155A.ino:82
static float ith_hex2decimal(uint8_t ith)
Converts ith demo circuit hex value to its decimal equivalent.
Definition: DC2155A.ino:244
LTC SMBus Support: Implementation for a shared SMBus layer.
#define ITH_MAX
Definition: DC2155A.ino:77
static uint8_t ith
Definition: DC2155A.ino:86
int32_t read_int()
static uint8_t gm
Definition: DC2155A.ino:87
float read_float()
static uint8_t ith_decimal2hex(float ith)
Converts ith decimal value to the demo circuit hex equivalent.
Definition: DC2155A.ino:270
static uint8_t ith_vals_hex[]
Definition: DC2155A.ino:95
LTC PMBus Support.
static int i
Definition: DC2430A.ino:184
static LT_SMBusNoPec * smbus
Definition: DC2155A.ino:83
static uint8_t gm_vals_hex[]
Definition: DC2155A.ino:96
LTC PMBus Support: Math conversion routines.
static float ith_vals[]
Definition: DC2155A.ino:93
static float gm_dec
Definition: DC2155A.ino:90
static uint8_t comp_config
Definition: DC2155A.ino:88
LTC SMBus Support: Implementation for a shared SMBus layer.
static float gm_vals[]
Definition: DC2155A.ino:94