The MAX500 is an 8 bit DAC that can output to higher voltages (~12V). The chip has 4 onboard DAC channels.
MAX500.h@0:b74d88185698, 2012-07-03 (annotated)
- Committer:
- JimmyTheHack
- Date:
- Tue Jul 03 03:22:59 2012 +0000
- Revision:
- 0:b74d88185698
updated DAC_SPI library to have virtual select function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimmyTheHack | 0:b74d88185698 | 1 | #ifndef MAX500_H |
JimmyTheHack | 0:b74d88185698 | 2 | #define MAX500_H |
JimmyTheHack | 0:b74d88185698 | 3 | |
JimmyTheHack | 0:b74d88185698 | 4 | #include "DAC_SPI.h" |
JimmyTheHack | 0:b74d88185698 | 5 | |
JimmyTheHack | 0:b74d88185698 | 6 | /** |
JimmyTheHack | 0:b74d88185698 | 7 | * The MAX500 is a quad package 8 bit DAC. We should be able to produce four analog output voltages up to the externally wired voltage references (VrefA/B, VrefC, VrefD). |
JimmyTheHack | 0:b74d88185698 | 8 | The maximum voltage output is recommended to be about 4V less than the power supply voltage, although getting a 12V output from a 15V power supply is possible. |
JimmyTheHack | 0:b74d88185698 | 9 | * |
JimmyTheHack | 0:b74d88185698 | 10 | * Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX500.pdf |
JimmyTheHack | 0:b74d88185698 | 11 | * |
JimmyTheHack | 0:b74d88185698 | 12 | * We use the "3-wire" serial interface since it seems to be more compatible with the mbed Serial library timing than the "2-wire" interface. The 2-wire interface uses a somewhat non-standard timing scheme |
JimmyTheHack | 0:b74d88185698 | 13 | * and may require custom code support. |
JimmyTheHack | 0:b74d88185698 | 14 | * |
JimmyTheHack | 0:b74d88185698 | 15 | * All serial commands are 10 bit words. The highest 2 bits are control bits, while the last 8 are the data bits for the 8-bit DAC MAX500. |
JimmyTheHack | 0:b74d88185698 | 16 | * + bit 13-12: choose which DAC to use |
JimmyTheHack | 0:b74d88185698 | 17 | * + bit 11-0: Data bits for the DAC. |
JimmyTheHack | 0:b74d88185698 | 18 | */ |
JimmyTheHack | 0:b74d88185698 | 19 | class MAX500: public DAC_SPI |
JimmyTheHack | 0:b74d88185698 | 20 | { |
JimmyTheHack | 0:b74d88185698 | 21 | public: |
JimmyTheHack | 0:b74d88185698 | 22 | |
JimmyTheHack | 0:b74d88185698 | 23 | /** Initializes the MAX 500 DAC |
JimmyTheHack | 0:b74d88185698 | 24 | * |
JimmyTheHack | 0:b74d88185698 | 25 | * @param SPIchannelNum An int representing the SPI channel used by this DAC |
JimmyTheHack | 0:b74d88185698 | 26 | * channel 0 for p5 and p7 |
JimmyTheHack | 0:b74d88185698 | 27 | * channel 1 for p11 and p13 |
JimmyTheHack | 0:b74d88185698 | 28 | * @param LOAD The chip select pin (CS) used to identify the device |
JimmyTheHack | 0:b74d88185698 | 29 | * @param LDAC The LDAC pin used to synchronize updates of multiple devices |
JimmyTheHack | 0:b74d88185698 | 30 | */ |
JimmyTheHack | 0:b74d88185698 | 31 | MAX500(int SPIchannelNum, PinName LOAD, PinName LDAC); |
JimmyTheHack | 0:b74d88185698 | 32 | |
JimmyTheHack | 0:b74d88185698 | 33 | /** Writes a value between 0-255 to the currently selected DAC output |
JimmyTheHack | 0:b74d88185698 | 34 | * @param DACvalue a value from 0-255 to write to the DAC register |
JimmyTheHack | 0:b74d88185698 | 35 | */ |
JimmyTheHack | 0:b74d88185698 | 36 | virtual void write(int DACvalue); |
JimmyTheHack | 0:b74d88185698 | 37 | |
JimmyTheHack | 0:b74d88185698 | 38 | /** Writes a value in mV to the DAC outputs. |
JimmyTheHack | 0:b74d88185698 | 39 | * The output will only be accurate if Vref is set to the appropriate voltage reference scaling factor. |
JimmyTheHack | 0:b74d88185698 | 40 | * @param millivolts The desired voltage output in millivolts |
JimmyTheHack | 0:b74d88185698 | 41 | */ |
JimmyTheHack | 0:b74d88185698 | 42 | virtual void write_mV(int millivolts); |
JimmyTheHack | 0:b74d88185698 | 43 | |
JimmyTheHack | 0:b74d88185698 | 44 | /** If automatic updating is disabled, this will update the DAC output on command */ |
JimmyTheHack | 0:b74d88185698 | 45 | void update(); |
JimmyTheHack | 0:b74d88185698 | 46 | |
JimmyTheHack | 0:b74d88185698 | 47 | /** select whether to use DAC A or DAC B. |
JimmyTheHack | 0:b74d88185698 | 48 | * @param DACnum 0 to modify DAC A, 1 to modify DAC B |
JimmyTheHack | 0:b74d88185698 | 49 | */ |
JimmyTheHack | 0:b74d88185698 | 50 | virtual void select(char DACnum); |
JimmyTheHack | 0:b74d88185698 | 51 | |
JimmyTheHack | 0:b74d88185698 | 52 | /** If true, the DAC output will update as soon as the output value is modified. If false, it will wait for an update command*/ |
JimmyTheHack | 0:b74d88185698 | 53 | bool autoUpdate; |
JimmyTheHack | 0:b74d88185698 | 54 | |
JimmyTheHack | 0:b74d88185698 | 55 | /** The currently selected DAC channel. 0 for DAC A, 1 for DAC B*/ |
JimmyTheHack | 0:b74d88185698 | 56 | char DACselect; |
JimmyTheHack | 0:b74d88185698 | 57 | |
JimmyTheHack | 0:b74d88185698 | 58 | /** The output scaling factor in mV for channels A and B. |
JimmyTheHack | 0:b74d88185698 | 59 | * The voltage wired to Vref will be used as the scaling factor which the DAC will use in producing the output voltage. |
JimmyTheHack | 0:b74d88185698 | 60 | * If using the write_mV function, it is important that Vref is properly set. This library uses 5000mV by default. |
JimmyTheHack | 0:b74d88185698 | 61 | */ |
JimmyTheHack | 0:b74d88185698 | 62 | int VrefAB; |
JimmyTheHack | 0:b74d88185698 | 63 | /** The output scaling factor in mV for channel C. |
JimmyTheHack | 0:b74d88185698 | 64 | * The voltage wired to Vref will be used as the scaling factor which the DAC will use in producing the output voltage. |
JimmyTheHack | 0:b74d88185698 | 65 | * If using the write_mV function, it is important that Vref is properly set. This library uses 5000mV by default. |
JimmyTheHack | 0:b74d88185698 | 66 | */ |
JimmyTheHack | 0:b74d88185698 | 67 | int VrefC; |
JimmyTheHack | 0:b74d88185698 | 68 | /** The output scaling factor in mV for channel D. |
JimmyTheHack | 0:b74d88185698 | 69 | * The voltage wired to Vref will be used as the scaling factor which the DAC will use in producing the output voltage. |
JimmyTheHack | 0:b74d88185698 | 70 | * If using the write_mV function, it is important that Vref is properly set. This library uses 5000mV by default. |
JimmyTheHack | 0:b74d88185698 | 71 | */ |
JimmyTheHack | 0:b74d88185698 | 72 | int VrefD; |
JimmyTheHack | 0:b74d88185698 | 73 | |
JimmyTheHack | 0:b74d88185698 | 74 | |
JimmyTheHack | 0:b74d88185698 | 75 | |
JimmyTheHack | 0:b74d88185698 | 76 | }; |
JimmyTheHack | 0:b74d88185698 | 77 | |
JimmyTheHack | 0:b74d88185698 | 78 | #endif //MAX500_H |