Skip to content

Commit

Permalink
calibration fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Apr 14, 2020
1 parent f0fd3f9 commit a945439
Show file tree
Hide file tree
Showing 16 changed files with 25,450 additions and 25,460 deletions.
22 changes: 11 additions & 11 deletions modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -5841,7 +5841,7 @@
"top": 0,
"width": 102,
"height": 40,
"text": " Discard"
"text": "\\u009f Discard"
}
]
}
Expand Down Expand Up @@ -6349,7 +6349,7 @@
"top": 0,
"width": 102,
"height": 40,
"text": " Discard"
"text": "\\u009f Discard"
}
]
}
Expand Down Expand Up @@ -47158,7 +47158,7 @@
{
"encoding": 134,
"x": 1,
"y": 0,
"y": -1,
"width": 16,
"height": 17,
"dx": 19,
Expand Down Expand Up @@ -47608,19 +47608,19 @@
{
"encoding": 159,
"x": 0,
"y": -2,
"width": 19,
"height": 19,
"y": -1,
"width": 17,
"height": 17,
"dx": 19,
"glyphBitmap": {
"height": 19,
"pixelArray": "2cc7fbfcfcfcfcfcfcfcfcfcfcfcfcfcfbc72acbffffffffffffffffffffffffffffffffffcaffffde69606060606060606060606069deffffffff690000000000000000000000000068ffffffff6000001f1a00000000001a1e000060ffffffff600020faf64200000040f5fa220060ffffffff60001ef8fff6410040f5fff8210060ffffffff60000048f8fff675f5fff948000060ffffffff6000000048f8fffffff94a00000060ffffffff60000000007dffffff800000000060ffffffff6000000042f6fffffff74400000060ffffffff60000041f6fff984f9fff743000060ffffffff60001af5fff94c004af9fff61d0060ffffffff60001efaf94c00000049f8fb210060ffffffff600000222200000000001e21000060ffffffff680000000000000000000000000068ffffffffdb655c5c5c5c5c5c5c5c5c5c5c65dbffffcdffffffffffffffffffffffffffffffffffcc30ccffffffffffffffffffffffffffffffcb2e",
"width": 19
"width": 17,
"height": 17,
"pixelArray": "40d9fcfcfcfcfcfcfcfcfcfcfcfcfcd940dcffffffffffffffffffffffffffffffdcffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe65ee8ffffffe65de6ffffffffffffffff5a0028e7ffe627005affffffffffffffffe4230028cc270024e4ffffffffffffffffffe22200010024e4ffffffffffffffffffffffc5010001c9ffffffffffffffffffffffe52500010027e6ffffffffffffffffffe6260025c8240027e6ffffffffffffffff590025e4ffe3230059ffffffffffffffffe256e4ffffffe255e2ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffffffffffffffffffffffffffffffde45deffffffffffffffffffffffffffde44"
},
"source": {
"filePath": "fonts\\webhostinghub-glyphs.ttf",
"size": 14,
"encoding": 62225
"size": 12,
"encoding": 62835
}
},
{
Expand Down
38,827 changes: 19,414 additions & 19,413 deletions src/eez/gui/document_simulator.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/eez/gui/document_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1857,4 +1857,4 @@ enum PagesEnum {
PAGE_ID_OVP_TYPE = 166
};

extern const uint8_t assets[413647];
extern const uint8_t assets[413664];
11,897 changes: 5,949 additions & 5,948 deletions src/eez/gui/document_stm32.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/eez/gui/document_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -1810,4 +1810,4 @@ enum PagesEnum {
PAGE_ID_OVP_TYPE = 161
};

extern const uint8_t assets[299706];
extern const uint8_t assets[299722];
4 changes: 3 additions & 1 deletion src/eez/modules/dcm220/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,12 @@ struct Channel : ChannelInterface {
if (crc == *((uint32_t *)(input + BUFFER_SIZE - 4))) {
numCrcErrors = 0;
} else {
if (++numCrcErrors >= 3) {
if (++numCrcErrors >= 4) {
event_queue::pushEvent(event_queue::EVENT_ERROR_SLOT1_CRC_CHECK_ERROR + slotIndex);
synchronized = false;
testResult = TEST_FAILED;
} else {
DebugTrace("CRC %d\n", numCrcErrors);
}
}
}
Expand Down
57 changes: 33 additions & 24 deletions src/eez/modules/psu/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
#include <math.h>
#include <stdio.h>

#include <eez/firmware.h>

#include <eez/modules/psu/calibration.h>
#include <eez/modules/psu/channel_dispatcher.h>
#include <eez/modules/psu/datetime.h>
#include <eez/modules/psu/profile.h>
#include <eez/modules/psu/scpi/psu.h>

namespace eez {
Expand All @@ -39,9 +42,6 @@ static char g_remark[CALIBRATION_REMARK_MAX_LENGTH + 1];

static int8_t g_currentRangeSelected = 0;

static int8_t g_currentRangeSaved;
static CurrentRangeSelectionMode g_currentRangeSelectionModeSaved;

static Value g_voltage(true);
static Value g_currents[] = { Value(false, 0), Value(false, 1) };

Expand Down Expand Up @@ -134,14 +134,14 @@ bool Value::checkRange(float dac, float data, float adc) {

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\n", dac, data, diff, allowedDiff);
return false;
}

if (g_slots[g_channel->slotIndex].moduleInfo->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);
DebugTrace("ADC check failed: level=%f, adc=%f, diff=%f, allowedDiff=%f\n", dac, adc, diff, allowedDiff);
return false;
}
}
Expand Down Expand Up @@ -212,48 +212,59 @@ Channel &getCalibrationChannel() {
return *g_channel;
}

void start(Channel *channel_) {
void start(Channel &channel) {
if (osThreadGetId() != g_psuTaskHandle) {
osMessagePut(g_psuMessageQueueId, PSU_QUEUE_MESSAGE(PSU_QUEUE_MESSAGE_TYPE_CALIBRATION_START, channel.channelIndex), osWaitForever);
return;
}

if (g_enabled)
return;

g_enabled = true;
g_channel = channel_;
profile::saveToLocation(10);
profile::setFreezeState(true);

g_currentRangeSaved = g_channel->flags.currentCurrentRange;
g_currentRangeSelectionModeSaved = g_channel->getCurrentRangeSelectionMode();
selectCurrentRange(0);
reset();

g_remarkSet = false;
g_remark[0] = 0;
g_channel = &channel;

selectCurrentRange(0);

g_voltage.reset();
g_currents[0].reset();
if (hasSupportForCurrentDualRange()) {
g_currents[1].reset();
}
g_voltage.reset();
g_remarkSet = false;
g_remark[0] = 0;

g_enabled = true;
g_channel->calibrationEnable(false);
resetChannelToZero();

channel_dispatcher::outputEnable(*g_channel, true);

g_channel->setOperBits(OPER_ISUM_CALI, true);
}

void stop() {
if (osThreadGetId() != g_psuTaskHandle) {
osMessagePut(g_psuMessageQueueId, PSU_QUEUE_MESSAGE(PSU_QUEUE_MESSAGE_TYPE_CALIBRATION_STOP, 0), osWaitForever);
return;
}

if (!g_enabled)
return;

g_enabled = false;

g_channel->setOperBits(OPER_ISUM_CALI, false);

profile::recallFromLocation(10);
profile::setFreezeState(false);

if (g_channel->isCalibrationExists()) {
g_channel->calibrationEnable(true);
}

g_channel->setCurrentRange(g_currentRangeSaved);
g_channel->setCurrentRangeSelectionMode(g_currentRangeSelectionModeSaved);

resetChannelToZero();

g_channel->setOperBits(OPER_ISUM_CALI, false);
}

bool hasSupportForCurrentDualRange() {
Expand Down Expand Up @@ -451,8 +462,6 @@ bool save() {
}
}

resetChannelToZero();

// TODO move this to scpi thread
return persist_conf::saveChannelCalibration(*g_channel);
}
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Channel &getCalibrationChannel();

/// Start calibration procedure on the channel.
/// /param channel Selected channel
void start(Channel *channel);
void start(Channel &channel);

/// Stop calibration procedure.
void stop();
Expand Down
35 changes: 13 additions & 22 deletions src/eez/modules/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@ int Channel::reg_get_ques_isum_bit_mask_for_channel_protection_value(ProtectionV
}

void Channel::protectionEnter(ProtectionValue &cpv) {
if (IS_OVP_VALUE(this, cpv)) {
if (flags.rprogEnabled) {
DebugTrace("OVP condition: %f (I_MON_DAC) > %f (OVP level)\n", channel_dispatcher::getUMonDacLast(*this), channel_dispatcher::getUProtectionLevel(*this));
} else {
DebugTrace("OVP condition: %f (I_MON) > %f (OVP level)\n", channel_dispatcher::getUMonLast(*this), channel_dispatcher::getUProtectionLevel(*this));
}
} else if (IS_OCP_VALUE(this, cpv)) {
DebugTrace("OCP condition: %f (I_MON) > %f (I_SET)\n", channel_dispatcher::getIMonLast(*this), channel_dispatcher::getISet(*this));
} else if (IS_OPP_VALUE(this, cpv)) {
DebugTrace("OPP condition: %f (U_MON) * %f (I_MON) > %f (OPP level)\n", channel_dispatcher::getUMonLast(*this), channel_dispatcher::getIMonLast(*this), channel_dispatcher::getPowerProtectionLevel(*this));
}

if (getVoltageTriggerMode() != TRIGGER_MODE_FIXED) {
trigger::abort();
}
Expand Down Expand Up @@ -504,34 +516,13 @@ void Channel::protectionCheck(ProtectionValue &cpv) {
if (cpv.flags.alarmed) {
if (micros() - cpv.alarm_started >= delay * 1000000UL) {
cpv.flags.alarmed = 0;

// if (IS_OVP_VALUE(this, cpv)) {
// DebugTrace("OVP condition: CV_MODE=%d, CC_MODE=%d, I DIFF=%d mA, I MON=%d
// mA", (int)flags.cvMode, (int)flags.ccMode, (int)(fabs(i.mon_last - i.set)
// * 1000), (int)(i.mon_last * 1000));
//}
// else if (IS_OCP_VALUE(this, cpv)) {
// DebugTrace("OCP condition: CC_MODE=%d, CV_MODE=%d, U DIFF=%d mV",
// (int)flags.ccMode, (int)flags.cvMode, (int)(fabs(u.mon_last - u.set) *
// 1000));
//}

protectionEnter(cpv);
}
} else {
cpv.flags.alarmed = 1;
cpv.alarm_started = micros();
}
} else {
// if (IS_OVP_VALUE(this, cpv)) {
// DebugTrace("OVP condition: CV_MODE=%d, CC_MODE=%d, I DIFF=%d mA",
// (int)flags.cvMode, (int)flags.ccMode, (int)(fabs(i.mon_last - i.set) * 1000));
//}
// else if (IS_OCP_VALUE(this, cpv)) {
// DebugTrace("OCP condition: CC_MODE=%d, CV_MODE=%d, U DIFF=%d mV",
// (int)flags.ccMode, (int)flags.cvMode, (int)(fabs(u.mon_last - u.set) * 1000));
//}

protectionEnter(cpv);
}
} else {
Expand Down Expand Up @@ -833,7 +824,7 @@ float Channel::getCurrentResolution(float value) const {
float precision = params.I_RESOLUTION; // 0.5mA

if (hasSupportForCurrentDualRange()) {
if ((!isNaN(value) && value <= 0.05f && isMicroAmperAllowed()) || flags.currentCurrentRange == CURRENT_RANGE_LOW) {
if (!isNaN(value) && value <= 0.05f && isMicroAmperAllowed()) {
precision = params.I_LOW_RESOLUTION; // 5uA
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/eez/modules/psu/channel_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1993,14 +1993,8 @@ bool isEditEnabled(const WidgetCursor &widgetCursor) {
return false;
}

if (channel.isOutputEnabled()) {
if (trigger::isActive()) {
return false;
}
} else {
if (getVoltageTriggerMode(channel) != TRIGGER_MODE_FIXED || getCurrentTriggerMode(channel) != TRIGGER_MODE_FIXED) {
return false;
}
if (getVoltageTriggerMode(channel) != TRIGGER_MODE_FIXED || getCurrentTriggerMode(channel) != TRIGGER_MODE_FIXED) {
return false;
}
}

Expand Down
15 changes: 2 additions & 13 deletions src/eez/modules/psu/gui/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,9 @@ void showCurrentStep();
void onStartPasswordOk() {
popPage();

channel_dispatcher::outputEnable(*g_channel, false);

g_channel->clearProtection();
g_channel->prot_conf.flags.u_state = 0;
g_channel->prot_conf.flags.i_state = 0;
g_channel->prot_conf.flags.p_state = 0;

g_channel->remoteProgrammingEnable(false);

channel_dispatcher::outputEnable(*g_channel, true);

trigger::abort();
calibration::start(*g_channel);

calibration::start(g_channel);
osDelay(1);

g_stepNum = 0;
showCurrentStep();
Expand Down
25 changes: 12 additions & 13 deletions src/eez/modules/psu/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <eez/scpi/scpi.h>

#include <eez/modules/psu/psu.h>
#include <eez/modules/psu/calibration.h>
#include <eez/modules/psu/channel_dispatcher.h>
#include <eez/modules/psu/datetime.h>
#include <eez/modules/psu/event_queue.h>
Expand Down Expand Up @@ -723,14 +722,17 @@ static bool recallState(Parameters &profile, List *lists, int recallOptions, int
Channel &channel = Channel::get(i);

if (profile.channels[i].flags.parameters_are_valid) {
channel.u.set = MIN(profile.channels[i].u_set, channel.u.max);
channel.u.step = profile.channels[i].u_step;
channel.u.limit = MIN(profile.channels[i].u_limit, channel.u.max);
channel.flags.currentRangeSelectionMode = profile.channels[i].flags.currentRangeSelectionMode;
channel.flags.autoSelectCurrentRange = profile.channels[i].flags.autoSelectCurrentRange;

channel.u.set = channel.roundChannelValue(UNIT_VOLT, MIN(profile.channels[i].u_set, channel.u.max));
channel.u.step = channel.roundChannelValue(UNIT_VOLT, profile.channels[i].u_step);
channel.u.limit = channel.roundChannelValue(UNIT_VOLT, MIN(profile.channels[i].u_limit, channel.u.max));

channel.i.set = MIN(profile.channels[i].i_set, channel.i.max);
channel.i.step = profile.channels[i].i_step;
channel.i.set = channel.roundChannelValue(UNIT_AMPER, MIN(profile.channels[i].i_set, channel.i.max));
channel.i.step = channel.roundChannelValue(UNIT_AMPER, profile.channels[i].i_step);

channel.p_limit = MIN(profile.channels[i].p_limit, channel.u.max * channel.i.max);
channel.p_limit = channel.roundChannelValue(UNIT_WATT, MIN(profile.channels[i].p_limit, channel.u.max * channel.i.max));

channel.prot_conf.u_delay = profile.channels[i].u_delay;
channel.prot_conf.u_level = profile.channels[i].u_level;
Expand Down Expand Up @@ -775,13 +777,10 @@ static bool recallState(Parameters &profile, List *lists, int recallOptions, int
channel.flags.currentTriggerMode = (TriggerMode)profile.channels[i].flags.i_triggerMode;
channel.flags.triggerOutputState = profile.channels[i].flags.triggerOutputState;
channel.flags.triggerOnListStop = profile.channels[i].flags.triggerOnListStop;
channel.u.triggerLevel = profile.channels[i].u_triggerValue;
channel.i.triggerLevel = profile.channels[i].i_triggerValue;
channel.u.triggerLevel = channel.roundChannelValue(UNIT_VOLT, profile.channels[i].u_triggerValue);
channel.i.triggerLevel = channel.roundChannelValue(UNIT_AMPER, profile.channels[i].i_triggerValue);
list::setListCount(channel, profile.channels[i].listCount);

channel.flags.currentRangeSelectionMode = profile.channels[i].flags.currentRangeSelectionMode;
channel.flags.autoSelectCurrentRange = profile.channels[i].flags.autoSelectCurrentRange;

channel.flags.dprogState = profile.channels[i].flags.dprogState;

channel.flags.trackingEnabled = profile.channels[i].flags.trackingEnabled;
Expand Down Expand Up @@ -1531,7 +1530,7 @@ static bool doRecallFromLastLocation(int *err) {
////////////////////////////////////////////////////////////////////////////////

static bool isTickSaveAllowed() {
return !trigger::isActive() && !calibration::isEnabled();
return !trigger::isActive();
}

static bool isAutoSaveAllowed() {
Expand Down
6 changes: 4 additions & 2 deletions src/eez/modules/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ void oneIter() {
channel_dispatcher::setVoltageInPsuThread((int)param);
} else if (type == PSU_QUEUE_MESSAGE_TYPE_SET_CURRENT) {
channel_dispatcher::setCurrentInPsuThread((int)param);
} else if (type == PSU_QUEUE_RESET_CHANNELS_HISTORY) {
Channel::resetHistoryForAllChannels();
} else if (type == PSU_QUEUE_MESSAGE_TYPE_CALIBRATION_START) {
calibration::start(Channel::get((int)param));
} else if (type == PSU_QUEUE_MESSAGE_TYPE_CALIBRATION_STOP) {
calibration::stop();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/eez/modules/psu/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ enum {
PSU_QUEUE_MESSAGE_TYPE_SET_VOLTAGE,
PSU_QUEUE_MESSAGE_TYPE_SET_CURRENT,
PSU_QUEUE_RESET_CHANNELS_HISTORY,
PSU_QUEUE_MESSAGE_TYPE_CALIBRATION_START,
PSU_QUEUE_MESSAGE_TYPE_CALIBRATION_STOP,
};

#define PSU_QUEUE_MESSAGE(type, param) (((param) << 8) | (type))
Expand Down
Loading

0 comments on commit a945439

Please sign in to comment.