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.
 
 
 
 

43 lines
1.1 KiB

  1. #ifndef CALIBRATE_H
  2. #define CALIBRATE_H
  3. #define ADC_CLAMP_MIN 256
  4. #define ADC_CLAMP_MAX 1792
  5. #define OVERSAMPLE_COUNT 256
  6. #define DAC_MIN DAC_LOW
  7. #define DAC_MAX DAC_HIGH
  8. #define SEEK_MAX_STEPS 1000
  9. #define SEEK_FUZZ_ADC 100
  10. #define SEEK_FUZZ_DAC (1+((DAC_RANGE * 5) / 65536))
  11. #define CALIBRATE_ADC_ZERO 1024
  12. #define CALIBRATE_ADC_LOW 512
  13. #define CALIBRATE_ADC_HIGH 1536
  14. /* Initialize. Assume some relatively-safe scaling if no calibration is run */
  15. void calibrate_init(void);
  16. /* Given the current DAC and ADC values d1 and a1,
  17. compute a new DAC value d2 to give the desired ADC value a2 */
  18. uint16_t adc_to_dac(uint16_t d1, int16_t a1, int16_t a2, float scale);
  19. /* Calculate a new scale factor given two DAC and ADC points */
  20. float calculate_scale(uint16_t d1, float a1, uint16_t d2, float a2);
  21. /* Seek with the DAC to reach a specific ADC value,
  22. using current scaling as a starting point. */
  23. uint16_t seek(uint16_t starting_dac, int16_t desired_adc);
  24. /* Perform calibration */
  25. uint16_t do_calibrate(void);
  26. /* Oversample to get a nice ADC value */
  27. float oversample(uint16_t dac);
  28. extern float g_scale; /* delta(DAC) / delta(ADC) */
  29. #endif