Skip to content

Commit

Permalink
dcp405 experimental changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed May 24, 2020
1 parent 9104177 commit 75be83c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
21 changes: 11 additions & 10 deletions src/eez/modules/dcp405/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,17 @@ struct DcpChannel : public Channel {
if (isOutputEnabled()) {
bool belowThreshold = !dac.isOverHwOvpThreshold();

if (value < previousUSet) {
fallingEdge = true;
fallingEdgePreviousUMonAdc = u.mon_adc;
fallingEdgeTimeout = millis() + (belowThreshold ? CONF_FALLING_EDGE_SW_OVP_DELAY_MS : CONF_FALLING_EDGE_HW_OVP_DELAY_MS);
if (isHwOvpEnabled(*this)) {
// deactivate HW OVP
prot_conf.flags.u_hwOvpDeactivated = 0; // this flag should be 0 while fallingEdge is true
ioexp.changeBit(IOExpander::IO_BIT_OUT_OVP_ENABLE, false);
}
} else if (belowThreshold) {
// if (value < previousUSet) {
// fallingEdge = true;
// fallingEdgePreviousUMonAdc = u.mon_adc;
// fallingEdgeTimeout = millis() + (belowThreshold ? CONF_FALLING_EDGE_SW_OVP_DELAY_MS : CONF_FALLING_EDGE_HW_OVP_DELAY_MS);
// if (isHwOvpEnabled(*this)) {
// // deactivate HW OVP
// prot_conf.flags.u_hwOvpDeactivated = 0; // this flag should be 0 while fallingEdge is true
// ioexp.changeBit(IOExpander::IO_BIT_OUT_OVP_ENABLE, false);
// }
// } else
if (belowThreshold) {
if (isHwOvpEnabled(*this)) {
// deactivate HW OVP
prot_conf.flags.u_hwOvpDeactivated = 1;
Expand Down
36 changes: 23 additions & 13 deletions src/eez/modules/dcp405/ioexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ uint8_t IOExpander::getRegValue(int i) {
} else if (reg == REG_GPIOA) {
value = REG_VALUE_GPIOA;
} else if (reg == REG_GPIOB) {
if (slot.moduleRevision >= MODULE_REVISION_DCP405_R3B1) {
value = R3B1_REG_VALUE_GPIOB;
} else {
value = REG_VALUE_GPIOB;
}
// if (slot.moduleRevision >= MODULE_REVISION_DCP405_R3B1) {
// value = R3B1_REG_VALUE_GPIOB;
// } else {
// value = REG_VALUE_GPIOB;
// }
value = REG_VALUE_GPIOB;
} else if (reg == REG_GPINTENA) {
value = REG_VALUE_GPINTENA;
} else if (reg == REG_DEFVALA) {
Expand Down Expand Up @@ -315,11 +316,11 @@ bool IOExpander::testBit(int io_bit) {
auto result = (gpio & (1 << io_bit)) ? true : false;

auto &slot = *g_slots[slotIndex];
if (slot.moduleRevision >= MODULE_REVISION_DCP405_R3B1) {
if (io_bit == IO_BIT_OUT_OVP_ENABLE) {
result = !result;
}
}
// if (slot.moduleRevision >= MODULE_REVISION_DCP405_R3B1) {
// if (io_bit == IO_BIT_OUT_OVP_ENABLE) {
// result = !result;
// }
// }

return result;
}
Expand All @@ -335,12 +336,21 @@ bool IOExpander::isAdcReady() {

void IOExpander::changeBit(int io_bit, bool set) {
auto &slot = *g_slots[slotIndex];
if (slot.moduleRevision >= MODULE_REVISION_DCP405_R3B1) {
if (io_bit == IO_BIT_OUT_OVP_ENABLE) {
set = !set;

if (io_bit == IO_BIT_OUT_OVP_ENABLE) {
if (set) {
write(REG_GPINTENA, REG_VALUE_GPINTENA);
} else {
write(REG_GPINTENA, 0);
}
}

// if (slot.moduleRevision >= MODULE_REVISION_DCP405_R3B1) {
// if (io_bit == IO_BIT_OUT_OVP_ENABLE) {
// set = !set;
// }
// }

#if defined(EEZ_PLATFORM_STM32)
if (io_bit < 8) {
uint8_t oldValue = (uint8_t)gpioWritten;
Expand Down

0 comments on commit 75be83c

Please sign in to comment.