#ifndef OPENPSU_CALIBRATION_H_ #define OPENPSU_CALIBRATION_H_ #include "util.h" /**************************************************************************** * Microcontroller CPU speed calibration * ****************************************************************************/ /* System timer calibration. Calibrated to 1000Hz */ #define SYSTIMER_TIMERFREQ ((0 << CS10) | (1 << CS11) | (0 << CS12)) /* == F_CPU/8 */ #define SYSTIMER_CMPVAL 2500 #define JIFFIES_PER_SECOND 1000 /**************************************************************************** * Other hardware calibration * ****************************************************************************/ /* The maximum voltage or current value for the 12bit DAC. */ #define MAX_DAC_VALUE ((1 << 12) - 1) /**************************************************************************** * Output voltage offset calibration * ****************************************************************************/ /* The maximum voltage value in millivolts. */ #define MAX_VOLTAGE 30000 /* Macro to convert an offset in millivolt to an offset in DAC steps. */ #define mV_offset(milli_offset) \ (int8_t)(((int8_t)(milli_offset) * (int32_t)MAX_DAC_VALUE) / (int32_t)MAX_VOLTAGE) /* Output voltage calibration. * The desired mV value is passed to this function. * It returns the DAC offset that is required for a voltage value * to really reach it at the output pins. */ static inline int8_t calib_voltage_offset(uint16_t mV) { if (mV <= 50) return mV_offset(0); if (mV <= 500) return mV_offset(27); if (mV <= 6000) return mV_offset(30); if (mV <= 10000) return mV_offset(20); if (mV <= 13000) return mV_offset(10); if (mV <= 15000) return mV_offset(0); if (mV <= 17000) return mV_offset(-10); if (mV <= 18000) return mV_offset(-20); if (mV <= 21000) return mV_offset(-30); if (mV <= 30000) return mV_offset(-40); BUG_ON(1); return 0; } /**************************************************************************** * Output Current offset calibration * ****************************************************************************/ /* The maximum current value in milliamps. */ #define MAX_CURRENT 3000 /* Macro to convert an offset in milliamps to an offset in DAC steps. */ #define mA_offset(milli_offset) \ (int8_t)(((int8_t)(milli_offset) * (int32_t)MAX_DAC_VALUE) / (int32_t)MAX_CURRENT) /* Output Max-Current calibration. * The desired mA value is passed to this function. * It returns the DAC offset that is required for a Current value * to really reach it at the output pins. */ static inline int8_t calib_maxcurrent_offset(uint16_t mV) { /* TODO */ return mA_offset(0); } #endif /* OPENPSU_CALIBRATION_H_ */