You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

44 lines
964 B

  1. #ifndef DAC_H
  2. #define DAC_H
  3. #include "config.h"
  4. #define FAKE_BITS
  5. #ifdef FAKE_BITS
  6. /* fake compressed range with random lookup bits */
  7. #define DAC_BITS 10
  8. #define __dac_actual(x) (dac_lookup[(x)&1023])
  9. #else
  10. /* normal range */
  11. #define DAC_BITS 16
  12. #define __dac_actual(x) (x)
  13. #endif
  14. #define DAC_LOW 0
  15. #define DAC_HIGH ((uint16_t)(((uint32_t)1 << DAC_BITS) - 1))
  16. #define DAC_MID ((uint16_t)((DAC_LOW + DAC_HIGH + (uint32_t)1) / 2))
  17. #define DAC_RANGE (DAC_HIGH - DAC_LOW + 1)
  18. /* Initialize DAC (AD5542) */
  19. void dac_init(void);
  20. /* Write raw value to DAC:
  21. DAC_HIGH 4.9998v
  22. DAC_MID 0v
  23. DAC_LOW -5v
  24. */
  25. void dac_write(uint16_t val);
  26. /* From DAC value, get the expected actual output voltage:
  27. 0xffff 4.9998v
  28. 0x8000 0v
  29. 0x0000 -5v
  30. */
  31. uint16_t dac_get_actual(uint16_t val);
  32. /* Get actual output voltage from DAC_LOW to DAC_HIGH, as a float */
  33. float dac_get_actual_float(uint16_t val);
  34. #endif