Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/AD5755/ad5755.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD5755.h
3 * @brief Header file of AD5755 Driver. This driver supporting the following
4 * devices: AD5755, AD5755-1 and AD5757
5 * @author Istvan Csomortani ([email protected])
6 ********************************************************************************
7 * Copyright 2012(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 *******************************************************************************/
41 #ifndef __AD5755_H__
42 #define __AD5755_H__
43
44 /******************************************************************************/
45 /***************************** Include Files **********************************/
46 /******************************************************************************/
47 #include "Communication.h" // Communication definitions.
48 #include "TIME.h"
49
50 /* Supported devices */
51 typedef enum {
52 ID_AD5755,
53 ID_AD5755_1,
54 ID_AD5757,
55 } AD5755_type_t;
56
57 /******************************************************************************/
58 /******************* Macros and Constants Definitions *************************/
59 /******************************************************************************/
60
61 /******************************************************************************/
62 /******************************** AD5755 **************************************/
63 /******************************************************************************/
64
65 /* LDAC */
66 #define AD5755_LDAC_OUT GPIO1_PIN_OUT
67 #define AD5755_LDAC_LOW GPIO1_LOW
68 #define AD5755_LDAC_HIGH GPIO1_HIGH
69
70 /* RESET */
71 #define AD5755_RESET_OUT GPIO4_PIN_OUT
72 #define AD5755_RESET_LOW GPIO4_LOW
73 #define AD5755_RESET_HIGH GPIO4_HIGH
74
75 /* CLEAR */
76 #define AD5755_CLEAR_OUT GPIO3_PIN_OUT
77 #define AD5755_CLEAR_LOW GPIO3_LOW
78 #define AD5755_CLEAR_HIGH GPIO3_HIGH
79
80 /* POC */
81 #define AD5755_POC_OUT GPIO6_PIN_OUT
82 #define AD5755_POC_LOW GPIO6_LOW
83 #define AD5755_POC_HIGH GPIO6_HIGH
84
85 /* SPI slave device ID */
86 #define AD5755_SLAVE_ID 1
87
88 /* Input Shift Register Contents for a Write Operation. */
89 #define AD5755_ISR_WRITE (0ul << 23) /* R/nW */
90 #define AD5755_ISR_DUT_AD1(x) (((x) & 0x1) << 22) /* Device AddrBit1*/
91 #define AD5755_ISR_DUT_AD0(x) (((x) & 0x1) << 21) /* Device AddrBit0*/
92 #define AD5755_ISR_DREG(x) (((x) & 0x7) << 18) /* Register AddrBits*/
93 #define AD5755_ISR_DAC_AD(x) (((x) & 0x3) << 16) /* Channel AddrBits */
94 #define AD5755_ISR_DATA(x) ((x) & 0xFFFF) /* Data Bits*/
95
96 /* Nop operation code. */
97 #define AD5755_ISR_NOP 0x1CE000
98
99 /* AD5755_ISR_DREG(x) options. (Register addresses) */
100 #define AD5755_DREG_WR_DAC 0
101 #define AD5755_DREG_WR_GAIN 2
102 #define AD5755_DREG_WR_GAIN_ALL 3
103 #define AD5755_DREG_WR_OFFSET 4
104 #define AD5755_DREG_WR_OFFSET_ALL 5
105 #define AD5755_DREG_WR_CLR_CODE 6
106 #define AD5755_DREG_WR_CTRL_REG 7
107
108 /* AD5755_ISR_DAC_AD(x) options. (Channel addresses) */
109 #define AD5755_DAC_A 0
110 #define AD5755_DAC_B 1
111 #define AD5755_DAC_C 2
112 #define AD5755_DAC_D 3
113
114 /* Gain register definition. */
115 #define AD5755_GAIN_ADJUSTMENT(x) ((x) & 0xFFFF)
116
117 /* Offset register definition. */
118 #define AD5755_OFFSET_ADJUSTMENT(x) ((x) & 0xFFFF)
119
120 /* Clear Code Register definition. */
121 #define AD5755_CLEAR_CODE(x) ((x) & 0xFFFF)
122
123 /* Control Register definition. */
124 #define AD5755_CTRL_CREG(x) (((x) & 0x7) << 13)
125 #define AD5755_CTRL_DATA(x) ((x) & 0x1FFF)
126
127 /* AD5755_CTRL_CREG(x) options. */
128 #define AD5755_CREG_SLEW 0 // Slew rate control register(one per channel)
129 #define AD5755_CREG_MAIN 1 // Main control register
130 #define AD5755_CREG_DAC 2 // DAC control register(one per channel)
131 #define AD5755_CREG_DC_DC 3 // DC-to-dc control register
132 #define AD5755_CREG_SOFT 4 // Software register
133
134 /* Slew Rate Control Register definition. */
135 #define AD5755_SLEW_SREN (1 << 12)
136 #define AD5755_SLEW_SR_CLOCK(x) (((x) & 0xF) << 3)
137 #define AD5755_SLEW_SR_STEP(x) (((x) & 0x7) << 0)
138
139 /* AD5755_SLEW_SR_CLOCK(x) options. */
140 #define AD5755_SR_CLK_64K 0
141 #define AD5755_SR_CLK_32k 1
142 #define AD5755_SR_CLK_16k 2
143 #define AD5755_SR_CLK_8K 3
144 #define AD5755_SR_CLK_4K 4
145 #define AD5755_SR_CLK_2K 5
146 #define AD5755_SR_CLK_1K 6
147 #define AD5755_SR_CLK_500 7
148 #define AD5755_SR_CLK_250 8
149 #define AD5755_SR_CLK_125 9
150 #define AD5755_SR_CLK_64 10
151 #define AD5755_SR_CLK_32 11
152 #define AD5755_SR_CLK_16 12
153 #define AD5755_SR_CLK_8 13
154 #define AD5755_SR_CLK_4 14
155 #define AD5755_SR_CLK_0_5 15
156
157 /* AD5755_SLEW_SR_STEP(x) options. */
158 #define AD5755_STEP_1 0
159 #define AD5755_STEP_2 1
160 #define AD5755_STEP_4 2
161 #define AD5755_STEP_16 3
162 #define AD5755_STEP_32 4
163 #define AD5755_STEP_64 5
164 #define AD5755_STEP_128 6
165 #define AD5755_STEP_256 7
166
167 /* Main Control Register definition. */
168 #define AD5755_MAIN_POC (1 << 12)
169 #define AD5755_MAIN_STATREAD (1 << 11)
170 #define AD5755_MAIN_EWD (1 <<10)
171 #define AD5755_MAIN_WD(x) (((x) & 0x3) << 8)
172 #define AD5755_MAIN_SHTCCTLIM(x) (((x) & 0x1) << 6)
173 #define AD5755_MAIN_OUTEN_ALL (1 << 5)
174 #define AD5755_MAIN_DCDC_ALL (1 << 4)
175
176 /* AD5755_MAIN_WD(x) options. */
177 #define AD5755_WD_5MS 0 // 5 ms timeout period
178 #define AD5755_WD_10MS 1 // 10 ms timeout period
179 #define AD5755_WD_100MS 2 // 100 ms timeout period
180 #define AD5755_WD_200MS 3 // 200 ms timeout period
181
182 /* AD5755_MAIN_SHTCCTLIM(x) options. */
183 #define AD5755_LIMIT_16_MA 0 // 16 mA (default)
184 #define AD5755_LIMIT_8_MA 1 // 8 mA
185
186 /* DAC Control Register definition. */
187 #define AD5755_DAC_INT_ENABLE (1 << 8)
188 #define AD5755_DAC_CLR_EN (1 << 7)
189 #define AD5755_DAC_OUTEN (1 << 6)
190 #define AD5755_DAC_RSET (1 << 5)
191 #define AD5755_DAC_DC_DC (1 << 4)
192 #define AD5755_DAC_OVRNG (1 << 3)
193 #define AD5755_DAC_R(x) ((x) & 0x7)
194
195 /* AD5755_DAC_R(x) options. */
196 #define AD5755_R_0_5_V 0 // 0 V to 5 V voltage range (default)
197 #define AD5755_R_0_10_V 1 // 0 V to 10 V voltage range
198 #define AD5755_R_M5_P5_V 2 // -5 V to +5 V voltage range
199 #define AD5755_R_M10_P10_V 3 // -10 V to 10 V voltage range
200 #define AD5755_R_4_20_MA 4 // 4 mA to 20 mA current range
201 #define AD5755_R_0_20_MA 5 // 0 mA to 20 mA current range
202 #define AD5755_R_0_24_MA 6 // 0 mA to 24 mA current range
203
204 /* DC-to-DC Control Register definition. */
205 #define AD5755_DC_DC_COMP (1 << 6)
206 #define AD5755_DC_DC_PHASE(x) (((x) & 0x3) << 4)
207 #define AD5755_DC_DC_FREQ(x) (((x) & 0x3) << 2)
208 #define AD5755_DC_DC_MAX_V(x) (((x) & 0x3) << 0)
209
210 /* AD5755_DC_DC_PHASE(x) options. */
211 #define AD5755_PHASE_ALL_DC_DC 0 // all dc-dc converters clock on same edge
212 #define AD5755_PHASE_AB_CD 1 // Ch A,B clk same edge, C,D opposite edge
213 #define AD5755_PHASE_AC_BD 2 // Ch A,C clk same edge, B,D opposite edge
214 #define AD5755_PHASE_A_B_C_D_90 3 // A,B,C,D clock 90 degree out of phase
215
216 /* AD5755_DC_DC_FREQ(x) options. */
217 #define AD5755_FREQ_250_HZ 0 // 250 +/- 10% kHz
218 #define AD5755_FREQ_410_HZ 1 // 410 +/- 10% kHz
219 #define AD5755_FREQ_650_HZ 2 // 650 +/- 10% kHz
220
221 /* AD5755_DC_DC_MAX_V(x) options. */
222 #define AD5755_MAX_23V 0 // 23 V + 1 V/-1.5 V (default)
223 #define AD5755_MAX_24_5V 1 // 24.5 V +/- 1 V
224 #define AD5755_MAX_27V 2 // 27 V +/- 1 V
225 #define AD5755_MAX_29_5V 3 // 29.5 V +/- 1V
226
227 /* Software Register definition. */
228 #define AD5755_SOFT_USER_BIT (1 << 12)
229 #define AD5755_SOFT_RESET_CODE(x) ((x) & 0xFFF)
230
231 /* AD5755_SOFT_RESET_CODE(x) options. */
232 #define AD5755_RESET_CODE 0x555 // Performs a reset of the AD5755.
233 #define AD5755_SPI_CODE 0x195 // If watchdog is enabled, 0x195 must be
234 // written to the software register within
235 // the programmed timeout period.
236
237 /* Input Shift Register Contents for a Read Operation. */
238 #define AD5755_ISR_READ (1 << 23)
239 /* Same as Input Shift Register Contents for a Write Operation. */
240 /*
241 #define AD5755_ISR_DUT_AD1(x) (((x) & 0x1) << 22)
242 #define AD5755_ISR_DUT_AD0(x) (((x) & 0x1) << 21)
243 */
244 #define AD5755_ISR_RD(x) (((x) & 0x1F) << 16)
245
246 /* AD5755_ISR_RD(x) options. (Read address decoding) */
247 #define AD5755_RD_DATA_REG(x) (((x) & 0x3) + 0)
248 #define AD5755_RD_CTRL_REG(x) (((x) & 0x3) + 4)
249 #define AD5755_RD_GAIN_REG(x) (((x) & 0x3) + 8)
250 #define AD5755_RD_OFFSET_REG(x) (((x) & 0x3) + 12)
251 #define AD5755_RD_CODE_REG(x) (((x) & 0x3) + 16)
252 #define AD5755_RD_SR_CTRL_REG(x) (((x) & 0x3) + 20)
253 #define AD5755_RD_STATUS_REG 24
254 #define AD5755_RD_MAIN_CTRL_REG 25
255 #define AD5755_RD_Dc_DC_CTRL_REG 26
256
257 /* Status Register definition. */
258 /* channelA = 0 ... channelD = 3 */
259 #define AD5755_STATUS_DC_DC(x) (1 << (12 + (x)))
260 #define AD5755_STATUS_USER_BIT (1 << 11)
261 #define AD5755_STATUS_PEC_ERROR (1 << 10)
262 #define AD5755_STATUS_RAMP_ACTIVE (1 << 9)
263 #define AD5755_STATUS_OVER_TEMP (1 << 8)
264 /* channelA = 0 ... channelD = 3 */
265 #define AD5755_STATUS_VOUT_FAULT(x) (1 << (4 + (x)))
266 #define AD5755_STATUS_IOUT_FAULT(x) (1 << (0 + (x)))
267
268 #define AD5755_CRC_POLYNOMIAL 0x07 // P(x)=x^8+x^2+x^1+1 = 100000111
269 #define AD5755_CRC_CHECK_CODE 0x00
270
271 /*****************************************************************************/
272 /************************** Types Declarations *******************************/
273 /*****************************************************************************/
274 /**
275 * struct AD5755_InitialSettings - Stores the settings that will be written to
276 * the device when the "AD5755_Init" functions is called.
277 *
278 * @pinAD0state: Reflects the logic state of the external pin AD0. Range 0..1
279 * @pinAD1state: Reflects the logic state of the external pin AD1. Range 0..1
280 * @enablePacketErrorCheck: Enables/Disables the Packet Error Checking that is
281 * used during all SPI transfers. Range 0..1
282 * @pocBit: Power-On Condition. Determines the state of the voltage output
283 * channels during normal operation.
284 * 0 - The output goes to the value set by the POC hardware pin when
285 * the voltage output is not enabled;
286 * 1 - The output goes to the opposite value of the POC hardware pin
287 * if the voltage output is not enabled.
288 * @statReadBit: Enables/Disables status readback during a write. Range 0..1
289 * @shtCcLimBit: Programmable short-circuit limit on the VOUT_x pin in the event
290 * of a short-circuit condition: 0 - 16 mA
291 * 1 - 8 mA
292 * @rsetBits: Selects an internal or external current sense resistor for the
293 * selected DAC channel: 0 - selects the external resistor
294 * 1 - selects the internal resistor
295 * @ovrngBits: Enables 20% overrange on voltage output channel only. Range 0..1
296 * @dcDcCompBit: Selects between an internal and external compensation resistor
297 * for the dc-to-dc converter. Range 0..1
298 * @dcDcPhaseBit: User programmable dc-to-dc converter phase (between channels).
299 * Range 0..3
300 * @dcDcFreqBit: DC-to-dc switching frequency. Range 0..2
301 * @dcDcMaxVBit: Maximum allowed VBOOST_x voltage supplied by the dc-to-dc
302 * converter. Range 0..3
303 *
304 */
305 typedef struct AD5755_InitialSettings
306 {
307 unsigned char pinAD0state;
308 unsigned char pinAD1state;
309 unsigned char enablePacketErrorCheck;
310
311 /* Main Control Register bits */
312 unsigned char pocBit;
313 unsigned char statReadBit;
314 unsigned char shtCcLimBit;
315
316 /* DAC Control Registers: A, B, C and D */
317 unsigned char rsetBits[4];
318 unsigned char ovrngBits[4];
319
320 /* DC-to-DC Control Register */
321 unsigned char dcDcCompBit;
322 unsigned char dcDcPhaseBit;
323 unsigned char dcDcFreqBit;
324 unsigned char dcDcMaxVBit;
325 } AD5755_Setup;
326
327 /******************************************************************************/
328 /************************ Functions Declarations ******************************/
329 /******************************************************************************/
330
331 /*! Initializes the device and powers-up all channels. */
332 char AD5755_Init(AD5755_type_t device);
333
334 /*! Reads the value of a register. */
335 long AD5755_GetRegisterValue(unsigned char registerAddress);
336
337 /*! Writes data into a register. */
338 unsigned short AD5755_SetRegisterValue(unsigned char registerAddress,
339 unsigned char channel,
340 unsigned short registerValue);
341
342 /*! Performs a software reset to the device. */
343 void AD5755_Software_Reset(void);
344
345 /*! Enables/Disables watchdog timer and sets the timeout period. */
346 void AD5755_WatchDogSetup(unsigned char wtdEnable, unsigned char timeout);
347
348 /*! Writes a "service pulse" to the AD5755 watchdog timer when enabled. */
349 void AD5755_FeedWatchDogTimer(void);
350
351 /*! Configures one of the control registers. */
352 void AD5755_SetControlRegisters(unsigned char ctrlRegAddress,
353 unsigned char channel,
354 unsigned short regValue);
355
356 /*! Computes the CRC for a data buffer. */
357 unsigned char AD5755_CheckCrc(unsigned char* data, unsigned char bytesNumber);
358
359 /*! Allows power-up/down of the dc-to-dc converter, DAC and internal amplifiers
360 for the selected channel. */
361 void AD5755_SetChannelPower(unsigned char channel, unsigned char pwrStatus);
362
363 /*! Sets the range of a channel. */
364 void AD5755_SetChannelRange(unsigned char channel, unsigned char range);
365
366 /*! Selects if the channel clears when CLEAR pin is activated. */
367 void AD5755_ChannelClearEnable(unsigned char channel, unsigned char clearEn);
368
369 /*! Configures the Digital Slew Rate Control. */
370 void AD5755_SlewRateCtrl(char channel, char srEn, char updtFreq, char stepSize);
371
372 /*! Sets the output voltage of a channel. */
373 float AD5755_SetVoltage(unsigned char channel, float voltage);
374
375 /*! Sets the output current of a channel. */
376 float AD5755_SetCurrent(unsigned char channel, float mACurrent);
377
378 #endif // __AD5755_H__