|
- #ifndef DAC_H
- #define DAC_H
-
- #include "config.h"
-
- #define DAC_TYPE 2
-
- #if DAC_TYPE == 0
- /* AD5542, normal 16-bit range */
- #define DAC_BITS 16
- #define __dac_actual(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])
- #elif DAC_TYPE == 2
- /* MAX504, true 10-bit DAC */
- #define DAC_BITS 10
- #define __dac_actual(x) ((x) << 2)
- #else
- #error Unknown DAC type
- #endif
-
- #define DAC_LOW 0
- #define DAC_HIGH ((uint16_t)(((uint32_t)1 << DAC_BITS) - 1))
- #define DAC_MID ((uint16_t)((DAC_LOW + DAC_HIGH + (uint32_t)1) / 2))
- #define DAC_RANGE (DAC_HIGH - DAC_LOW + 1)
-
- /* Initialize DAC (AD5542) */
- void dac_init(void);
-
- /* Write raw value to DAC:
- DAC_HIGH 4.9998v
- DAC_MID 0v
- DAC_LOW -5v
- */
- void dac_write(uint16_t val);
-
- /* From DAC value, get the expected actual output voltage:
- 0xffff 4.9998v
- 0x8000 0v
- 0x0000 -5v
- */
- 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
|