From 58197f484578bc87067b30f9a5fece9cffa8a88d Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Thu, 28 Jan 2021 18:50:55 +0100 Subject: [PATCH] #143 --- src/eez/modules/psu/channel.cpp | 17 ++++++++++++++++- src/eez/modules/psu/gui/psu.cpp | 19 ++++++++----------- src/eez/modules/psu/profile.cpp | 4 ++-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/eez/modules/psu/channel.cpp b/src/eez/modules/psu/channel.cpp index 4d93c2356..c3be3b96d 100644 --- a/src/eez/modules/psu/channel.cpp +++ b/src/eez/modules/psu/channel.cpp @@ -790,16 +790,31 @@ void Channel::updateAllChannels() { } } + bool initiateTrigger = false; + for (int i = 0; i < CH_NUM; ++i) { Channel &channel = Channel::get(i); if (channel.isOk()) { + bool triggerModeEnabled = channel.flags.outputEnabled && + (channel_dispatcher::getVoltageTriggerMode(channel) != TRIGGER_MODE_FIXED || + channel_dispatcher::getCurrentTriggerMode(channel) != TRIGGER_MODE_FIXED) && !channel.isRemoteProgrammingEnabled(); + + if (triggerModeEnabled && trigger::g_triggerSource == trigger::SOURCE_IMMEDIATE) { + initiateTrigger = true; + } + channel.flags.outputEnabledValueOnNextSync = channel.flags.outputEnabled; channel.flags.outputEnabled = !channel.flags.outputEnabled; channel.flags.doOutputEnableOnNextSync = 1; } } - Channel::syncOutputEnable(); + if (initiateTrigger) { + // trigger will call syncOutputEnable + trigger::initiate(); + } else { + Channel::syncOutputEnable(); + } for (int i = 0; i < CH_NUM; ++i) { Channel &channel = Channel::get(i); diff --git a/src/eez/modules/psu/gui/psu.cpp b/src/eez/modules/psu/gui/psu.cpp index e7d7348a9..a1a352684 100644 --- a/src/eez/modules/psu/gui/psu.cpp +++ b/src/eez/modules/psu/gui/psu.cpp @@ -1924,17 +1924,6 @@ void channelReinitiateTrigger() { channelInitiateTrigger(); } -// void clearTrip(int channelIndex) { -// Channel &channel = Channel::get(channelIndex); -// channel_dispatcher::clearProtection(channel); - -// if (temperature::sensors[temp_sensor::AUX].isTripped()) { -// temperature::sensors[temp_sensor::AUX].clearProtection(); -// } - -// channelToggleOutput(); -// } - void doChannelToggleOutput() { Channel &channel = *g_channel; bool triggerModeEnabled = @@ -1977,6 +1966,14 @@ void channelToggleOutput() { Channel &channel = *g_channel; int channelIndex; if (channel_dispatcher::isTripped(channel, channelIndex)) { + // auto clearTrip = [] (int channelIndex) { + // Channel &channel = Channel::get(channelIndex); + // channel_dispatcher::clearProtection(channel); + // if (temperature::sensors[temp_sensor::AUX].isTripped()) { + // temperature::sensors[temp_sensor::AUX].clearProtection(); + // } + // channelToggleOutput(); + // }; if (temperature::sensors[temp_sensor::AUX].isTripped()) { // errorMessageWithAction("AUX temp. sensor is tripped!", clearTrip, "Clear", channelIndex); errorMessage("AUX temp. sensor is tripped!"); diff --git a/src/eez/modules/psu/profile.cpp b/src/eez/modules/psu/profile.cpp index f0e9f5155..ff892e5cd 100644 --- a/src/eez/modules/psu/profile.cpp +++ b/src/eez/modules/psu/profile.cpp @@ -849,12 +849,12 @@ static bool recallState(Parameters &profile, List *lists, int recallOptions, int } } - Channel::updateAllChannels(); - trigger::g_triggerContinuousInitializationEnabled = profile.flags.triggerContinuousInitializationEnabled; trigger::g_triggerSource = (trigger::Source)profile.triggerSource; trigger::g_triggerDelay = profile.triggerDelay; + Channel::updateAllChannels(); + memcpy(io_pins::g_ioPins, profile.ioPins, sizeof(profile.ioPins)); memcpy(io_pins::g_pwmFrequency, profile.ioPinsPwmFrequency, sizeof(profile.ioPinsPwmFrequency)); memcpy(io_pins::g_pwmDuty, profile.ioPinsPwmDuty, sizeof(profile.ioPinsPwmDuty));