| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC980.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC980A/B Demonstration Board Control
3
4 LTC2970: Dual I2C Power Supply Monitor and Margining Controller
5
6 @verbatim
7 http://www.linear.com/product/LTC2970
8
9 NOTES
10 Setup:
11 Set the terminal baud rate to 115200 and select the newline terminator.
12
13 @endverbatim
14
15 http://www.linear.com/product/LTC2970
16
17 http://www.linear.com/demo/#demoboards
18
19
20 Copyright 2018(c) Analog Devices, Inc.
21
22 All rights reserved.
23
24 Redistribution and use in source and binary forms, with or without
25 modification, are permitted provided that the following conditions are met:
26 - Redistributions of source code must retain the above copyright
27 notice, this list of conditions and the following disclaimer.
28 - Redistributions in binary form must reproduce the above copyright
29 notice, this list of conditions and the following disclaimer in
30 the documentation and/or other materials provided with the
31 distribution.
32 - Neither the name of Analog Devices, Inc. nor the names of its
33 contributors may be used to endorse or promote products derived
34 from this software without specific prior written permission.
35 - The use of this software may or may not infringe the patent rights
36 of one or more patent holders. This license does not release you
37 from the requirement that you obtain separate licenses from these
38 patent holders to use this software.
39 - Use of the software either in source or binary form, must be run
40 on or directly connected to an Analog Devices Inc. component.
41
42 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
43 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
44 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
46 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
48 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 !*/
53
54 /*! @file
55 @ingroup LTC2970
56 */
57
58 #include <Arduino.h>
59 #include <stdint.h>
60 #include "Linduino.h"
61 #include "UserInterface.h"
62 #include "LT_SMBusNoPec.h"
63 #include "LTC2970.h"
64
65 #define LTC2970_I2C_ADDRESS 0x5B //global 7-bit address
66 //#define LTC2970_I2C_ADDRESS 0x6F //SLAVE_HH 7-bit address
67
68
69 /****************************************************************************/
70 // Global variables
71 static uint8_t ltc2970_i2c_address;
72
73 static LT_SMBusNoPec *smbus = new LT_SMBusNoPec();
74
75 uint16_t servo0_value_marg;
76 uint16_t servo0_value_nom;
77 uint16_t servo1_value_marg;
78 uint16_t servo1_value_nom;
79
80
81 /****************************************************************************/
82 //! Initialize Linduino
83 //! @return void
84 void setup()
85 {
86 uint16_t return_val;
87
88 // initialize the i2c port
89 Serial.begin(115200); //! Initialize the serial port to the PC
90 print_title();
91 print_prompt();
92
93 ltc2970_i2c_address = LTC2970_I2C_ADDRESS;
94
95 servo0_value_nom = 0x2733;
96 servo1_value_nom = 0x1A24;
97 servo0_value_marg = 0x2347; // 10% low
98 servo1_value_marg = 0x1786; // 10% low
99
100 //************************ init_voltage_transition();
101 }
102
103 //! Main Linduino loop
104 //! @return void
105 void loop()
106 {
107 uint8_t user_command;
108 uint16_t return_val;
109
110 int i = 0;
111
112 if (Serial.available()) //! Checks for user input
113 {
114 user_command = read_int(); //! Reads the user command
115 if (user_command != 'm')
116 Serial.println(user_command);
117
118 switch (user_command) //! Prints the appropriate submenu
119 {
120
121 case 1 :
122 Serial.print(F("\n****INITIALIZING THE LTC2970****\n"));
123 ltc2970_configure();
124 break;
125
126 case 2 :
127 Serial.print(F("\n****ENABLE LTC2970 CHANNEL 0 AND CHANNEL 1****\n"));
128 ltc2970_dac_disconnect(smbus, ltc2970_i2c_address, 0);
129 ltc2970_gpio_up(smbus, ltc2970_i2c_address, 0);
130
131 ltc2970_dac_disconnect(smbus, ltc2970_i2c_address, 1);
132 ltc2970_gpio_up(smbus, ltc2970_i2c_address, 1);
133 break;
134
135 case 3 :
136 Serial.print(F("\n****SOFT CONNECT LTC2970 DAC0 and DAC1****\n"));
137 ltc2970_soft_connect_dac(smbus, ltc2970_i2c_address, 0);
138 ltc2970_soft_connect_dac(smbus, ltc2970_i2c_address, 1);
139 break;
140
141 case 4 :
142 Serial.print(F("\n****SERVO CHANNEL 0 and 1 VOLTAGES 10% LOW****\n"));
143 ltc2970_servo_to_adc_val(smbus, ltc2970_i2c_address, 0, servo0_value_marg);
144 ltc2970_servo_to_adc_val(smbus, ltc2970_i2c_address, 1, servo1_value_marg);
145 break;
146
147 case 5 :
148 Serial.print(F("\n****SERVO CHANNEL 0 and 1 VOLTAGES TO NOMINAL****\n"));
149 ltc2970_servo_to_adc_val(smbus, ltc2970_i2c_address, 0, servo0_value_nom);
150 ltc2970_servo_to_adc_val(smbus, ltc2970_i2c_address, 1, servo1_value_nom);
151 break;
152
153 case 6 :
154 Serial.print(F("\n****ADC CH_0 VOLTAGE = (HEX VALUE)\n"));
155 return_val = smbus->readWord(ltc2970_i2c_address, LTC2970_CH0_A_ADC);
156 Serial.println(((return_val & 0x7FFF)*500e-6), DEC);
157 Serial.println(return_val, HEX);
158
159 Serial.print(F("\n****ADC CH_1 VOLTAGE = (HEX VALUE)\n"));
160 return_val = smbus->readWord(ltc2970_i2c_address, LTC2970_CH1_A_ADC);
161 Serial.println(((return_val & 0x7FFF)*500e-6), DEC);
162 Serial.println(return_val, HEX);
163 break;
164
165 case 7 :
166 Serial.print(F("\n****ADC CH_0 CURRENT = (HEX VALUE)\n"));
167 return_val = smbus->readWord(ltc2970_i2c_address, LTC2970_CH0_B_ADC);
168 Serial.println((((return_val & 0x7FFF)*500e-6)/0.007), DEC);
169 Serial.println(return_val, HEX);
170
171 Serial.print(F("\n****ADC CH_1 CURRENT = (HEX VALUE)\n"));
172 return_val = smbus->readWord(ltc2970_i2c_address, LTC2970_CH1_B_ADC);
173 Serial.println((((return_val & 0x7FFF)*500e-6)/0.008), DEC);
174 Serial.println(return_val, HEX);
175 break;
176
177 case 8 :
178 Serial.print(F("\n****PRINT FAULTS, CLEAR LATCHED FAULTS \n"));
179 ltc2970_read_faults(smbus, ltc2970_i2c_address);
180 break;
181
182 case 9 :
183 Serial.print(F("\n****PRINT DIE TEMPERATURE \n"));
184 ltc2970_print_die_temp (smbus, ltc2970_i2c_address);
185 break;
186
187 default:
188 Serial.println(F("Incorrect Option"));
189 break;
190 }
191 print_prompt();
192 }
193 }
194
195
196 /************************************************************************/
197 // Function Definitions
198
199 //! Prints the title block when program first starts.
200 //! @return void
201 void print_title()
202 {
203 Serial.print(F("\n***************************************************************\n"));
204 Serial.print(F("* DC980 Regulator Control Program *\n"));
205 Serial.print(F("* *\n"));
206 Serial.print(F("* This program provides a simple interface to control the *\n"));
207 Serial.print(F("* the DC980 regulators through the LTC2970 *\n"));
208 Serial.print(F("* *\n"));
209 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
210 Serial.print(F("* *\n"));
211 Serial.print(F("*****************************************************************\n"));
212 }
213
214 //! Prints main menu.
215 //! @return void
216 void print_prompt()
217 {
218 Serial.print(F("\n"));
219 Serial.print(F(" 1 - Reset the LTC2970, Disable Regulators\n"));
220 Serial.print(F(" 2 - Enable Channel 0 and Channel 1; DACs disconnected\n"));
221 Serial.print(F(" 3 - Soft-Connect DAC0 and DAC1, and Confirm Connection\n"));
222 Serial.print(F(" 4 - Servo Channel 0 and Channel 1 Voltages 10% low\n"));
223 Serial.print(F(" 5 - Servo Channel 0 and Channel 1 Voltages to nominal\n"));
224 Serial.print(F(" 6 - Print Channel 0 & 1 Voltages\n"));
225 Serial.print(F(" 7 - Print Channel 0 & 1 Currents\n"));
226 Serial.print(F(" 8 - Print Fault Register Contents\n"));
227 Serial.print(F(" 9 - Print LTC2970 Temperature\n"));
228 Serial.print(F("\nEnter a command number:"));
229 }
230
231
232 //! Writes configuration values to the LTC2970 registers
233 //! @return void
234 void ltc2970_configure()
235 {
236 uint16_t return_val;
237 //start the 2970 by configuring all of its registers for this application
238 // use SMbus commands
239 smbus->writeWord(ltc2970_i2c_address, LTC2970_FAULT_EN, 0x0168);
240 smbus->writeWord(ltc2970_i2c_address, LTC2970_IO, 0x000A);
241 smbus->writeWord(ltc2970_i2c_address, LTC2970_ADC_MON, 0x007F);
242 smbus->writeWord(ltc2970_i2c_address, LTC2970_VDD_OV, 0x2CEC);
243 smbus->writeWord(ltc2970_i2c_address, LTC2970_VDD_UV, 0x2328);
244 smbus->writeWord(ltc2970_i2c_address, LTC2970_V12_OV, 0x3FFF);
245 smbus->writeWord(ltc2970_i2c_address, LTC2970_V12_UV, 0x00000);
246
247 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH0_A_OV, 0x2AF8);
248 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH0_A_UV, 0x2328);
249 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH0_A_SERVO, 0x0000);
250 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH0_A_IDAC, 0x0084);
251 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH0_B_OV, 0x3FFF);
252 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH0_B_UV, 0x0000);
253
254 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH1_A_OV, 0x1C5D);
255 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH1_A_UV, 0x1770);
256 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH1_A_SERVO, 0x0000);
257 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH1_A_IDAC, 0x0084);
258 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH1_B_OV, 0x3FFF);
259 smbus->writeWord(ltc2970_i2c_address, LTC2970_CH1_B_UV, 0x0000);
260 }
261
ltc2970_configure
static void ltc2970_configure()
Writes configuration values to the LTC2970 registers.
Definition: DC980.ino:234
ltc2970_i2c_address
static uint8_t ltc2970_i2c_address
Definition: DC980.ino:71
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LTC2970_CH1_A_SERVO
#define LTC2970_CH1_A_SERVO
Definition: LTC2970.h:128
servo0_value_marg
static uint16_t servo0_value_marg
Definition: DC980.ino:75
loop
static void loop()
Main Linduino loop.
Definition: DC980.ino:105
LT_SMBusBase::writeWord
void writeWord(uint8_t address, uint8_t command, uint16_t data)
SMBus write word command.
Definition: LT_SMBusBase.cpp:265
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC980.ino:201
LTC2970_CH1_A_OV
#define LTC2970_CH1_A_OV
Definition: LTC2970.h:126
LTC2970_CH1_B_OV
#define LTC2970_CH1_B_OV
Definition: LTC2970.h:136
LTC2970_CH1_A_UV
#define LTC2970_CH1_A_UV
Definition: LTC2970.h:127
Linduino.h
Header File for Linduino Libraries and Demo Code.
LT_SMBusNoPec
Definition: LT_SMBusNoPec.h:60
LTC2970_CH1_B_UV
#define LTC2970_CH1_B_UV
Definition: LTC2970.h:137
LTC2970_CH0_A_SERVO
#define LTC2970_CH0_A_SERVO
Definition: LTC2970.h:114
LTC2970_V12_OV
#define LTC2970_V12_OV
Definition: LTC2970.h:106
LTC2970_VDD_OV
#define LTC2970_VDD_OV
Definition: LTC2970.h:100
ltc2970_print_die_temp
void ltc2970_print_die_temp(LT_SMBus *smbus, uint8_t ltc2970_i2c_address)
Prints die temperature on the LTC2970.
Definition: LTC2970.cpp:265
ltc2970_read_faults
void ltc2970_read_faults(LT_SMBus *smbus, uint8_t ltc2970_i2c_address)
Read FAULT, FAULT_LA, and FAULT_LA_INDEX registers print the results.
Definition: LTC2970.cpp:289
LTC2970_I2C_ADDRESS
#define LTC2970_I2C_ADDRESS
Definition: DC980.ino:65
LTC2970_CH0_B_ADC
#define LTC2970_CH0_B_ADC
Definition: LTC2970.h:119
servo1_value_marg
static uint16_t servo1_value_marg
Definition: DC980.ino:77
LTC2970_ADC_MON
#define LTC2970_ADC_MON
Definition: LTC2970.h:91
LTC2970_VDD_UV
#define LTC2970_VDD_UV
Definition: LTC2970.h:101
LTC2970_CH0_A_ADC
#define LTC2970_CH0_A_ADC
Definition: LTC2970.h:111
LTC2970_CH0_A_OV
#define LTC2970_CH0_A_OV
Definition: LTC2970.h:112
smbus
static LT_SMBusNoPec * smbus
Definition: DC980.ino:73
servo1_value_nom
static uint16_t servo1_value_nom
Definition: DC980.ino:78
ltc2970_dac_disconnect
void ltc2970_dac_disconnect(LT_SMBus *smbus, uint8_t ltc2970_i2c_address, int dac_number)
Disconnect a DAC from its channel.
Definition: LTC2970.cpp:51
ltc2970_servo_to_adc_val
void ltc2970_servo_to_adc_val(LT_SMBus *smbus, uint8_t ltc2970_i2c_address, int channel_number, uint16_t code)
Servo once to a given ADC value.
Definition: LTC2970.cpp:227
LTC2970_CH0_A_IDAC
#define LTC2970_CH0_A_IDAC
Definition: LTC2970.h:115
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC2970_CH0_B_UV
#define LTC2970_CH0_B_UV
Definition: LTC2970.h:121
LTC2970_IO
#define LTC2970_IO
Definition: LTC2970.h:90
LTC2970_CH0_B_OV
#define LTC2970_CH0_B_OV
Definition: LTC2970.h:120
LTC2970.h
Header for LTC2970: Dual I2C Power Supply Monitor and Margining Controller.
setup
static void setup()
Initialize Linduino.
Definition: DC980.ino:84
i
static int i
Definition: DC2430A.ino:184
ltc2970_soft_connect_dac
int ltc2970_soft_connect_dac(LT_SMBus *smbus, uint8_t ltc2970_i2c_address, int dac_number)
soft-connect DACn to its controlled node
Definition: LTC2970.cpp:114
LTC2970_CH1_B_ADC
#define LTC2970_CH1_B_ADC
Definition: LTC2970.h:135
LTC2970_V12_UV
#define LTC2970_V12_UV
Definition: LTC2970.h:107
LTC2970_CH1_A_IDAC
#define LTC2970_CH1_A_IDAC
Definition: LTC2970.h:129
LTC2970_CH1_A_ADC
#define LTC2970_CH1_A_ADC
Definition: LTC2970.h:125
LTC2970_FAULT_EN
#define LTC2970_FAULT_EN
Definition: LTC2970.h:83
ltc2970_gpio_up
void ltc2970_gpio_up(LT_SMBus *smbus, uint8_t ltc2970_i2c_address, int gpio_number)
Set GPIO_n high.
Definition: LTC2970.cpp:5
LTC2970_CH0_A_UV
#define LTC2970_CH0_A_UV
Definition: LTC2970.h:113
servo0_value_nom
static uint16_t servo0_value_nom
Definition: DC980.ino:76
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC980.ino:216
LT_SMBusBase::readWord
uint16_t readWord(uint8_t address, uint8_t command)
SMBus read word command.
Definition: LT_SMBusBase.cpp:301