From d85e5b4bc72ee2b6b9a1f0e52f331d32b8d1e4af Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Fri, 16 Aug 2019 12:00:06 +0200 Subject: [PATCH] trigger on ch3 fixed --- modular-psu-firmware.eez-project | 10 +- src/eez/apps/psu/channel.h | 3 +- src/eez/apps/psu/channel_dispatcher.cpp | 146 ++++++++++++------------ src/eez/apps/psu/debug.cpp | 14 +-- src/eez/apps/psu/debug.h | 12 +- src/eez/apps/psu/gui/psu.cpp | 8 +- src/eez/apps/psu/trigger.cpp | 11 +- 7 files changed, 106 insertions(+), 98 deletions(-) diff --git a/modular-psu-firmware.eez-project b/modular-psu-firmware.eez-project index 6494dff92..7edff8c7c 100644 --- a/modular-psu-firmware.eez-project +++ b/modular-psu-firmware.eez-project @@ -12005,7 +12005,7 @@ "action": "", "left": 0, "top": 0, - "width": 320, + "width": 480, "height": 28, "widgets": [ { @@ -12020,7 +12020,7 @@ }, "left": 0, "top": 0, - "width": 320, + "width": 480, "height": 28 }, { @@ -12037,7 +12037,7 @@ "action": "", "left": 0, "top": 0, - "width": 320, + "width": 480, "height": 28, "focusStyle": { "inheritFrom": "default", @@ -12059,7 +12059,7 @@ "action": "", "left": 0, "top": 0, - "width": 320, + "width": 480, "height": 28, "focusStyle": { "inheritFrom": "default", @@ -12081,7 +12081,7 @@ "action": "", "left": 0, "top": 0, - "width": 320, + "width": 480, "height": 28, "focusStyle": { "inheritFrom": "default", diff --git a/src/eez/apps/psu/channel.h b/src/eez/apps/psu/channel.h index 54f50b6b5..1520213c5 100644 --- a/src/eez/apps/psu/channel.h +++ b/src/eez/apps/psu/channel.h @@ -405,7 +405,6 @@ class Channel { /// @param gpio State of IO expander GPIO register. /// @param adc_data ADC snapshot data. void eventAdcData(int16_t adc_data, bool startAgain = true); - void eventGpio(uint8_t gpio); /// Called when device power is turned off, so channel /// can do its own housekeeping. @@ -666,7 +665,7 @@ class Channel { void doDpEnable(bool enable); #if !CONF_SKIP_PWRGOOD_TEST - void testPwrgood(uint8_t gpio); + void testPwrgood(); #endif float getDualRangeGndOffset(); diff --git a/src/eez/apps/psu/channel_dispatcher.cpp b/src/eez/apps/psu/channel_dispatcher.cpp index 36d72aa86..24adc5f2d 100644 --- a/src/eez/apps/psu/channel_dispatcher.cpp +++ b/src/eez/apps/psu/channel_dispatcher.cpp @@ -59,7 +59,7 @@ bool setType(Type value) { g_channelCoupling = value; - for (int i = 0; i < 2; ++i) { + for (int i = 0; i < CH_MAX; ++i) { if (i < CH_NUM) { Channel &channel = Channel::get(i); if (Channel::get(i).isOk()) { @@ -77,81 +77,83 @@ bool setType(Type value) { list::resetChannelList(channel); - if (isTracked()) { - channel.setVoltageLimit(MIN(Channel::get(0).getVoltageLimit(), - Channel::get(1).getVoltageLimit())); - if (i != 0) { - channel.setVoltage(Channel::get(0).u.set); - } - - channel.setCurrentLimit(MIN(Channel::get(0).getCurrentLimit(), - Channel::get(1).getCurrentLimit())); - if (i != 0) { - channel.setCurrent(Channel::get(0).i.set); - } - - trigger::setVoltage(channel, Channel::get(0).u.def); - trigger::setCurrent(channel, Channel::get(0).i.def); - } else if (isCoupled()) { - channel.setVoltage(getUMin(channel)); - channel.setVoltageLimit(MIN(Channel::get(0).getVoltageLimit(), - Channel::get(1).getVoltageLimit())); - - channel.setCurrent(getIMin(channel)); - channel.setCurrentLimit(MIN(Channel::get(0).getCurrentLimit(), - Channel::get(1).getCurrentLimit())); - - trigger::setVoltage(channel, getUMin(channel)); - trigger::setCurrent(channel, getIMin(channel)); + if (i < 2) { + if (isTracked()) { + channel.setVoltageLimit(MIN(Channel::get(0).getVoltageLimit(), + Channel::get(1).getVoltageLimit())); + if (i != 0) { + channel.setVoltage(Channel::get(0).u.set); + } + + channel.setCurrentLimit(MIN(Channel::get(0).getCurrentLimit(), + Channel::get(1).getCurrentLimit())); + if (i != 0) { + channel.setCurrent(Channel::get(0).i.set); + } + + trigger::setVoltage(channel, Channel::get(0).u.def); + trigger::setCurrent(channel, Channel::get(0).i.def); + } else if (isCoupled()) { + channel.setVoltage(getUMin(channel)); + channel.setVoltageLimit(MIN(Channel::get(0).getVoltageLimit(), + Channel::get(1).getVoltageLimit())); + + channel.setCurrent(getIMin(channel)); + channel.setCurrentLimit(MIN(Channel::get(0).getCurrentLimit(), + Channel::get(1).getCurrentLimit())); + + trigger::setVoltage(channel, getUMin(channel)); + trigger::setCurrent(channel, getIMin(channel)); #ifdef EEZ_PLATFORM_SIMULATOR - channel.simulator.setLoadEnabled(false); - channel.simulator.setLoad(Channel::get(0).simulator.getLoad()); + channel.simulator.setLoadEnabled(false); + channel.simulator.setLoad(Channel::get(0).simulator.getLoad()); #endif - } + } - if (isTracked() || isCoupled()) { - channel.prot_conf.flags.u_state = - Channel::get(0).prot_conf.flags.u_state || - Channel::get(1).prot_conf.flags.u_state - ? 1 - : 0; - channel.prot_conf.u_level = MIN(Channel::get(0).prot_conf.u_level, - Channel::get(1).prot_conf.u_level); - channel.prot_conf.u_delay = MIN(Channel::get(0).prot_conf.u_delay, - Channel::get(1).prot_conf.u_delay); - - channel.prot_conf.flags.i_state = - Channel::get(0).prot_conf.flags.i_state || - Channel::get(1).prot_conf.flags.i_state - ? 1 - : 0; - channel.prot_conf.i_delay = MIN(Channel::get(0).prot_conf.i_delay, - Channel::get(1).prot_conf.i_delay); - - channel.prot_conf.flags.p_state = - Channel::get(0).prot_conf.flags.p_state || - Channel::get(1).prot_conf.flags.p_state - ? 1 - : 0; - channel.prot_conf.p_level = MIN(Channel::get(0).prot_conf.p_level, - Channel::get(1).prot_conf.p_level); - channel.prot_conf.p_delay = MIN(Channel::get(0).prot_conf.p_delay, - Channel::get(1).prot_conf.p_delay); - - temperature::sensors[temp_sensor::CH1 + channel.slotIndex].prot_conf.state = - temperature::sensors[temp_sensor::CH1].prot_conf.state || - temperature::sensors[temp_sensor::CH2].prot_conf.state - ? 1 - : 0; - - temperature::sensors[temp_sensor::CH1 + channel.slotIndex].prot_conf.level = - MIN(temperature::sensors[temp_sensor::CH1].prot_conf.level, - temperature::sensors[temp_sensor::CH2].prot_conf.level); - - temperature::sensors[temp_sensor::CH1 + channel.slotIndex].prot_conf.delay = - MIN(temperature::sensors[temp_sensor::CH1].prot_conf.delay, - temperature::sensors[temp_sensor::CH2].prot_conf.delay); + if (isTracked() || isCoupled()) { + channel.prot_conf.flags.u_state = + Channel::get(0).prot_conf.flags.u_state || + Channel::get(1).prot_conf.flags.u_state + ? 1 + : 0; + channel.prot_conf.u_level = MIN(Channel::get(0).prot_conf.u_level, + Channel::get(1).prot_conf.u_level); + channel.prot_conf.u_delay = MIN(Channel::get(0).prot_conf.u_delay, + Channel::get(1).prot_conf.u_delay); + + channel.prot_conf.flags.i_state = + Channel::get(0).prot_conf.flags.i_state || + Channel::get(1).prot_conf.flags.i_state + ? 1 + : 0; + channel.prot_conf.i_delay = MIN(Channel::get(0).prot_conf.i_delay, + Channel::get(1).prot_conf.i_delay); + + channel.prot_conf.flags.p_state = + Channel::get(0).prot_conf.flags.p_state || + Channel::get(1).prot_conf.flags.p_state + ? 1 + : 0; + channel.prot_conf.p_level = MIN(Channel::get(0).prot_conf.p_level, + Channel::get(1).prot_conf.p_level); + channel.prot_conf.p_delay = MIN(Channel::get(0).prot_conf.p_delay, + Channel::get(1).prot_conf.p_delay); + + temperature::sensors[temp_sensor::CH1 + channel.slotIndex].prot_conf.state = + temperature::sensors[temp_sensor::CH1].prot_conf.state || + temperature::sensors[temp_sensor::CH2].prot_conf.state + ? 1 + : 0; + + temperature::sensors[temp_sensor::CH1 + channel.slotIndex].prot_conf.level = + MIN(temperature::sensors[temp_sensor::CH1].prot_conf.level, + temperature::sensors[temp_sensor::CH2].prot_conf.level); + + temperature::sensors[temp_sensor::CH1 + channel.slotIndex].prot_conf.delay = + MIN(temperature::sensors[temp_sensor::CH1].prot_conf.delay, + temperature::sensors[temp_sensor::CH2].prot_conf.delay); + } } } diff --git a/src/eez/apps/psu/debug.cpp b/src/eez/apps/psu/debug.cpp index a845a5b06..3d02212e8 100644 --- a/src/eez/apps/psu/debug.cpp +++ b/src/eez/apps/psu/debug.cpp @@ -43,14 +43,12 @@ namespace eez { namespace psu { namespace debug { -DebugValueVariable g_uDac[2] = { DebugValueVariable("CH1 U_DAC"), DebugValueVariable("CH2 U_DAC") }; -DebugValueVariable g_uMon[2] = { DebugValueVariable("CH1 U_MON"), DebugValueVariable("CH2 U_MON") }; -DebugValueVariable g_uMonDac[2] = { DebugValueVariable("CH1 U_MON_DAC"), - DebugValueVariable("CH2 U_MON_DAC") }; -DebugValueVariable g_iDac[2] = { DebugValueVariable("CH1 I_DAC"), DebugValueVariable("CH2 I_DAC") }; -DebugValueVariable g_iMon[2] = { DebugValueVariable("CH1 I_MON"), DebugValueVariable("CH2 I_MON") }; -DebugValueVariable g_iMonDac[2] = { DebugValueVariable("CH1 I_MON_DAC"), - DebugValueVariable("CH2 I_MON_DAC") }; +DebugValueVariable g_uDac[CH_MAX] = { DebugValueVariable("CH1 U_DAC"), DebugValueVariable("CH2 U_DAC"), DebugValueVariable("CH3 U_DAC") }; +DebugValueVariable g_uMon[CH_MAX] = { DebugValueVariable("CH1 U_MON"), DebugValueVariable("CH2 U_MON"), DebugValueVariable("CH3 U_MON") }; +DebugValueVariable g_uMonDac[CH_MAX] = { DebugValueVariable("CH1 U_MON_DAC"), DebugValueVariable("CH2 U_MON_DAC"), DebugValueVariable("CH3 U_MON_DAC") }; +DebugValueVariable g_iDac[CH_MAX] = { DebugValueVariable("CH1 I_DAC"), DebugValueVariable("CH2 I_DAC"), DebugValueVariable("CH3 I_DAC") }; +DebugValueVariable g_iMon[CH_MAX] = { DebugValueVariable("CH1 I_MON"), DebugValueVariable("CH2 I_MON"), DebugValueVariable("CH3 I_MON") }; +DebugValueVariable g_iMonDac[CH_MAX] = { DebugValueVariable("CH1 I_MON_DAC"), DebugValueVariable("CH2 I_MON_DAC"), DebugValueVariable("CH3 I_MON_DAC") }; DebugDurationVariable g_mainLoopDuration("MAIN_LOOP_DURATION"); #if CONF_DEBUG_VARIABLES diff --git a/src/eez/apps/psu/debug.h b/src/eez/apps/psu/debug.h index 4e5d056d9..769ef940c 100644 --- a/src/eez/apps/psu/debug.h +++ b/src/eez/apps/psu/debug.h @@ -34,12 +34,12 @@ namespace debug { void tick(uint32_t tickCount); -extern DebugValueVariable g_uDac[2]; -extern DebugValueVariable g_uMon[2]; -extern DebugValueVariable g_uMonDac[2]; -extern DebugValueVariable g_iDac[2]; -extern DebugValueVariable g_iMon[2]; -extern DebugValueVariable g_iMonDac[2]; +extern DebugValueVariable g_uDac[CH_MAX]; +extern DebugValueVariable g_uMon[CH_MAX]; +extern DebugValueVariable g_uMonDac[CH_MAX]; +extern DebugValueVariable g_iDac[CH_MAX]; +extern DebugValueVariable g_iMon[CH_MAX]; +extern DebugValueVariable g_iMonDac[CH_MAX]; extern DebugDurationVariable g_mainLoopDuration; #if CONF_DEBUG_VARIABLES diff --git a/src/eez/apps/psu/gui/psu.cpp b/src/eez/apps/psu/gui/psu.cpp index ce5401923..637853ee9 100644 --- a/src/eez/apps/psu/gui/psu.cpp +++ b/src/eez/apps/psu/gui/psu.cpp @@ -775,9 +775,11 @@ void channelToggleOutput() { trigger::abort(); for (int i = 0; i < CH_NUM; ++i) { Channel &channel = Channel::get(i); - if (channel_dispatcher::getVoltageTriggerMode(channel) != TRIGGER_MODE_FIXED || - channel_dispatcher::getCurrentTriggerMode(channel) != TRIGGER_MODE_FIXED) { - channel_dispatcher::outputEnable(Channel::get(i), false); + if (channel.isOk()) { + if (channel_dispatcher::getVoltageTriggerMode(channel) != TRIGGER_MODE_FIXED || + channel_dispatcher::getCurrentTriggerMode(channel) != TRIGGER_MODE_FIXED) { + channel_dispatcher::outputEnable(Channel::get(i), false); + } } } } else { diff --git a/src/eez/apps/psu/trigger.cpp b/src/eez/apps/psu/trigger.cpp index adf5d5c05..f0a593817 100644 --- a/src/eez/apps/psu/trigger.cpp +++ b/src/eez/apps/psu/trigger.cpp @@ -244,6 +244,10 @@ int checkTrigger() { for (int i = 0; i < CH_NUM; ++i) { Channel &channel = Channel::get(i); + if (!channel.isOk()) { + continue; + } + if (i == 0 || !(channel_dispatcher::isCoupled() || channel_dispatcher::isTracked())) { if (channel.getVoltageTriggerMode() != channel.getCurrentTriggerMode()) { return SCPI_ERROR_INCOMPATIBLE_TRANSIENT_MODES; @@ -301,7 +305,10 @@ int startImmediately() { setState(STATE_EXECUTING); for (int i = 0; i < CH_NUM; ++i) { - g_triggerInProgress[i] = true; + Channel &channel = Channel::get(i); + if (channel.isOk()) { + g_triggerInProgress[i] = true; + } } io_pins::onTrigger(); @@ -309,7 +316,7 @@ int startImmediately() { for (int i = 0; i < CH_NUM; ++i) { Channel &channel = Channel::get(i); - if (i == 0 || !(channel_dispatcher::isCoupled() || channel_dispatcher::isTracked())) { + if (channel.isOk() && (i == 0 || !(channel_dispatcher::isCoupled() || channel_dispatcher::isTracked()))) { if (channel.getVoltageTriggerMode() == TRIGGER_MODE_LIST) { channel_dispatcher::setVoltage(channel, 0); channel_dispatcher::setCurrent(channel, 0);