Skip to content

Commit

Permalink
dcm220 calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 23, 2019
1 parent 1cc93da commit 65a27a6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
24 changes: 11 additions & 13 deletions src/eez/apps/psu/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down
12 changes: 6 additions & 6 deletions src/eez/apps/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 9 additions & 0 deletions src/eez/apps/psu/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions src/eez/apps/psu/conf_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/eez/apps/psu/conf_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 65a27a6

Please sign in to comment.