Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 7, 2021
1 parent 5c1ce88 commit 996440b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 27 deletions.
78 changes: 51 additions & 27 deletions src/eez/function_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ float g_offsetI[CH_MAX];
float g_dutyCycleI[CH_MAX];

bool g_dprogStateModified[CH_MAX];
bool g_currentRangeModified[CH_MAX];

static const float PERIOD = 0.0002f;

Expand Down Expand Up @@ -291,6 +292,30 @@ WaveformFunction getWaveformFunction(WaveformParameters &waveformParameters) {
}
}

float getMin(WaveformParameters &waveformParameters) {
if (waveformParameters.waveform == WAVEFORM_DC) {
return waveformParameters.amplitude;
}

if (waveformParameters.waveform == WAVEFORM_HALF_RECTIFIED || waveformParameters.waveform == WAVEFORM_FULL_RECTIFIED) {
return waveformParameters.offset;
}

return waveformParameters.offset - waveformParameters.amplitude / 2.0f;
}

float getMax(WaveformParameters &waveformParameters) {
if (waveformParameters.waveform == WAVEFORM_DC) {
return waveformParameters.amplitude;
}

if (waveformParameters.waveform == WAVEFORM_HALF_RECTIFIED || waveformParameters.waveform == WAVEFORM_FULL_RECTIFIED) {
return waveformParameters.offset + waveformParameters.amplitude;
}

return waveformParameters.offset + waveformParameters.amplitude / 2.0f;
}

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

class FunctionGeneratorPage : public SetPage {
Expand Down Expand Up @@ -560,17 +585,8 @@ class FunctionGeneratorPage : public SetPage {
int yPrev1 = 0;
int yPrev2 = 0;

float ytMin;
float ytMax;
if (waveformParameters.waveform == WAVEFORM_DC) {
ytMin = ytMax = waveformParameters.amplitude;
} else if (waveformParameters.waveform == WAVEFORM_DC || waveformParameters.waveform == WAVEFORM_DC) {
ytMin = waveformParameters.offset;
ytMax = waveformParameters.amplitude;
} else {
ytMin = waveformParameters.offset - waveformParameters.amplitude / 2.0f;
ytMax = waveformParameters.offset + waveformParameters.amplitude / 2.0f;
}
float ytMin = getMin(waveformParameters);
float ytMax = getMax(waveformParameters);

for (int xOffset = 0; xOffset < widget->w; xOffset++) {
float t1 = xOffset * T / widget->w;
Expand Down Expand Up @@ -1667,18 +1683,6 @@ bool isActive() {
return g_active;
}

float getMax(WaveformParameters &waveformParameters) {
if (waveformParameters.waveform == WAVEFORM_DC) {
return waveformParameters.amplitude;
}

if (waveformParameters.waveform == WAVEFORM_HALF_RECTIFIED || waveformParameters.waveform == WAVEFORM_FULL_RECTIFIED) {
return waveformParameters.offset + waveformParameters.amplitude;
}

return waveformParameters.offset + waveformParameters.amplitude / 2.0f;
}

int checkLimits(int iChannel) {
Channel &channel = Channel::get(iChannel);

Expand Down Expand Up @@ -1717,6 +1721,7 @@ int checkLimits(int iChannel) {
void executionStart() {
for (int i = 0; i < CH_NUM; i++) {
g_dprogStateModified[i] = false;
g_currentRangeModified[i] = false;
}

for (int i = 0; i < g_selectedResources.m_numResources; i++) {
Expand Down Expand Up @@ -1824,6 +1829,19 @@ void reloadWaveformParameters() {
g_amplitudeI[channel->channelIndex] = waveformParameters.amplitude;
g_offsetI[channel->channelIndex] = waveformParameters.offset;
}

if (g_slots[slotIndex]->moduleType == MODULE_TYPE_DCP405) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel->getCurrentRangeSelectionMode() == CURRENT_RANGE_SELECTION_USE_BOTH) {
float max = getMax(waveformParameters);
if (max > 0.05f) {
channel_dispatcher::setCurrentRangeSelectionMode(*channel, CURRENT_RANGE_SELECTION_ALWAYS_HIGH);
} else {
channel_dispatcher::setCurrentRangeSelectionMode(*channel, CURRENT_RANGE_SELECTION_ALWAYS_LOW);
}
g_currentRangeModified[i] = true;
}
}
}
#if defined(EEZ_PLATFORM_STM32)
__enable_irq();
Expand Down Expand Up @@ -1932,11 +1950,17 @@ void tick() {
}

void abort() {
g_active = false;
if (g_active) {
g_active = false;

for (int i = 0; i < CH_NUM; i++) {
if (g_dprogStateModified[i]) {
Channel::get(i).setDprogState(DPROG_STATE_ON);
for (int i = 0; i < CH_NUM; i++) {
if (g_dprogStateModified[i]) {
Channel::get(i).setDprogState(DPROG_STATE_ON);
}

if (g_currentRangeModified[i]) {
channel_dispatcher::setCurrentRangeSelectionMode(Channel::get(i), CURRENT_RANGE_SELECTION_USE_BOTH);
}
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions src/eez/modules/psu/list_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static struct {

static bool g_active;

bool g_currentRangeModified[CH_MAX];

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

void init() {
Expand Down Expand Up @@ -511,6 +513,14 @@ void updateChannelsWithVisibleCountersList();

void setActive(bool active, bool forceUpdate = false) {
if (g_active != active) {
if (g_active) {
for (int i = 0; i < CH_NUM; i++) {
if (g_currentRangeModified[i]) {
channel_dispatcher::setCurrentRangeSelectionMode(Channel::get(i), CURRENT_RANGE_SELECTION_USE_BOTH);
}
}
}

g_active = active;
updateChannelsWithVisibleCountersList();
} else {
Expand All @@ -523,8 +533,34 @@ void setActive(bool active, bool forceUpdate = false) {
void executionStart(Channel &channel) {
g_execution[channel.channelIndex].it = -1;
g_execution[channel.channelIndex].counter = g_channelsLists[channel.channelIndex].count;

channel_dispatcher::setVoltage(channel, 0);

g_currentRangeModified[channel.channelIndex] = false;
if (g_slots[channel.slotIndex]->moduleType == MODULE_TYPE_DCP405) {
if (channel.getCurrentRangeSelectionMode() == CURRENT_RANGE_SELECTION_USE_BOTH) {
float max = 0.0f;

uint16_t currentListLength = g_channelsLists[channel.channelIndex].currentListLength;
for (int j = 0; j < currentListLength; ++j) {
float current = g_channelsLists[channel.channelIndex].currentList[j];
if (j == 0 || current > max) {
max = current;
}
}

if (max > 0.05f) {
channel_dispatcher::setCurrentRangeSelectionMode(channel, CURRENT_RANGE_SELECTION_ALWAYS_HIGH);
} else {
channel_dispatcher::setCurrentRangeSelectionMode(channel, CURRENT_RANGE_SELECTION_ALWAYS_LOW);
}

g_currentRangeModified[channel.channelIndex] = true;
}
}

channel_dispatcher::setCurrent(channel, 0);

setActive(true, true);
}

Expand Down

0 comments on commit 996440b

Please sign in to comment.