diff --git a/src/eez/apps/psu/calibration.cpp b/src/eez/apps/psu/calibration.cpp index a55f40945..a92f21e2f 100644 --- a/src/eez/apps/psu/calibration.cpp +++ b/src/eez/apps/psu/calibration.cpp @@ -126,21 +126,21 @@ bool Value::checkRange(float dac, float data, float adc) { } } - float allowedDiff = range * CALIBRATION_DATA_TOLERANCE / 100; + float allowedDiff = range * g_channel->params->CALIBRATION_DATA_TOLERANCE_PERCENT / 100; float diff; diff = fabsf(dac - data); if (diff > allowedDiff) { - DebugTrace("Data check failed: level=%f, data=%f, diff=%f, allowedDiff=%f", dac, data, - diff, allowedDiff); + DebugTrace("Data check failed: level=%f, data=%f, diff=%f, allowedDiff=%f", dac, data, diff, allowedDiff); return false; } - diff = fabsf(dac - adc); - if (diff > allowedDiff) { - DebugTrace("ADC check failed: level=%f, adc=%f, diff=%f, allowedDiff=%f", dac, adc, diff, - allowedDiff); - return false; + if (g_slots[g_channel->slotIndex].moduleType != MODULE_TYPE_DCM220) { + diff = fabsf(dac - adc); + if (diff > allowedDiff) { + DebugTrace("ADC check failed: level=%f, adc=%f, diff=%f, allowedDiff=%f", dac, adc, diff, allowedDiff); + return false; + } } return true; @@ -180,7 +180,7 @@ void Value::setData(float dac, float data, float adc) { bool Value::checkMid() { float mid = remap(mid_dac, min_dac, min_val, max_dac, max_val); - float allowedDiff = CALIBRATION_MID_TOLERANCE_PERCENT * (max_val - min_val) / 100.0f; + float allowedDiff = g_channel->params->CALIBRATION_MID_TOLERANCE_PERCENT * (max_val - min_val) / 100.0f; float diff = fabsf(mid - mid_val); if (diff <= allowedDiff) { @@ -348,14 +348,12 @@ bool save() { uint8_t month; uint8_t day; if (datetime::getDate(year, month, day)) { - sprintf(g_channel->cal_conf.calibration_date, "%d%02d%02d", (int)(2000 + year), (int)month, - (int)day); + sprintf(g_channel->cal_conf.calibration_date, "%d%02d%02d", (int)(2000 + year), (int)month, (int)day); } else { strcpy(g_channel->cal_conf.calibration_date, ""); } - memset(&g_channel->cal_conf.calibration_remark, 0, - sizeof(g_channel->cal_conf.calibration_remark)); + memset(&g_channel->cal_conf.calibration_remark, 0, sizeof(g_channel->cal_conf.calibration_remark)); strcpy(g_channel->cal_conf.calibration_remark, g_remark); if (isVoltageCalibrated()) { diff --git a/src/eez/apps/psu/channel.cpp b/src/eez/apps/psu/channel.cpp index 84dfcbad3..fe967bb45 100644 --- a/src/eez/apps/psu/channel.cpp +++ b/src/eez/apps/psu/channel.cpp @@ -72,12 +72,12 @@ static uint16_t CH_BOARD_REVISION_FEATURES[] = { }; static ChannelParams CH_BOARD_REVISION_PARAMS[] = { - // VOLTAGE_GND_OFFSET // CURRENT_GND_OFFSET - { CH_PARAMS_NONE, 0, 0, }, // CH_BOARD_REVISION_NONE - { CH_PARAMS_50V_5A, 1.05f, 0.11f }, // CH_BOARD_REVISION_DCP505_R1B3 - { CH_PARAMS_40V_5A, 0.86f, 0.11f }, // CH_BOARD_REVISION_DCP405_R1B1 - { CH_PARAMS_40V_5A, 0.86f, 0.11f }, // CH_BOARD_REVISION_DCP405_R2B5 - { CH_PARAMS_20V_4A, 0, 0 } // CH_BOARD_REVISION_DCM220_R1B1 + // VOLTAGE_GND_OFFSET // CURRENT_GND_OFFSET // CALIBRATION_DATA_TOLERANCE_PERCENT // CALIBRATION_MID_TOLERANCE_PERCENT + { CH_PARAMS_NONE, 0, 0, 10.0f, 1.0f }, // CH_BOARD_REVISION_NONE + { CH_PARAMS_50V_5A, 1.05f, 0.11f, 10.0f, 1.0f }, // CH_BOARD_REVISION_DCP505_R1B3 + { CH_PARAMS_40V_5A, 0.86f, 0.11f, 10.0f, 1.0f }, // CH_BOARD_REVISION_DCP405_R1B1 + { CH_PARAMS_40V_5A, 0.86f, 0.11f, 10.0f, 1.0f }, // CH_BOARD_REVISION_DCP405_R2B5 + { CH_PARAMS_20V_4A, 0, 0, 15.0f, 2.0f } // CH_BOARD_REVISION_DCM220_R1B1 }; //////////////////////////////////////////////////////////////////////////////// diff --git a/src/eez/apps/psu/channel.h b/src/eez/apps/psu/channel.h index b58160396..6d79f8a8e 100644 --- a/src/eez/apps/psu/channel.h +++ b/src/eez/apps/psu/channel.h @@ -123,8 +123,17 @@ struct ChannelParams { float I_RESOLUTION; float I_LOW_RESOLUTION; float P_RESOLUTION; + float VOLTAGE_GND_OFFSET; // [V], (1375 / 65535) * (40V | 50V) float CURRENT_GND_OFFSET; // [A] + + /// Maximum difference, in percentage, between ADC + /// and real value during calibration. + float CALIBRATION_DATA_TOLERANCE_PERCENT; + + /// Maximum difference, in percentage, between calculated mid value + /// and real mid value during calibration. + float CALIBRATION_MID_TOLERANCE_PERCENT; }; /// PSU channel. diff --git a/src/eez/apps/psu/conf_advanced.h b/src/eez/apps/psu/conf_advanced.h index decff3b26..ceaeb6b97 100644 --- a/src/eez/apps/psu/conf_advanced.h +++ b/src/eez/apps/psu/conf_advanced.h @@ -86,14 +86,6 @@ /// Default calibration remark text. #define CALIBRATION_REMARK_INIT "Not calibrated" -/// Maximum difference, in percentage, between ADC -/// and real value during calibration. -#define CALIBRATION_DATA_TOLERANCE 10.0f - -/// Maximum difference, in percentage, between calculated mid value -/// and real mid value during calibration. -#define CALIBRATION_MID_TOLERANCE_PERCENT 1.0f - /// Temperature reading interval. #define TEMP_SENSOR_READ_EVERY_MS 1000 diff --git a/src/eez/apps/psu/conf_channel.h b/src/eez/apps/psu/conf_channel.h index b26baaacb..4d8a0ae47 100644 --- a/src/eez/apps/psu/conf_channel.h +++ b/src/eez/apps/psu/conf_channel.h @@ -37,7 +37,7 @@ // U_MIN, U_DEF, U_MAX, U_MAX_CONF, U_MIN_STEP, U_DEF_STEP, U_MAX_STEP, U_CAL_VAL_MIN, U_CAL_VAL_MID, U_CAL_VAL_MAX, U_CURR_CAL #define CH_PARAMS_U_40V 0.0f, 0.0f, 40.0f, 40.0f, 0.01f, 0.1f, 5.0f, 0.15f, 20.0f, 38.0f, 20.0f, CH_PARAMS_OVP // U_MIN, U_DEF, U_MAX, U_MAX_CONF, U_MIN_STEP, U_DEF_STEP, U_MAX_STEP, U_CAL_VAL_MIN, U_CAL_VAL_MID, U_CAL_VAL_MAX, U_CURR_CAL -#define CH_PARAMS_U_20V 0.0f, 0.0f, 20.0f, 20.0f, 0.01f, 0.1f, 5.0f, 0.75f, 10.0f, 18.0f, 10.0f, CH_PARAMS_OVP +#define CH_PARAMS_U_20V 0.0f, 0.0f, 20.0f, 20.0f, 0.01f, 0.1f, 5.0f, 0.75f, 10.0f, 18.0f, 20.0f, CH_PARAMS_OVP // OCP_DEFAULT_STATE, OCP_MIN_DELAY, OCP_DEFAULT_DELAY, OCP_MAX_DELAY #define CH_PARAMS_OCP false, 0.0f, 0.02f, 10.0f