Driver for the DACxx6xT series of Texas Instruments DACs Not all functions have been implemented yet. DAC7562T, DAC7563T, DAC8162T DAC8163T, DAC8562T, DAC8563T

Committer:
Ryan Vasquez
Date:
Tue Jan 29 13:07:27 2019 -0600
Revision:
2:6edde8a229f7
Parent:
1:c033f984277b
Corrected some formulas and initialized custom gains to 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rvasquez6089 0:af07575e0c04 1 #ifndef DACXX6XT_DRIVER_H
rvasquez6089 0:af07575e0c04 2 #define DACXX6XT_DRIVER_H
rvasquez6089 0:af07575e0c04 3
rvasquez6089 0:af07575e0c04 4 #include "mbed.h"
rvasquez6089 0:af07575e0c04 5
rvasquez6089 0:af07575e0c04 6 #define WRITE_DAC_A_REG 0x00 //Write to DAC-A input register
rvasquez6089 0:af07575e0c04 7 #define WRITE_DAC_B_REG 0x01 //Write to DAC-B input register
rvasquez6089 0:af07575e0c04 8 #define WRITE_DAC_AB_REG 0x07 //Write to DAC-A and DAC-B input registers
rvasquez6089 0:af07575e0c04 9 #define WRITE_DAC_A_REG_UPDATE_ALL 0x10 //Write to DAC-A input register and update all DACs
rvasquez6089 0:af07575e0c04 10 #define WRITE_DAC_B_REG_UPDATE_ALL 0x11 //Write to DAC-B input register and update all DACs
rvasquez6089 0:af07575e0c04 11 //#define WRITE_DAC_AB_REG_UPDATE_ALL 0x17 //Write to DAC-A and DAC-B input register and update all DACs
rvasquez6089 0:af07575e0c04 12 #define WRITE_DAC_A_REG_UPDATE_A 0x18 //Write to DAC-A input register and update DAC-A
rvasquez6089 0:af07575e0c04 13 #define WRITE_DAC_B_REG_UPDATE_B 0x19 //Write to DAC-B input register and update DAC-B
rvasquez6089 0:af07575e0c04 14 #define WRITE_DAC_AB_REG_UPDATE_ALL 0x1F //Write to DAC-A and DAC-B input register and update all DACs
rvasquez6089 0:af07575e0c04 15 #define UPDATE_DAC_A 0x08 //Update DAC-A
rvasquez6089 0:af07575e0c04 16 #define UPDATE_DAC_B 0x09 //Update DAC-B
rvasquez6089 0:af07575e0c04 17 #define UPDATE_ALL_DACS 0x0F //Update all DACs
Ryan Vasquez 1:c033f984277b 18 #define DAC_B_G2_DAC_A_G2 0x020000 //0 Gain: DAC-B gain = 2, DAC-A gain = 2 (default with internal VREF)
rvasquez6089 0:af07575e0c04 19 #define DAC_B_G2_DAC_A_G1 0x020001 //Gain: DAC-B gain = 2, DAC-A gain = 1
rvasquez6089 0:af07575e0c04 20 #define DAC_B_G1_DAC_A_G2 0x020002 //Gain: DAC-B gain = 1, DAC-A gain = 2
rvasquez6089 0:af07575e0c04 21 #define DAC_B_G1_DAC_A_G1 0x020003 //Gain: DAC-B gain = 1, DAC-A gain = 1 (power-on default)
rvasquez6089 0:af07575e0c04 22 #define POWERUP_DAC_A 0x200001 //Power up DAC-A
rvasquez6089 0:af07575e0c04 23 #define POWERUP_DAC_B 0x200002 //Power up DAC-B
rvasquez6089 0:af07575e0c04 24 #define POWERUP_ALL_DAC 0x200003 //Power up DAC-A and DAC-B
rvasquez6089 0:af07575e0c04 25 #define POWERDOWN_DAC_A_1K 0x020009 //Power down DAC-A; 1 kΩ to GND
rvasquez6089 0:af07575e0c04 26 #define POWERDOWN_DAC_B_1K 0x02000A //Power down DAC-B; 1 kΩ to GND
rvasquez6089 0:af07575e0c04 27 #define POWERDOWN_DAC_ALL_1K 0x02000B //Power down DAC-A and DAC-B; 1 kΩ to GND
rvasquez6089 0:af07575e0c04 28 #define POWERDOWN_DAC_A_100K 0x0200011 // Power down DAC-A; 100 kΩ to GND
rvasquez6089 0:af07575e0c04 29 #define POWERDOWN_DAC_B_100K 0x0200012 // Power down DAC-B; 100 kΩ to GND
rvasquez6089 0:af07575e0c04 30 #define POWERDOWN_DAC_ALL_100K 0x0200013 // Power down DAC-A and DAC-B; 100 kΩ to GND
rvasquez6089 0:af07575e0c04 31 #define POWERDOWN_DAC_A_HIZ 0x0200019 //Power down DAC-A; Hi-Z
rvasquez6089 0:af07575e0c04 32 #define POWERDOWN_DAC_B_HIZ 0x020001A //Power down DAC-B; Hi-Z
rvasquez6089 0:af07575e0c04 33 #define POWERDOWN_DAC_ALL_HIZ 0x020001B //Power down DAC-A and DAC-B; Hi-Z
rvasquez6089 0:af07575e0c04 34 #define RESET_DAC_ALL_UPDATE_ALL 0x280000 //Reset DAC-A and DAC-B input register and update all DACs
rvasquez6089 0:af07575e0c04 35 #define RESET_ALL_REG_UPDATE_ALL 0x280001 //Reset all registers and update all DACs (Power-on-reset update)
rvasquez6089 0:af07575e0c04 36 #define LDAC_ACTAB 0x300000 // LDAC pin active for DAC-B and DAC-A
rvasquez6089 0:af07575e0c04 37 #define LDAC_ACTB_ONLY 0x300001 //LDAC pin active for DAC-B; inactive for DAC-A
rvasquez6089 0:af07575e0c04 38 #define LDAC_ACTA_ONLY 0x300002 //LDAC pin inactive for DAC-B; active for DAC-A
rvasquez6089 0:af07575e0c04 39 #define LDAC_IVACTIVE_ALL 0x300003 //LDAC pin inactive for DAC-B and DAC-A
rvasquez6089 0:af07575e0c04 40 #define DIS_INTREF_GAIN1_ALL 0x380000 //Disable internal reference and reset DACs to gain = 1
rvasquez6089 0:af07575e0c04 41 #define EN_INTREF_GAIN2_ALL 0x380001 //Enable internal reference and reset DACs to gain = 2
rvasquez6089 0:af07575e0c04 42 #define INTERNAL_VREF 2.5 //Internal voltage reference
rvasquez6089 0:af07575e0c04 43
rvasquez6089 0:af07575e0c04 44 /** This is a driver for the DACxx6xT series of Texas instruments DACs
rvasquez6089 0:af07575e0c04 45 */
rvasquez6089 0:af07575e0c04 46 class DACxx6xT
rvasquez6089 0:af07575e0c04 47 {
rvasquez6089 0:af07575e0c04 48 public:
rvasquez6089 0:af07575e0c04 49 DACxx6xT(SPI *A, float Vref);
rvasquez6089 0:af07575e0c04 50 /** Create a DACxx6xT device class
rvasquez6089 0:af07575e0c04 51 *
rvasquez6089 0:af07575e0c04 52 * Constructor for the DACxx6xT class
rvasquez6089 0:af07575e0c04 53 *
rvasquez6089 0:af07575e0c04 54 * @param A SPI object pointer, this is the SPI bus the DAC is one
rvasquez6089 0:af07575e0c04 55 * @param Vref for the external voltage reference you are using. The default is 3.3V.
rvasquez6089 0:af07575e0c04 56 */
rvasquez6089 0:af07575e0c04 57 DACxx6xT(SPI *A, DigitalOut *device_CS, float Vref);
rvasquez6089 0:af07575e0c04 58 /** This funciton can be run to initialize everything to its default state
rvasquez6089 0:af07575e0c04 59 */
rvasquez6089 0:af07575e0c04 60 void init();
rvasquez6089 0:af07575e0c04 61 /** Write a value to the DAC
rvasquez6089 0:af07575e0c04 62 *
rvasquez6089 0:af07575e0c04 63 * The number written to do the DAC will be a 16 bit number regardless of
rvasquez6089 0:af07575e0c04 64 * whether the part is 12,14, or 16 bit. This maintains forward and backward
rvasquez6089 0:af07575e0c04 65 * compatibility between the parts.
rvasquez6089 0:af07575e0c04 66 *
rvasquez6089 0:af07575e0c04 67 * @param value 16 bit value to be written to DAC
rvasquez6089 0:af07575e0c04 68 * @param dacnum pick between DAC A or B. DAC A = 1, DAC B = 2
rvasquez6089 0:af07575e0c04 69 * @param daccs choose which device number you want to select
rvasquez6089 0:af07575e0c04 70 */
rvasquez6089 0:af07575e0c04 71 void write(short value, int dacnum);
rvasquez6089 0:af07575e0c04 72
rvasquez6089 0:af07575e0c04 73 /** Sets the internal gain on the DACs. The default gain on the DACs
rvasquez6089 0:af07575e0c04 74 * is 1 and it uses the external reference for refence
rvasquez6089 0:af07575e0c04 75 *
rvasquez6089 0:af07575e0c04 76 * @param dac select the DAC for gain change 1 for DAC A and 2 DAC B
rvasquez6089 0:af07575e0c04 77 * @param gain gain you want. 1 for 1 and 2 for 2
rvasquez6089 0:af07575e0c04 78 */
rvasquez6089 0:af07575e0c04 79 void set_DAC_gain(short gain, int dacnum);
rvasquez6089 0:af07575e0c04 80
rvasquez6089 0:af07575e0c04 81 void enable_internal_vref();
rvasquez6089 0:af07575e0c04 82 void disable_internal_vref();
rvasquez6089 0:af07575e0c04 83 void write_voltage(float value, int dacnum);
rvasquez6089 0:af07575e0c04 84 void set_custom_gain(float value, int dacnum);
rvasquez6089 0:af07575e0c04 85 private:
rvasquez6089 0:af07575e0c04 86 int numslaves;
rvasquez6089 0:af07575e0c04 87 DigitalOut *CS;
Ryan Vasquez 1:c033f984277b 88 float vref_A;
Ryan Vasquez 1:c033f984277b 89 float vref_B;
rvasquez6089 0:af07575e0c04 90 float vrefpin;
rvasquez6089 0:af07575e0c04 91 float gain_DAC_A;
rvasquez6089 0:af07575e0c04 92 float gain_DAC_B;
rvasquez6089 0:af07575e0c04 93 float custom_gain_A;
rvasquez6089 0:af07575e0c04 94 float custom_gain_B;
rvasquez6089 0:af07575e0c04 95 SPI *DACC;
rvasquez6089 0:af07575e0c04 96 };
rvasquez6089 0:af07575e0c04 97
rvasquez6089 0:af07575e0c04 98 #endif