Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 26, 2021
1 parent da71ef1 commit 8583eef
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/eez/modules/dib-dcm220/dib-dcm220.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ struct DcmChannel : public Channel {
float iSet;
#endif

uint16_t uMonAdc = 0;
uint16_t iMonAdc = 0;

float temperature = 25.0f;

float I_MAX_FOR_REMAP;
Expand Down Expand Up @@ -362,6 +365,22 @@ struct DcmChannel : public Channel {
return NAN;
#endif
}

void dumpDebugVariables(scpi_t *context) override {
char buffer[100];

snprintf(buffer, sizeof(buffer), "CH%d U_DAC = %d", channelIndex + 1, (int)uSet);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d U_MON = %d", channelIndex + 1, (int)uMonAdc);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d I_DAC = %d", channelIndex + 1, (int)iSet);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d I_MON = %d", channelIndex + 1, (int)iMonAdc);
SCPI_ResultText(context, buffer);
}
};

struct DcmModule : public PsuModule {
Expand Down Expand Up @@ -546,10 +565,12 @@ struct DcmModule : public PsuModule {
channel.ccMode = (input[0] & (subchannelIndex == 0 ? REG0_CC1_MASK : REG0_CC2_MASK)) != 0;

uint16_t uMonAdc = inputSetValues[offset];
channel.uMonAdc = uMonAdc;
float uMon = remap(uMonAdc, (float)ADC_MIN, 0, (float)ADC_MAX, channel.params.U_MAX);
channel.onAdcData(ADC_DATA_TYPE_U_MON, uMon);

uint16_t iMonAdc = inputSetValues[offset + 1];
channel.iMonAdc = iMonAdc;
const float FULL_SCALE = 2.0F;
const float U_REF = 2.5F;
float iMon = remap(iMonAdc, (float)ADC_MIN, 0, FULL_SCALE * ADC_MAX / U_REF, /*params.I_MAX*/ channel.I_MAX_FOR_REMAP);
Expand Down
21 changes: 21 additions & 0 deletions src/eez/modules/dib-dcm224/dib-dcm224.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ struct DcmChannel : public Channel {
float iSet;
#endif

uint16_t uMonAdc = 0;
uint16_t iMonAdc = 0;

float temperature = 25.0f;

float I_MAX_FOR_REMAP;
Expand Down Expand Up @@ -447,6 +450,22 @@ struct DcmChannel : public Channel {
}
}
}

void dumpDebugVariables(scpi_t *context) override {
char buffer[100];

snprintf(buffer, sizeof(buffer), "CH%d U_DAC = %d", channelIndex + 1, (int)uSet);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d U_MON = %d", channelIndex + 1, (int)uMonAdc);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d I_DAC = %d", channelIndex + 1, (int)iSet);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d I_MON = %d", channelIndex + 1, (int)iMonAdc);
SCPI_ResultText(context, buffer);
}
};

