|
|
@@ -8,15 +8,18 @@ |
|
|
|
#if DAC_TYPE == 0
|
|
|
|
/* AD5542, normal 16-bit range */
|
|
|
|
#define DAC_BITS 16
|
|
|
|
#define __dac_actual(x) (x)
|
|
|
|
#define __dac_to_spi_cmd(x) (x)
|
|
|
|
#define __dac_to_16bit_equiv(x) (x)
|
|
|
|
#elif DAC_TYPE == 1
|
|
|
|
/* AD5542, fake 10-bit range using random lower bits */
|
|
|
|
#define DAC_BITS 10
|
|
|
|
#define __dac_actual(x) (dac_lookup[(x)&1023])
|
|
|
|
#define __dac_to_spi_cmd(x) (dac_lookup[(x)&1023])
|
|
|
|
#define __dac_to_16bit_equiv(x) (dac_lookup[(x)&1023])
|
|
|
|
#elif DAC_TYPE == 2
|
|
|
|
/* MAX504, true 10-bit DAC */
|
|
|
|
#define DAC_BITS 10
|
|
|
|
#define __dac_actual(x) ((x) << 2)
|
|
|
|
#define __dac_to_spi_cmd(x) ((x) << 2)
|
|
|
|
#define __dac_to_16bit_equiv(x) ((x) << 6)
|
|
|
|
#else
|
|
|
|
#error Unknown DAC type
|
|
|
|
#endif
|
|
|
@@ -36,14 +39,22 @@ void dac_init(void); |
|
|
|
*/
|
|
|
|
void dac_write(uint16_t val);
|
|
|
|
|
|
|
|
/* From DAC value, get the expected actual output voltage:
|
|
|
|
0xffff 4.9998v
|
|
|
|
0x8000 0v
|
|
|
|
0x0000 -5v
|
|
|
|
/* Given a DAC command between DAC_LOW and DAC_HIGH,
|
|
|
|
get the actual expected output voltage as a 16-bit value, where:
|
|
|
|
0xffff = 4.9998v
|
|
|
|
0x8000 = 0v
|
|
|
|
0x0000 = -5v
|
|
|
|
*/
|
|
|
|
uint16_t dac_get_actual_16bit(uint16_t val);
|
|
|
|
|
|
|
|
/* Given a DAC command between DAC_LOW and DAC_HIGH,
|
|
|
|
get the actual expected output voltage as a FLOAT, where:
|
|
|
|
DAC_HIGH = 4.9998v
|
|
|
|
DAC_MID = 0v
|
|
|
|
DAC_LOW = -5v
|
|
|
|
Example: for 10-bit DAC, convert integer command 123 into
|
|
|
|
the more accurate 123.45 using known lower bits.
|
|
|
|
*/
|
|
|
|
uint16_t dac_get_actual(uint16_t val);
|
|
|
|
|
|
|
|
/* Get actual output voltage from DAC_LOW to DAC_HIGH, as a float */
|
|
|
|
float dac_get_actual_float(uint16_t val);
|
|
|
|
|
|
|
|
#endif
|