Skip to content

Commit

Permalink
trigger on ch3 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Aug 16, 2019
1 parent 7c1c48f commit d85e5b4
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 98 deletions.
10 changes: 5 additions & 5 deletions modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -12005,7 +12005,7 @@
"action": "",
"left": 0,
"top": 0,
"width": 320,
"width": 480,
"height": 28,
"widgets": [
{
Expand All @@ -12020,7 +12020,7 @@
},
"left": 0,
"top": 0,
"width": 320,
"width": 480,
"height": 28
},
{
Expand All @@ -12037,7 +12037,7 @@
"action": "",
"left": 0,
"top": 0,
"width": 320,
"width": 480,
"height": 28,
"focusStyle": {
"inheritFrom": "default",
Expand All @@ -12059,7 +12059,7 @@
"action": "",
"left": 0,
"top": 0,
"width": 320,
"width": 480,
"height": 28,
"focusStyle": {
"inheritFrom": "default",
Expand All @@ -12081,7 +12081,7 @@
"action": "",
"left": 0,
"top": 0,
"width": 320,
"width": 480,
"height": 28,
"focusStyle": {
"inheritFrom": "default",
Expand Down
3 changes: 1 addition & 2 deletions src/eez/apps/psu/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
146 changes: 74 additions & 72 deletions src/eez/apps/psu/channel_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/eez/apps/psu/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/eez/apps/psu/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/eez/apps/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions src/eez/apps/psu/trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -301,15 +305,18 @@ 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();

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);
Expand Down

0 comments on commit d85e5b4

Please sign in to comment.