static const float DEFAULT_COUNTERPHASE_FREQUENCY = 500000.0f;
Expand Down Expand Up @@ -1066,10 +1085,12 @@ void DcmModule::tick(uint8_t slotIndex) {
channel.ccMode = (input[0] & (subchannelIndex == 0 ? REG0_CC1_MASK : REG0_CC2_MASK)) != 0;

uint16_t uMonAdc = inputSetValues[offset];
channel.uMonAdc = uMonAdc;
float uMon = remap(uMonAdc, (float)ADC_MIN, 0, (float)ADC_MAX, channel.params.U_MAX);
channel.onAdcData(ADC_DATA_TYPE_U_MON, uMon);

uint16_t iMonAdc = inputSetValues[offset + 1];
channel.iMonAdc = iMonAdc;
const float FULL_SCALE = 2.0F;
const float U_REF = 2.5F;
float iMon = remap(iMonAdc, (float)ADC_MIN, 0, FULL_SCALE * ADC_MAX / U_REF, /*params.I_MAX*/ channel.I_MAX_FOR_REMAP);
Expand Down
2 changes: 2 additions & 0 deletions src/eez/modules/dib-dcp405/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@ float AnalogDigitalConverter::read() {
channel.i.mon_adc = value;
} else if (adcDataType == ADC_DATA_TYPE_U_MON_DAC) {
value = remapAdcDataToVoltage(channel, adcDataType, adcValue);
m_uLastMonDac = adcValue;
} else {
value = remapAdcDataToCurrent(channel, adcDataType, adcValue);
m_iLastMonDac = adcValue;
}

return value;
Expand Down
3 changes: 3 additions & 0 deletions src/eez/modules/dib-dcp405/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class AnalogDigitalConverter {

AdcDataType adcDataType;

int16_t m_uLastMonDac;
int16_t m_iLastMonDac;

void init();
bool test();

Expand Down
4 changes: 4 additions & 0 deletions src/eez/modules/dib-dcp405/dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp
if (rampOption != FROM_RAMP) {
m_uIsRampActive = false;
}

m_uLastValue = value;
}
else {
if (
Expand All @@ -262,6 +264,8 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp
if (rampOption != FROM_RAMP) {
m_iIsRampActive = false;
}

m_iLastValue = value;
}

uint8_t data[3];
Expand Down
3 changes: 3 additions & 0 deletions src/eez/modules/dib-dcp405/dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class DigitalAnalogConverter {
uint8_t channelIndex;
TestResult testResult;

uint16_t m_uLastValue;
uint16_t m_iLastValue;

void init();
bool test(IOExpander &ioexp, AnalogDigitalConverter &adc);

Expand Down
24 changes: 24 additions & 0 deletions src/eez/modules/dib-dcp405/dib-dcp405.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <new>
#include <assert.h>
#include <string.h>
#include <stdio.h>

#include <eez/modules/dib-dcp405/dib-dcp405.h>
#include <eez/modules/dib-dcp405/adc.h>
Expand Down Expand Up @@ -970,6 +972,28 @@ struct DcpChannel : public Channel {
int getAdvancedOptionsPageId() override {
return eez::gui::PAGE_ID_CH_SETTINGS_ADV_OPTIONS;
}

void dumpDebugVariables(scpi_t *context) override {
char buffer[100];

snprintf(buffer, sizeof(buffer), "CH%d U_DAC = %d", channelIndex + 1, (int)dac.m_uLastValue);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d U_MON = %d", channelIndex + 1, (int)u.mon_adc);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d U_MON_DAC = %d", channelIndex + 1, (int)adc.m_uLastMonDac);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d I_DAC = %d", channelIndex + 1, (int)dac.m_iLastValue);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d I_MON = %d", channelIndex + 1, (int)i.mon_adc);
SCPI_ResultText(context, buffer);

snprintf(buffer, sizeof(buffer), "CH%d I_MON_DAC = %d", channelIndex + 1, (int)adc.m_iLastMonDac);
SCPI_ResultText(context, buffer);
}
};

struct DcpModule : public PsuModule {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void Value::setDacValue(float value) {
channel_dispatcher::setVoltage(*channel, channel->params.I_CAL_U_SET);
} else {
// prevent false power fault detection (#275)
channel_dispatcher::setCurrent(*channel, 0.015);
channel_dispatcher::setCurrent(*channel, 0.015f);
channel_dispatcher::setVoltage(*channel, channel->params.I_LOW_RANGE_CAL_U_SET);
osDelay(3);
channel_dispatcher::setCurrent(*channel, value);
Expand Down
4 changes: 4 additions & 0 deletions src/eez/modules/psu/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <eez/modules/psu/persist_conf.h>
#include <eez/modules/psu/temp_sensor.h>

#include <scpi/types.h>

#define IS_OVP_VALUE(channel, cpv) (&cpv == &channel->ovp)
#define IS_OCP_VALUE(channel, cpv) (&cpv == &channel->ocp)
#define IS_OPP_VALUE(channel, cpv) (&cpv == &channel->opp)
Expand Down Expand Up @@ -706,6 +708,8 @@ struct Channel {
const char *getDefaultLabel();
const char *getLabelOrDefault() { return *label ? label : getDefaultLabel(); }

virtual void dumpDebugVariables(scpi_t *context) = 0;

//
//
//
Expand Down
7 changes: 4 additions & 3 deletions src/eez/modules/psu/scpi/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ scpi_result_t scpi_cmd_debugQ(scpi_t *context) {
}
}

static char buffer[2048];

#ifndef __EMSCRIPTEN__
for (int i = 0; i < CH_NUM; i++) {
if (!measureAllAdcValuesOnChannel(i)) {
Expand All @@ -199,7 +197,10 @@ scpi_result_t scpi_cmd_debugQ(scpi_t *context) {
}
#endif

SCPI_ResultCharacters(context, buffer, strlen(buffer));
for (int i = 0; i < CH_NUM; i++) {
Channel &channel = Channel::get(i);
channel.dumpDebugVariables(context);
}

return SCPI_RES_OK;
#else
Expand Down

0 comments on commit 8583eef

Please sign in to comment.