Skip to content

Commit

Permalink
fix for hw ovp for dcp405 r2b11 (4ms ramp)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed May 6, 2020
1 parent 59b033f commit 48bc67a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/eez/modules/dcp405/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#define CONF_OVP_SW_OVP_AT_START_U_SET_THRESHOLD 1.2f
#define CONF_OVP_SW_OVP_AT_START_U_PROTECTION_LEVEL 1.55f

#define CONF_OVP_HW_VOLTAGE_THRESHOLD 1.0f

namespace eez {

using namespace psu;
Expand Down Expand Up @@ -328,7 +326,7 @@ struct DcpChannel : public Channel {
// HW OVP handling
if (ioexp.testBit(IOExpander::IO_BIT_OUT_OUTPUT_ENABLE)) {
if (!fallingEdge && isHwOvpEnabled(*this) && !ioexp.testBit(IOExpander::IO_BIT_OUT_OVP_ENABLE)) {
if (u.set > CONF_OVP_HW_VOLTAGE_THRESHOLD) {
if (dac.isOverHwOvpThreshold()) {
// activate HW OVP
prot_conf.flags.u_hwOvpDeactivated = 0;
ioexp.changeBit(IOExpander::IO_BIT_OUT_OVP_ENABLE, true);
Expand Down Expand Up @@ -459,7 +457,7 @@ struct DcpChannel : public Channel {
// OVP
if (tasks & OUTPUT_ENABLE_TASK_OVP) {
if (isHwOvpEnabled(*this)) {
if (u.set > CONF_OVP_HW_VOLTAGE_THRESHOLD) {
if (dac.isOverHwOvpThreshold()) {
// OVP has to be enabled after OE activation
prot_conf.flags.u_hwOvpDeactivated = 0;
ioexp.changeBit(IOExpander::IO_BIT_OUT_OVP_ENABLE, true);
Expand Down Expand Up @@ -579,7 +577,7 @@ struct DcpChannel : public Channel {
uSet = value;

if (isOutputEnabled()) {
bool belowThreshold = u.set <= CONF_OVP_HW_VOLTAGE_THRESHOLD;
bool belowThreshold = !dac.isOverHwOvpThreshold();

if (value < previousUSet) {
fallingEdge = true;
Expand Down
18 changes: 12 additions & 6 deletions src/eez/modules/dcp405/dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,21 @@ void DigitalAnalogConverter::tick(uint32_t tickCount) {
value = m_rampTargetValue;
m_isRampActive = false;
} else {
value = m_rampStartValue + (m_rampTargetValue - m_rampStartValue) * diff / CONF_DCP405_R2B11_RAMP_DURATION;
value = m_rampTargetValue * diff / CONF_DCP405_R2B11_RAMP_DURATION;
}

set(DATA_BUFFER_B, value, FROM_RAMP);
}
#endif
}

bool DigitalAnalogConverter::isOverHwOvpThreshold() {
static const float CONF_OVP_HW_VOLTAGE_THRESHOLD = 1.0f;
Channel &channel = Channel::get(channelIndex);
float u_set = remap(m_rampLastValue, (float)DAC_MIN, channel.params.U_MIN, (float)DAC_MAX, channel.params.U_MAX);
return u_set > channel.getCalibratedVoltage(CONF_OVP_HW_VOLTAGE_THRESHOLD);
}

////////////////////////////////////////////////////////////////////////////////

void DigitalAnalogConverter::setVoltage(float value, RampOption rampOption) {
Expand Down Expand Up @@ -196,14 +203,13 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp
!ramp::isActive(channel)
) {
m_isRampActive = true;
m_rampStartValue = m_rampLastValue;
m_rampTargetValue = value;
m_rampStartTime = micros();
return;
value = 0;
rampOption = FROM_RAMP;
}

m_rampLastValue = value;

m_rampLastValue = value;

if (rampOption != FROM_RAMP) {
m_isRampActive = false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/eez/modules/dcp405/dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ class DigitalAnalogConverter {
return m_testing;
}

bool isOverHwOvpThreshold();

private:
bool m_testing;

// ramp
uint16_t m_rampLastValue;
uint16_t m_rampStartValue = 0;
uint16_t m_rampTargetValue;
uint32_t m_rampStartTime;

Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ void data_channel_protection_ovp_type(DataOperationEnum operation, Cursor cursor
value = page->type ? 0 : 1;
} else {
if (channel.prot_conf.flags.u_type) {
if (channel.isOutputEnabled() && channel.prot_conf.flags.u_hwOvpDeactivated) {
if (channel.prot_conf.flags.u_state && channel.isOutputEnabled() && channel.prot_conf.flags.u_hwOvpDeactivated) {
value = 3;
} else {
value = 0;
Expand Down

0 comments on commit 48bc67a

Please sign in to comment.