General usable MCP4728 quad DAC implementation only limited function has to be used together with the DevInterface lib
Dependents: mbedSerialInterface_talkback2 MCP4728test mbedSerialInterface_sequencer
mcp4728.h@5:164362cf5836, 2016-07-06 (annotated)
- Committer:
- wbeaumont
- Date:
- Wed Jul 06 14:55:28 2016 +0000
- Revision:
- 5:164362cf5836
- Parent:
- 4:f45f4ff5a51a
added methods to set output gain, ref source and power mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:7a0ebc527fb9 | 1 | #ifndef MCP_4728_H |
wbeaumont | 0:7a0ebc527fb9 | 2 | #define MCP_4728_H |
wbeaumont | 1:cd7c70a46739 | 3 | #include "getVersion.h" |
wbeaumont | 0:7a0ebc527fb9 | 4 | |
wbeaumont | 0:7a0ebc527fb9 | 5 | #include "stdbool.h" |
wbeaumont | 0:7a0ebc527fb9 | 6 | |
wbeaumont | 2:366e996af95c | 7 | |
wbeaumont | 0:7a0ebc527fb9 | 8 | #include "dev_interface_def.h" |
wbeaumont | 0:7a0ebc527fb9 | 9 | #include "I2CInterface.h" |
wbeaumont | 0:7a0ebc527fb9 | 10 | #include "DACInterface.h" |
wbeaumont | 0:7a0ebc527fb9 | 11 | |
wbeaumont | 5:164362cf5836 | 12 | #define VERSION_MCP4728_HDR "0.50" |
wbeaumont | 0:7a0ebc527fb9 | 13 | |
wbeaumont | 0:7a0ebc527fb9 | 14 | /** MCP4728 class. |
wbeaumont | 0:7a0ebc527fb9 | 15 | * Used for interfacing with a mcp4728 12-Bit QUAD Digital-to-Analog Converter. |
wbeaumont | 1:cd7c70a46739 | 16 | * For version 0.4X mode can not be set ( Intern ref, gain x2 power mode normal) |
wbeaumont | 2:366e996af95c | 17 | * It has to be used with the https://developer.mbed.org/users/wbeaumont/code/DevInterfaces/ package |
wbeaumont | 2:366e996af95c | 18 | * This includes the "virtual" I2CInterface class that is the interface to the I2C device |
wbeaumont | 2:366e996af95c | 19 | * An implementation of the I2Cinterface class for the MBED can be found at |
wbeaumont | 2:366e996af95c | 20 | * |
wbeaumont | 1:cd7c70a46739 | 21 | * ( DACInterface inherits getVersion ) |
wbeaumont | 5:164362cf5836 | 22 | * ee-prom set / read not tested / implemented. |
wbeaumont | 5:164362cf5836 | 23 | * |
wbeaumont | 5:164362cf5836 | 24 | * V 0.50 added methods to set the modes ( gain, ch power mode , reference |
wbeaumont | 5:164362cf5836 | 25 | * |
wbeaumont | 5:164362cf5836 | 26 | * (C) Wim Beaumont Universiteit Antwerpen 2015 2016 |
wbeaumont | 0:7a0ebc527fb9 | 27 | * |
wbeaumont | 0:7a0ebc527fb9 | 28 | */ |
wbeaumont | 1:cd7c70a46739 | 29 | class MCP4728 : public DACInterface { |
wbeaumont | 1:cd7c70a46739 | 30 | |
wbeaumont | 0:7a0ebc527fb9 | 31 | public: |
wbeaumont | 0:7a0ebc527fb9 | 32 | /** The device supports two types of power modes: normal and power-down. In normal mode the device |
wbeaumont | 0:7a0ebc527fb9 | 33 | * operates a normal digital to analog conversion. In power-down mode all digitial to analog |
wbeaumont | 0:7a0ebc527fb9 | 34 | * conversion is stopped, resulting in the device using less power (typically 60nA). Also, in power |
wbeaumont | 0:7a0ebc527fb9 | 35 | * down mode Vout will be pulled to ground using either a 1k, 100k or 500k ohm internal resistors. */ |
wbeaumont | 0:7a0ebc527fb9 | 36 | enum PowerMode { |
wbeaumont | 0:7a0ebc527fb9 | 37 | /** In normal mode the device operates a normal D2A conversion. */ |
wbeaumont | 0:7a0ebc527fb9 | 38 | Normal=0, |
wbeaumont | 0:7a0ebc527fb9 | 39 | /** Enter the device into a power down mode, and pull Vout to ground using an internal 1k resistor. */ |
wbeaumont | 0:7a0ebc527fb9 | 40 | PowerDown1k=1, |
wbeaumont | 0:7a0ebc527fb9 | 41 | /** Enter the device into a power down mode, and pull Vout to ground using an internal 100k resistor. */ |
wbeaumont | 0:7a0ebc527fb9 | 42 | PowerDown100k=2, |
wbeaumont | 0:7a0ebc527fb9 | 43 | /** Enter the device into a power down mode, and pull Vout to ground using an internal 500k resistor. */ |
wbeaumont | 0:7a0ebc527fb9 | 44 | PowerDown500k=3 |
wbeaumont | 0:7a0ebc527fb9 | 45 | }; |
wbeaumont | 2:366e996af95c | 46 | /** Voltage reference can be either External, this means the Vdd or internal , 2.048 V |
wbeaumont | 2:366e996af95c | 47 | The output goes from 0 to Vref ( either 2.048 V or Vdd ), |
wbeaumont | 2:366e996af95c | 48 | */ |
wbeaumont | 0:7a0ebc527fb9 | 49 | enum VrefMode { |
wbeaumont | 0:7a0ebc527fb9 | 50 | ExternRef=0, // == VDD |
wbeaumont | 1:cd7c70a46739 | 51 | InternRef=1 |
wbeaumont | 0:7a0ebc527fb9 | 52 | }; |
wbeaumont | 2:366e996af95c | 53 | /** In case the internal reference is used the output can be multiplied by a factor 2. |
wbeaumont | 2:366e996af95c | 54 | in that case the output goes between 0 and 4.096 V |
wbeaumont | 2:366e996af95c | 55 | */ |
wbeaumont | 0:7a0ebc527fb9 | 56 | enum GainMode { |
wbeaumont | 0:7a0ebc527fb9 | 57 | GainX1=0, |
wbeaumont | 0:7a0ebc527fb9 | 58 | GainX2=1 |
wbeaumont | 0:7a0ebc527fb9 | 59 | }; |
wbeaumont | 0:7a0ebc527fb9 | 60 | |
wbeaumont | 1:cd7c70a46739 | 61 | |
wbeaumont | 1:cd7c70a46739 | 62 | |
wbeaumont | 0:7a0ebc527fb9 | 63 | |
wbeaumont | 0:7a0ebc527fb9 | 64 | |
wbeaumont | 0:7a0ebc527fb9 | 65 | /** The device supports 3 different I2C bus frequencies.*/ |
wbeaumont | 0:7a0ebc527fb9 | 66 | enum BusFrequency { |
wbeaumont | 0:7a0ebc527fb9 | 67 | /** Standard 100kHz bus. */ |
wbeaumont | 0:7a0ebc527fb9 | 68 | Standard100kHz, |
wbeaumont | 0:7a0ebc527fb9 | 69 | /** Fast 400kHz bus. */ |
wbeaumont | 0:7a0ebc527fb9 | 70 | Fast400kHz, |
wbeaumont | 0:7a0ebc527fb9 | 71 | /** High Speed 3.4Mhz bus. WARNING: the test suite fails for the mbed LPC1768 when this frequency is selected - not tested on other platforms.*/ |
wbeaumont | 0:7a0ebc527fb9 | 72 | HighSpeed3_4Mhz |
wbeaumont | 0:7a0ebc527fb9 | 73 | }; |
wbeaumont | 2:366e996af95c | 74 | /** structure used to set the channel configuration */ |
wbeaumont | 2:366e996af95c | 75 | typedef struct MCP4728ChCfg{ |
wbeaumont | 2:366e996af95c | 76 | GainMode gain; |
wbeaumont | 2:366e996af95c | 77 | VrefMode vref; |
wbeaumont | 2:366e996af95c | 78 | PowerMode pwr; |
wbeaumont | 2:366e996af95c | 79 | } MCP4728ChCfgdummy; |
wbeaumont | 2:366e996af95c | 80 | |
wbeaumont | 0:7a0ebc527fb9 | 81 | |
wbeaumont | 0:7a0ebc527fb9 | 82 | /** Create an mcp4725 I2C interface |
wbeaumont | 0:7a0ebc527fb9 | 83 | * |
wbeaumont | 1:cd7c70a46739 | 84 | * @param i2cinterface pointer to the I2C interface (proto type) |
wbeaumont | 0:7a0ebc527fb9 | 85 | * @param device_address_bits The 3bit address bits of the device. |
wbeaumont | 3:2a2eafba8a1d | 86 | * @param Vdd the voltage on the Vdd pin ( power) is used to calculate voltage is Vref is set to external |
wbeaumont | 0:7a0ebc527fb9 | 87 | */ |
wbeaumont | 1:cd7c70a46739 | 88 | MCP4728(I2CInterface* i2cinterface, int device_address_bits, float Vdd ); |
wbeaumont | 0:7a0ebc527fb9 | 89 | |
wbeaumont | 1:cd7c70a46739 | 90 | |
wbeaumont | 1:cd7c70a46739 | 91 | /** Read the contents of the dac registers,( also eeprom settings) , and if an eeprom write is currently active. |
wbeaumont | 1:cd7c70a46739 | 92 | * result of the reading is stored in the channelstatus structure . |
wbeaumont | 4:f45f4ff5a51a | 93 | * @param checkall check if the channel nr and adress is returned correctly in 04x this is not tested /checked so set to false . |
wbeaumont | 4:f45f4ff5a51a | 94 | * @returns 0 on success non-0 on failure |
wbeaumont | 0:7a0ebc527fb9 | 95 | */ |
wbeaumont | 3:2a2eafba8a1d | 96 | int update(bool checkall); |
wbeaumont | 4:f45f4ff5a51a | 97 | |
wbeaumont | 4:f45f4ff5a51a | 98 | /** Read the contents of the dac registers,( also eeprom settings) , and if an eeprom write is currently active. |
wbeaumont | 4:f45f4ff5a51a | 99 | * result of the reading is stored in the channelstatus structure . |
wbeaumont | 4:f45f4ff5a51a | 100 | * implementation of the update from the DACInterface |
wbeaumont | 4:f45f4ff5a51a | 101 | * @returns 0 on success non-0 on failure |
wbeaumont | 4:f45f4ff5a51a | 102 | */ |
wbeaumont | 3:2a2eafba8a1d | 103 | |
wbeaumont | 1:cd7c70a46739 | 104 | virtual int update() { return update(false);} |
wbeaumont | 3:2a2eafba8a1d | 105 | |
wbeaumont | 3:2a2eafba8a1d | 106 | |
wbeaumont | 1:cd7c70a46739 | 107 | /** format a string with the channel status |
wbeaumont | 1:cd7c70a46739 | 108 | * @param ch : the channel nr |
wbeaumont | 3:2a2eafba8a1d | 109 | * @param updatereq: if true the function update(true) is called else the class status table is used . |
wbeaumont | 3:2a2eafba8a1d | 110 | * @param eprom: if true the values in the eprom are used else the values of the DAC channel |
wbeaumont | 4:f45f4ff5a51a | 111 | * @param str a pointer to an array of char by example chanstatstr[200] 200 is minuimum. |
wbeaumont | 1:cd7c70a46739 | 112 | * @param dimension of the str array ( so sizeoff(chanstatstr) |
wbeaumont | 4:f45f4ff5a51a | 113 | * @return the number of chars in the string or negative in case of an error |
wbeaumont | 1:cd7c70a46739 | 114 | */ |
wbeaumont | 1:cd7c70a46739 | 115 | int StatusString(int ch,bool updatereq ,bool eprom, char *str , int length); |
wbeaumont | 0:7a0ebc527fb9 | 116 | |
wbeaumont | 3:2a2eafba8a1d | 117 | /**gives the last value of the DAC register obtained by the last update command. |
wbeaumont | 3:2a2eafba8a1d | 118 | Implementation of the getDACvalue of the DACInterface |
wbeaumont | 3:2a2eafba8a1d | 119 | @param value by reference , the DAC value for the channel |
wbeaumont | 3:2a2eafba8a1d | 120 | @param ch the channel nr 0..3 |
wbeaumont | 3:2a2eafba8a1d | 121 | @return the I2C result of the last update command |
wbeaumont | 3:2a2eafba8a1d | 122 | */ |
wbeaumont | 1:cd7c70a46739 | 123 | virtual int getDACvalue(int &value, int ch=0); |
wbeaumont | 3:2a2eafba8a1d | 124 | /** gives the last value of the DAC output voltage obtained by the last update command. |
wbeaumont | 3:2a2eafba8a1d | 125 | Use the channel status bits and eventual Vdd value to convert the DAC value to a voltage. |
wbeaumont | 3:2a2eafba8a1d | 126 | Implementation of the getVoltagevalue of the DACInterface |
wbeaumont | 3:2a2eafba8a1d | 127 | @param voltage by reference , the DAC output voltage for the channel |
wbeaumont | 3:2a2eafba8a1d | 128 | @param ch the channel nr 0..3 |
wbeaumont | 3:2a2eafba8a1d | 129 | @return the I2C result of the last update command |
wbeaumont | 3:2a2eafba8a1d | 130 | */ |
wbeaumont | 1:cd7c70a46739 | 131 | virtual int getVoltage(float &voltage, int ch=0); |
wbeaumont | 0:7a0ebc527fb9 | 132 | |
wbeaumont | 3:2a2eafba8a1d | 133 | /** set the dac value for a certain channel. |
wbeaumont | 3:2a2eafba8a1d | 134 | Implementation of the setDACvalue of the DACInterface |
wbeaumont | 3:2a2eafba8a1d | 135 | It also sets the DAC configuration bits ( Vref, power mode , gain ) |
wbeaumont | 3:2a2eafba8a1d | 136 | ( For version 0.4x this is internal, normal power , gain x2 ) |
wbeaumont | 3:2a2eafba8a1d | 137 | @param value the DAC value to be set |
wbeaumont | 3:2a2eafba8a1d | 138 | @param ch the channel nr 0..3 |
wbeaumont | 4:f45f4ff5a51a | 139 | @return the I2C result when trying to set the DAC value |
wbeaumont | 3:2a2eafba8a1d | 140 | */ |
wbeaumont | 0:7a0ebc527fb9 | 141 | virtual int setDACvalue( int value, int ch=0); |
wbeaumont | 3:2a2eafba8a1d | 142 | |
wbeaumont | 3:2a2eafba8a1d | 143 | |
wbeaumont | 3:2a2eafba8a1d | 144 | /** gives the last value of the DAC output voltage obtained by the last update command. |
wbeaumont | 3:2a2eafba8a1d | 145 | Use the channel configuration setings and eventual Vdd value to convert the voltage to a DAC value. |
wbeaumont | 3:2a2eafba8a1d | 146 | Then it calls setDACValue so it sets also the channel configuration. |
wbeaumont | 3:2a2eafba8a1d | 147 | Implementation of the setVoltagevalue of the DACInterface |
wbeaumont | 3:2a2eafba8a1d | 148 | @param voltage by reference , the request DAC output voltage for the channel |
wbeaumont | 3:2a2eafba8a1d | 149 | @param ch the channel nr 0..3 |
wbeaumont | 4:f45f4ff5a51a | 150 | @return the I2C result when trying to set the DAC value |
wbeaumont | 3:2a2eafba8a1d | 151 | */ |
wbeaumont | 3:2a2eafba8a1d | 152 | |
wbeaumont | 1:cd7c70a46739 | 153 | virtual int setVoltage (float voltage, int ch=0); |
wbeaumont | 2:366e996af95c | 154 | |
wbeaumont | 5:164362cf5836 | 155 | /** prepare power mode to 1k for all channels , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 156 | */ |
wbeaumont | 5:164362cf5836 | 157 | void setPowerMode1k(){ for ( int ch=0;ch<4;ch++) ChCfg[ch].pwr=PowerDown1k;} |
wbeaumont | 2:366e996af95c | 158 | |
wbeaumont | 5:164362cf5836 | 159 | /** prepare power mode to 1k for a channel , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 160 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 161 | */ |
wbeaumont | 5:164362cf5836 | 162 | void setPowerMode1k(int ch ){ ChCfg[ch].pwr=PowerDown1k;} |
wbeaumont | 5:164362cf5836 | 163 | |
wbeaumont | 5:164362cf5836 | 164 | /** prepare power mode to 100k for all channels , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 165 | */ |
wbeaumont | 5:164362cf5836 | 166 | void setPowerMode100k(){ for ( int ch=0;ch<4;ch++) ChCfg[ch].pwr=PowerDown100k;} |
wbeaumont | 5:164362cf5836 | 167 | |
wbeaumont | 5:164362cf5836 | 168 | /** prepare power mode to 100k for a channel , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 169 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 170 | */ |
wbeaumont | 5:164362cf5836 | 171 | void setPowerMode100k(int ch ){ ChCfg[ch].pwr=PowerDown100k;} |
wbeaumont | 5:164362cf5836 | 172 | |
wbeaumont | 5:164362cf5836 | 173 | /** prepare power mode to 500k for all channels , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 174 | */ |
wbeaumont | 5:164362cf5836 | 175 | void setPowerMode500k(){ for ( int ch=0;ch<4;ch++) ChCfg[ch].pwr=PowerDown500k;} |
wbeaumont | 5:164362cf5836 | 176 | |
wbeaumont | 5:164362cf5836 | 177 | /** prepare power mode to 500k for a channel , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 178 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 179 | */ |
wbeaumont | 5:164362cf5836 | 180 | void setPowerMode500k(int ch ){ ChCfg[ch].pwr=PowerDown500k;} |
wbeaumont | 5:164362cf5836 | 181 | |
wbeaumont | 5:164362cf5836 | 182 | /** prepare power mode to normal (active) for all channels , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 183 | */ |
wbeaumont | 5:164362cf5836 | 184 | void setPowerModeNormal(){ for ( int ch=0;ch<4;ch++) ChCfg[ch].pwr=Normal;} |
wbeaumont | 5:164362cf5836 | 185 | |
wbeaumont | 5:164362cf5836 | 186 | /** prepare power mode to normal (active) for a channel , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 187 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 188 | */ |
wbeaumont | 5:164362cf5836 | 189 | void setPowerModeNormal(int ch ){ ChCfg[ch].pwr=Normal;} |
wbeaumont | 5:164362cf5836 | 190 | |
wbeaumont | 5:164362cf5836 | 191 | /** prepare to intern reference for a channel , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 192 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 193 | */ |
wbeaumont | 5:164362cf5836 | 194 | void setRefIntern ( ) { for ( int ch=0;ch<4;ch++) ChCfg[ch].vref=InternRef;} |
wbeaumont | 5:164362cf5836 | 195 | |
wbeaumont | 5:164362cf5836 | 196 | /** prepare to intern reference for a channel , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 197 | @param the channel the reference has to be set for. |
wbeaumont | 5:164362cf5836 | 198 | */ |
wbeaumont | 5:164362cf5836 | 199 | void setRefIntern (int ch ) { ChCfg[ch].vref=InternRef;} |
wbeaumont | 5:164362cf5836 | 200 | |
wbeaumont | 5:164362cf5836 | 201 | /** prepare to extern reference for a channel , mode becomes active with the next set voltage for the channel |
wbeaumont | 5:164362cf5836 | 202 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 203 | */ |
wbeaumont | 5:164362cf5836 | 204 | void setRefExtern ( ) { for ( int ch=0;ch<4;ch++) ChCfg[ch].vref=ExternRef;} |
wbeaumont | 5:164362cf5836 | 205 | |
wbeaumont | 5:164362cf5836 | 206 | /** prepare to intern reference for a channel. |
wbeaumont | 5:164362cf5836 | 207 | mode becomes active with the next set voltage for the channel!! |
wbeaumont | 5:164362cf5836 | 208 | @param the channel the reference has to be set for. |
wbeaumont | 5:164362cf5836 | 209 | */ |
wbeaumont | 5:164362cf5836 | 210 | void setRefExtern (int ch ) { ChCfg[ch].vref=ExternRef;} |
wbeaumont | 5:164362cf5836 | 211 | |
wbeaumont | 5:164362cf5836 | 212 | /** prepare to set the output gain to 2 for all channel |
wbeaumont | 5:164362cf5836 | 213 | mode becomes active with the next set voltage for the channel!! |
wbeaumont | 5:164362cf5836 | 214 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 215 | */ |
wbeaumont | 5:164362cf5836 | 216 | void setGainX2 () {for ( int ch=0;ch<4;ch++) ChCfg[ch].gain=GainX2;} |
wbeaumont | 5:164362cf5836 | 217 | |
wbeaumont | 5:164362cf5836 | 218 | /** prepare to set the output gain to 2 for a channel |
wbeaumont | 5:164362cf5836 | 219 | mode becomes active with the next set voltage for the channel!! |
wbeaumont | 5:164362cf5836 | 220 | @param the channel the reference has to be set for. |
wbeaumont | 5:164362cf5836 | 221 | */ |
wbeaumont | 5:164362cf5836 | 222 | void setGainX2 (int ch) { ChCfg[ch].gain=GainX2;} |
wbeaumont | 5:164362cf5836 | 223 | |
wbeaumont | 5:164362cf5836 | 224 | /** prepare to set the output gain to 1 for all channel |
wbeaumont | 5:164362cf5836 | 225 | mode becomes active with the next set voltage for the channel!! |
wbeaumont | 5:164362cf5836 | 226 | @param the channel the power mode has to be set for. |
wbeaumont | 5:164362cf5836 | 227 | */ |
wbeaumont | 5:164362cf5836 | 228 | void setGainX1 () {for ( int ch=0;ch<4;ch++) ChCfg[ch].gain=GainX1;} |
wbeaumont | 5:164362cf5836 | 229 | |
wbeaumont | 5:164362cf5836 | 230 | /** prepare to set the output gain to 1 for a channel |
wbeaumont | 5:164362cf5836 | 231 | mode becomes active with the next set voltage for the channel!! |
wbeaumont | 5:164362cf5836 | 232 | @param the channel the reference has to be set for. |
wbeaumont | 5:164362cf5836 | 233 | */ |
wbeaumont | 5:164362cf5836 | 234 | void setGainX1 (int ch) { ChCfg[ch].gain=GainX1;} |
wbeaumont | 5:164362cf5836 | 235 | |
wbeaumont | 2:366e996af95c | 236 | |
wbeaumont | 0:7a0ebc527fb9 | 237 | protected: |
wbeaumont | 1:cd7c70a46739 | 238 | /** pointer to the I2C interface driver. */ |
wbeaumont | 0:7a0ebc527fb9 | 239 | I2CInterface* _i2c_interface; |
wbeaumont | 0:7a0ebc527fb9 | 240 | /** The full i2c device address. */ |
wbeaumont | 0:7a0ebc527fb9 | 241 | int _device_address; |
wbeaumont | 1:cd7c70a46739 | 242 | char _adrbytes; |
wbeaumont | 3:2a2eafba8a1d | 243 | /** calculates the voltage based on the value and the channel configuration bits |
wbeaumont | 3:2a2eafba8a1d | 244 | @param value : the value of the DAC register |
wbeaumont | 3:2a2eafba8a1d | 245 | @param gain : the gain setting x1 or x2 |
wbeaumont | 3:2a2eafba8a1d | 246 | @param vref : use internal or external reference |
wbeaumont | 3:2a2eafba8a1d | 247 | @return : the voltage based on the parameters |
wbeaumont | 3:2a2eafba8a1d | 248 | */ |
wbeaumont | 1:cd7c70a46739 | 249 | float dig2volt( short int value,GainMode gain, VrefMode vref); |
wbeaumont | 3:2a2eafba8a1d | 250 | |
wbeaumont | 3:2a2eafba8a1d | 251 | /** calculates the nearest DAC register setting to get the requested voltage output |
wbeaumont | 3:2a2eafba8a1d | 252 | given the DAC configuration. There is no "under/ overflow" check |
wbeaumont | 3:2a2eafba8a1d | 253 | @param voltage the requested voltage |
wbeaumont | 3:2a2eafba8a1d | 254 | @param gain : the gain setting x1 or x2 |
wbeaumont | 4:f45f4ff5a51a | 255 | @param vref : use internal or external reference |
wbeaumont | 3:2a2eafba8a1d | 256 | @return : the DAC value based the parameters to get the requested output voltage |
wbeaumont | 3:2a2eafba8a1d | 257 | */ |
wbeaumont | 1:cd7c70a46739 | 258 | short int volt2dig( float voltage,GainMode gain, VrefMode vref); |
wbeaumont | 3:2a2eafba8a1d | 259 | |
wbeaumont | 3:2a2eafba8a1d | 260 | /** holds the Vdd value , used to calculate the voltage in case of vref = external */ |
wbeaumont | 1:cd7c70a46739 | 261 | float Vdd; |
wbeaumont | 3:2a2eafba8a1d | 262 | /** holds the status of the last update request */ |
wbeaumont | 3:2a2eafba8a1d | 263 | int lastupdateresult; |
wbeaumont | 0:7a0ebc527fb9 | 264 | |
wbeaumont | 3:2a2eafba8a1d | 265 | /** array for reading the status will be removed after debugging so don't use for future development */ |
wbeaumont | 3:2a2eafba8a1d | 266 | char rbdata[24] ; |
wbeaumont | 2:366e996af95c | 267 | |
wbeaumont | 3:2a2eafba8a1d | 268 | /** used setting the configuration bits for each channel |
wbeaumont | 3:2a2eafba8a1d | 269 | These values are the "requested" values so not the actual values. |
wbeaumont | 3:2a2eafba8a1d | 270 | These values are not updated after a update request !! |
wbeaumont | 3:2a2eafba8a1d | 271 | */ |
wbeaumont | 2:366e996af95c | 272 | MCP4728ChCfg ChCfg[4]; |
wbeaumont | 3:2a2eafba8a1d | 273 | /** structure to store all channel status / config bits */ |
wbeaumont | 2:366e996af95c | 274 | typedef struct MCP4728ChStatus{ |
wbeaumont | 2:366e996af95c | 275 | GainMode gain; |
wbeaumont | 2:366e996af95c | 276 | VrefMode vref; |
wbeaumont | 2:366e996af95c | 277 | PowerMode pwr; |
wbeaumont | 3:2a2eafba8a1d | 278 | bool busy; |
wbeaumont | 2:366e996af95c | 279 | bool por; |
wbeaumont | 2:366e996af95c | 280 | short int dacvalue; |
wbeaumont | 2:366e996af95c | 281 | short int promvalue; |
wbeaumont | 2:366e996af95c | 282 | GainMode promgain; |
wbeaumont | 2:366e996af95c | 283 | VrefMode promvref; |
wbeaumont | 2:366e996af95c | 284 | PowerMode prompwr; |
wbeaumont | 2:366e996af95c | 285 | |
wbeaumont | 2:366e996af95c | 286 | } MCP4728Chstatus; |
wbeaumont | 2:366e996af95c | 287 | |
wbeaumont | 3:2a2eafba8a1d | 288 | /** storage of the channel status and configuration bits */ |
wbeaumont | 3:2a2eafba8a1d | 289 | MCP4728ChStatus chstat[4]; |
wbeaumont | 2:366e996af95c | 290 | |
wbeaumont | 2:366e996af95c | 291 | |
wbeaumont | 0:7a0ebc527fb9 | 292 | }; |
wbeaumont | 0:7a0ebc527fb9 | 293 | |
wbeaumont | 0:7a0ebc527fb9 | 294 | #endif |