| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#ifndef __AD5755_H__ |
| 42 |
#define __AD5755_H__ |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
#include "Communication.h" |
| 48 |
#include "TIME.h" |
| 49 |
|
| 50 |
|
| 51 |
typedef enum { |
| 52 |
ID_AD5755, |
| 53 |
ID_AD5755_1, |
| 54 |
ID_AD5757, |
| 55 |
} AD5755_type_t; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
#define AD5755_LDAC_OUT GPIO1_PIN_OUT |
| 67 |
#define AD5755_LDAC_LOW GPIO1_LOW |
| 68 |
#define AD5755_LDAC_HIGH GPIO1_HIGH |
| 69 |
|
| 70 |
|
| 71 |
#define AD5755_RESET_OUT GPIO4_PIN_OUT |
| 72 |
#define AD5755_RESET_LOW GPIO4_LOW |
| 73 |
#define AD5755_RESET_HIGH GPIO4_HIGH |
| 74 |
|
| 75 |
|
| 76 |
#define AD5755_CLEAR_OUT GPIO3_PIN_OUT |
| 77 |
#define AD5755_CLEAR_LOW GPIO3_LOW |
| 78 |
#define AD5755_CLEAR_HIGH GPIO3_HIGH |
| 79 |
|
| 80 |
|
| 81 |
#define AD5755_POC_OUT GPIO6_PIN_OUT |
| 82 |
#define AD5755_POC_LOW GPIO6_LOW |
| 83 |
#define AD5755_POC_HIGH GPIO6_HIGH |
| 84 |
|
| 85 |
|
| 86 |
#define AD5755_SLAVE_ID 1 |
| 87 |
|
| 88 |
|
| 89 |
#define AD5755_ISR_WRITE (0ul << 23) |
| 90 |
#define AD5755_ISR_DUT_AD1(x) (((x) & 0x1) << 22) |
| 91 |
#define AD5755_ISR_DUT_AD0(x) (((x) & 0x1) << 21) |
| 92 |
#define AD5755_ISR_DREG(x) (((x) & 0x7) << 18) |
| 93 |
#define AD5755_ISR_DAC_AD(x) (((x) & 0x3) << 16) |
| 94 |
#define AD5755_ISR_DATA(x) ((x) & 0xFFFF) |
| 95 |
|
| 96 |
|
| 97 |
#define AD5755_ISR_NOP 0x1CE000 |
| 98 |
|
| 99 |
|
| 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 |
|
| 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 |
|
| 115 |
#define AD5755_GAIN_ADJUSTMENT(x) ((x) & 0xFFFF) |
| 116 |
|
| 117 |
|
| 118 |
#define AD5755_OFFSET_ADJUSTMENT(x) ((x) & 0xFFFF) |
| 119 |
|
| 120 |
|
| 121 |
#define AD5755_CLEAR_CODE(x) ((x) & 0xFFFF) |
| 122 |
|
| 123 |
|
| 124 |
#define AD5755_CTRL_CREG(x) (((x) & 0x7) << 13) |
| 125 |
#define AD5755_CTRL_DATA(x) ((x) & 0x1FFF) |
| 126 |
|
| 127 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 183 |
#define AD5755_LIMIT_16_MA 0 // 16 mA (default) |
| 184 |
#define AD5755_LIMIT_8_MA 1 // 8 mA |
| 185 |
|
| 186 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 228 |
#define AD5755_SOFT_USER_BIT (1 << 12) |
| 229 |
#define AD5755_SOFT_RESET_CODE(x) ((x) & 0xFFF) |
| 230 |
|
| 231 |
|
| 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 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
#define AD5755_ISR_READ (1 << 23) |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
#define AD5755_ISR_RD(x) (((x) & 0x1F) << 16) |
| 245 |
|
| 246 |
|
| 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 |
|
| 258 |
|
| 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 |
|
| 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 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
typedef struct AD5755_InitialSettings |
| 306 |
{ |
| 307 |
unsigned char pinAD0state; |
| 308 |
unsigned char pinAD1state; |
| 309 |
unsigned char enablePacketErrorCheck; |
| 310 |
|
| 311 |
|
| 312 |
unsigned char pocBit; |
| 313 |
unsigned char statReadBit; |
| 314 |
unsigned char shtCcLimBit; |
| 315 |
|
| 316 |
|
| 317 |
unsigned char rsetBits[4]; |
| 318 |
unsigned char ovrngBits[4]; |
| 319 |
|
| 320 |
|
| 321 |
unsigned char dcDcCompBit; |
| 322 |
unsigned char dcDcPhaseBit; |
| 323 |
unsigned char dcDcFreqBit; |
| 324 |
unsigned char dcDcMaxVBit; |
| 325 |
} AD5755_Setup; |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
char AD5755_Init(AD5755_type_t device); |
| 333 |
|
| 334 |
|
| 335 |
long AD5755_GetRegisterValue(unsigned char registerAddress); |
| 336 |
|
| 337 |
|
| 338 |
unsigned short AD5755_SetRegisterValue(unsigned char registerAddress, |
| 339 |
unsigned char channel, |
| 340 |
unsigned short registerValue); |
| 341 |
|
| 342 |
|
| 343 |
void AD5755_Software_Reset(void); |
| 344 |
|
| 345 |
|
| 346 |
void AD5755_WatchDogSetup(unsigned char wtdEnable, unsigned char timeout); |
| 347 |
|
| 348 |
|
| 349 |
void AD5755_FeedWatchDogTimer(void); |
| 350 |
|
| 351 |
|
| 352 |
void AD5755_SetControlRegisters(unsigned char ctrlRegAddress, |
| 353 |
unsigned char channel, |
| 354 |
unsigned short regValue); |
| 355 |
|
| 356 |
|
| 357 |
unsigned char AD5755_CheckCrc(unsigned char* data, unsigned char bytesNumber); |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
void AD5755_SetChannelPower(unsigned char channel, unsigned char pwrStatus); |
| 362 |
|
| 363 |
|
| 364 |
void AD5755_SetChannelRange(unsigned char channel, unsigned char range); |
| 365 |
|
| 366 |
|
| 367 |
void AD5755_ChannelClearEnable(unsigned char channel, unsigned char clearEn); |
| 368 |
|
| 369 |
|
| 370 |
void AD5755_SlewRateCtrl(char channel, char srEn, char updtFreq, char stepSize); |
| 371 |
|
| 372 |
|
| 373 |
float AD5755_SetVoltage(unsigned char channel, float voltage); |
| 374 |
|
| 375 |
|
| 376 |
float AD5755_SetCurrent(unsigned char channel, float mACurrent); |
| 377 |
|
| 378 |
#endif |