| 1 | /***************************************************************************//** |
| 2 | * @file AD5628.h |
| 3 | * @brief Header file of AD5628 Driver. |
| 4 | * @author DNechita ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2012(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | ******************************************************************************** |
| 40 | * SVN Revision: $WCREV$ |
| 41 | *******************************************************************************/ |
| 42 | |
| 43 | #ifndef __AD5628_H__ |
| 44 | #define __AD5628_H__ |
| 45 | |
| 46 | /******************************************************************************/ |
| 47 | /***************************** Include Files **********************************/ |
| 48 | /******************************************************************************/ |
| 49 | #include "Communication.h" |
| 50 | |
| 51 | /******************************************************************************/ |
| 52 | /******************************** AD5628 **************************************/ |
| 53 | /******************************************************************************/ |
| 54 | |
| 55 | /* SPI slave device ID */ |
| 56 | #define AD5628_SLAVE_ID 1 |
| 57 | |
| 58 | /* AD5628 Input Register */ |
| 59 | #define AD5628_CMD(x) ((0x000F & (long)(x)) << 24) |
| 60 | #define AD5628_ADDR(x) ((0x000F & (long)(x)) << 20) |
| 61 | #define AD5628_DATA_BITS(x) ((0x0FFF & (long)(x)) << 8) |
| 62 | |
| 63 | /* Command Definitions (AD5628_COMMAND(x) options) */ |
| 64 | #define AD5628_CMD_WRITE_INPUT_N 0 // Write to Input Register n. |
| 65 | #define AD5628_CMD_UPDATE_DAC_N 1 // Update DAC Register n. |
| 66 | #define AD5628_CMD_WRITE_INPUT_N_UPDATE_ALL 2 // Write to Input Register n, update all. |
| 67 | #define AD5628_CMD_WRITE_INPUT_N_UPDATE_N 3 // Write to and update DAC Channel n. |
| 68 | #define AD5628_CMD_POWERDOWN 4 // Power down/power up DAC. |
| 69 | #define AD5628_CMD_LOAD_CLEAR_CODE 5 // Load clear code register. |
| 70 | #define AD5628_CMD_LOAD_LDAC_REG 6 // Load LDAC register. |
| 71 | #define AD5628_CMD_RESET 7 // Reset (power-on reset) |
| 72 | #define AD5628_CMD_SET_INT_REF 8 // Set up internal REF register. |
| 73 | |
| 74 | /* Address Commands (AD5628_ADDRESS(x) options) */ |
| 75 | #define AD5628_ADDR_DAC_A 0x00 //DAC A |
| 76 | #define AD5628_ADDR_DAC_B 0x01 //DAC B |
| 77 | #define AD5628_ADDR_DAC_C 0x02 //DAC C |
| 78 | #define AD5628_ADDR_DAC_D 0x03 //DAC D |
| 79 | #define AD5628_ADDR_DAC_E 0x04 //DAC E |
| 80 | #define AD5628_ADDR_DAC_F 0x05 //DAC F |
| 81 | #define AD5628_ADDR_DAC_G 0x06 //DAC G |
| 82 | #define AD5628_ADDR_DAC_H 0x07 //DAC H |
| 83 | #define AD5628_ADDR_DAC_ALL 0x0F //All DACs |
| 84 | |
| 85 | /* Internal Reference Register */ |
| 86 | #define AD5628_INT_REF_OFF 0 |
| 87 | #define AD5628_INT_REF_ON 1 |
| 88 | |
| 89 | /* Power-Down Modes of Operation */ |
| 90 | #define AD5628_POWER_MODE(x) ((0x03 & (unsigned short) (x)) << 8) |
| 91 | |
| 92 | #define AD5628_PWRDN_NONE 0 // Normal operation |
| 93 | #define AD5628_PWRDN_1K 1 // 1 KOhm to GND (Power-down mode) |
| 94 | #define AD5628_PWRDN_100K 2 // 100 KOhm to GND (Power-down mode) |
| 95 | #define AD5628_PWRDN_3STATE 3 // Three-state (Power-down mode) |
| 96 | |
| 97 | /* Clear Code Function */ |
| 98 | #define AD5628_CODE_0X0000 0 |
| 99 | #define AD5628_CODE_0X8000 1 |
| 100 | #define AD5628_CODE_0XFFFF 2 |
| 101 | #define AD5628_CODE_NOP 3 |
| 102 | |
| 103 | /******************************************************************************/ |
| 104 | /************************ Functions Declarations ******************************/ |
| 105 | /******************************************************************************/ |
| 106 | |
| 107 | /*! Resets the device and performs several initializations. */ |
| 108 | char AD5628_Init(void); |
| 109 | |
| 110 | /*! Sets the device in a specific power mode. */ |
| 111 | void AD5628_PowerMode(unsigned char pwrMode, unsigned char channel); |
| 112 | |
| 113 | /*! Resets the device. */ |
| 114 | void AD5628_Reset(void); |
| 115 | |
| 116 | /*! Writes a 32-bit data-word to the Input Register of the device. */ |
| 117 | void AD5628_SetInputRegister(unsigned long registerValue); |
| 118 | |
| 119 | #endif /* __AD5628_H__ */ |