Skip to content

Commit

Permalink
voltage ramp for DCP405 R2B11 on ch on
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Apr 29, 2020
1 parent eb4441d commit c12d360
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 39 deletions.
3 changes: 3 additions & 0 deletions src/eez/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ struct ChannelParams {

uint32_t DAC_MAX;
uint32_t ADC_MAX;

float U_RAMP_DURATION_MIN_VALUE;
};

struct ChannelInterface {
Expand Down Expand Up @@ -219,6 +221,7 @@ static const uint16_t MODULE_TYPE_DCM224 = 224;
static const uint16_t MODULE_REVISION_DCP405_R1B1 = 0x0101;
static const uint16_t MODULE_REVISION_DCP405_R2B5 = 0x0205;
static const uint16_t MODULE_REVISION_DCP405_R2B7 = 0x0207;
static const uint16_t MODULE_REVISION_DCP405_R2B11 = 0x020B;
static const uint16_t MODULE_REVISION_DCP405_R3B1 = 0x0301;

static const uint16_t MODULE_REVISION_DCP405B_R2B7 = 0x0207;
Expand Down
19 changes: 14 additions & 5 deletions src/eez/modules/dcm220/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ static const uint16_t ADC_MAX = 65535;

static const float PTOT = 155.0f;

static const float I_MON_RESOLUTION = 0.02f;

#if defined(EEZ_PLATFORM_STM32)

#define REG0_CC1_MASK (1 << 1)
Expand Down Expand Up @@ -169,7 +171,7 @@ struct Channel : ChannelInterface {
float I_MAX_FOR_REMAP;

float U_CAL_POINTS[2];
float I_CAL_POINTS[2];
float I_CAL_POINTS[6];

Channel(int slotIndex_)
: ChannelInterface(slotIndex_)
Expand Down Expand Up @@ -197,7 +199,7 @@ struct Channel : ChannelInterface {

U_CAL_POINTS[0] = 2.0f;
U_CAL_POINTS[1] = slot.moduleInfo->moduleType == MODULE_TYPE_DCM224 ? 22.0f : 18.0f;
params.U_CAL_NUM_POINTS = 2;
params.U_CAL_NUM_POINTS = sizeof(U_CAL_POINTS) / sizeof(float);
params.U_CAL_POINTS = U_CAL_POINTS;
params.U_CAL_I_SET = 1.0f;

Expand All @@ -211,9 +213,13 @@ struct Channel : ChannelInterface {
params.I_DEF_STEP = 0.01f;
params.I_MAX_STEP = 1.0f;

I_CAL_POINTS[0] = 0.5f;
I_CAL_POINTS[1] = slot.moduleInfo->moduleType == MODULE_TYPE_DCM224 ? 4.5f : 3.5f;
params.I_CAL_NUM_POINTS = 2;
I_CAL_POINTS[0] = 0.1f;
I_CAL_POINTS[1] = 0.2f;
I_CAL_POINTS[2] = 0.3f;
I_CAL_POINTS[3] = 0.4f;
I_CAL_POINTS[4] = 0.5f;
I_CAL_POINTS[5] = slot.moduleInfo->moduleType == MODULE_TYPE_DCM224 ? 4.5f : 3.5f;
params.I_CAL_NUM_POINTS = sizeof(I_CAL_POINTS) / sizeof(float);
params.I_CAL_POINTS = I_CAL_POINTS;
params.I_CAL_U_SET = 20.0f;

Expand Down Expand Up @@ -259,6 +265,8 @@ struct Channel : ChannelInterface {
params.ADC_MAX = ADC_MAX;

I_MAX_FOR_REMAP = slot.moduleInfo->moduleType == MODULE_TYPE_DCM224 ? 5.0f : 4.1667f;

params.U_RAMP_DURATION_MIN_VALUE = 0.002f;
}

#if defined(EEZ_PLATFORM_STM32)
Expand Down Expand Up @@ -445,6 +453,7 @@ struct Channel : ChannelInterface {
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, /*channel.params.I_MAX*/ I_MAX_FOR_REMAP);
iMon = roundPrec(iMon, I_MON_RESOLUTION);
channel.onAdcData(ADC_DATA_TYPE_I_MON, iMon);

#ifdef DEBUG
Expand Down
26 changes: 25 additions & 1 deletion src/eez/modules/dcpX05/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ struct Channel : ChannelInterface {

params.DAC_MAX = DigitalAnalogConverter::DAC_MAX;
params.ADC_MAX = AnalogDigitalConverter::ADC_MAX;

if (slot.moduleInfo->moduleType == MODULE_TYPE_DCP405 && slot.moduleRevision <= MODULE_REVISION_DCP405_R2B11) {
params.U_RAMP_DURATION_MIN_VALUE = 0.004f;
} else {
params.U_RAMP_DURATION_MIN_VALUE = 0.002f;
}
}

void init(int subchannelIndex) {
Expand Down Expand Up @@ -462,7 +468,7 @@ struct Channel : ChannelInterface {

// DAC
if (tasks & OUTPUT_ENABLE_TASK_DAC) {
dac.setVoltage(uSet);
dac.setVoltage(uSet, DigitalAnalogConverter::WITH_RAMP);
}

// Current range
Expand Down Expand Up @@ -835,5 +841,23 @@ static Channel g_channel1(1);
static Channel g_channel2(2);
ChannelInterface *g_channelInterfaces[NUM_SLOTS] = { &g_channel0, &g_channel1, &g_channel2 };

bool isDacRampActive() {
return g_channel0.dac.m_isRampActive || g_channel1.dac.m_isRampActive || g_channel2.dac.m_isRampActive;
}

void tickDacRamp(uint32_t tickCount) {
if (g_channel0.dac.m_isRampActive) {
g_channel0.dac.tick(tickCount);
}

if (g_channel1.dac.m_isRampActive) {
g_channel1.dac.tick(tickCount);
}

if (g_channel2.dac.m_isRampActive) {
g_channel2.dac.tick(tickCount);
}
}

} // namespace dcpX05
} // namespace eez
3 changes: 3 additions & 0 deletions src/eez/modules/dcpX05/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ namespace dcpX05 {

extern ChannelInterface *g_channelInterfaces[NUM_SLOTS];

bool isDacRampActive();
void tickDacRamp(uint32_t tickCount);

} // namespace dcpX05
} // namespace eez
52 changes: 47 additions & 5 deletions src/eez/modules/dcpX05/dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif

#include <eez/modules/psu/psu.h>
#include <eez/modules/psu/ramp.h>

#include <eez/modules/dcpX05/dac.h>
#include <eez/modules/dcpX05/adc.h>
Expand All @@ -47,6 +48,8 @@ extern float g_uSet[CH_MAX];
extern float g_iSet[CH_MAX];
#endif

static const uint32_t CONF_DCP405_R2B11_RAMP_DURATION = 4000; // 4 ms

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

void DigitalAnalogConverter::init() {
Expand Down Expand Up @@ -114,13 +117,31 @@ bool DigitalAnalogConverter::test(IOExpander &ioexp, AnalogDigitalConverter &adc
return g_testResult != TEST_FAILED;
}

void DigitalAnalogConverter::tick(uint32_t tickCount) {
#if defined(EEZ_PLATFORM_STM32)
if (m_isRampActive) {
uint16_t value;

uint32_t diff = tickCount - m_rampStartTime;
if (diff >= CONF_DCP405_R2B11_RAMP_DURATION) {
value = m_rampTargetValue;
m_isRampActive = false;
} else {
value = m_rampStartValue + (m_rampTargetValue - m_rampStartValue) * diff / CONF_DCP405_R2B11_RAMP_DURATION;
}

set(DATA_BUFFER_B, value, FROM_RAMP);
}
#endif
}

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

void DigitalAnalogConverter::setVoltage(float value) {
void DigitalAnalogConverter::setVoltage(float value, RampOption rampOption) {
Channel &channel = Channel::getBySlotIndex(slotIndex);

#if defined(EEZ_PLATFORM_STM32)
set(DATA_BUFFER_B, remap(value, channel.params.U_MIN, (float)DAC_MIN, channel.params.U_MAX, (float)DAC_MAX));
set(DATA_BUFFER_B, remap(value, channel.params.U_MIN, (float)DAC_MIN, channel.params.U_MAX, (float)DAC_MAX), rampOption);
#endif

#if defined(EEZ_PLATFORM_SIMULATOR)
Expand Down Expand Up @@ -166,16 +187,37 @@ void DigitalAnalogConverter::setDacCurrent(uint16_t value) {

#if defined(EEZ_PLATFORM_STM32)

void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value) {
void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption rampOption) {
Channel &channel = Channel::getBySlotIndex(slotIndex);

#ifdef DEBUG
if (buffer == DATA_BUFFER_B) {
if (
rampOption == WITH_RAMP &&
g_slots[slotIndex].moduleInfo->moduleType == MODULE_TYPE_DCP405 &&
g_slots[slotIndex].moduleRevision <= MODULE_REVISION_DCP405_R2B11 &&
!ramp::isActive(channel)
) {
m_isRampActive = true;
m_rampStartValue = m_rampLastValue;
m_rampTargetValue = value;
m_rampStartTime = micros();
return;
}

m_rampLastValue = value;

if (rampOption != FROM_RAMP) {
m_isRampActive = false;
}

#ifdef DEBUG
debug::g_uDac[channel.channelIndex].set(value);
#endif
} else {
#ifdef DEBUG
debug::g_iDac[channel.channelIndex].set(value);
}
#endif
}

uint8_t data[3];
uint8_t result[3];
Expand Down
22 changes: 19 additions & 3 deletions src/eez/modules/dcpX05/dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,40 @@ class DigitalAnalogConverter {

uint8_t slotIndex;
TestResult g_testResult;
bool m_isRampActive = false;

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

void setVoltage(float voltage);
void tick(uint32_t tickCount);

enum RampOption {
NO_RAMP,
WITH_RAMP,
FROM_RAMP
};

void setVoltage(float voltage, RampOption rampOption = NO_RAMP);
void setDacVoltage(uint16_t voltage);

void setCurrent(float voltage);
void setDacCurrent(uint16_t current);

bool isTesting() {
return m_testing;
}

private:
private:
bool m_testing;

// ramp
uint16_t m_rampLastValue;
uint16_t m_rampStartValue = 0;
uint16_t m_rampTargetValue;
uint32_t m_rampStartTime;

#if defined(EEZ_PLATFORM_STM32)
void set(uint8_t buffer, uint16_t value);
void set(uint8_t buffer, uint16_t value, RampOption rampOption = NO_RAMP);
void set(uint8_t buffer, float value);
#endif
};
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ void start(Channel &channel) {
return;

channel_dispatcher::outputEnable(channel, false);
channel_dispatcher::setVoltage(channel, 0);
channel_dispatcher::setCurrent(channel, 0);
channel_dispatcher::setVoltage(channel, channel.u.min);
channel_dispatcher::setCurrent(channel, channel.i.min);

profile::saveToLocation(10);
profile::setFreezeState(true);
Expand Down
20 changes: 10 additions & 10 deletions src/eez/modules/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,27 +1461,27 @@ void Channel::setPowerLimit(float limit) {
}

bool Channel::isVoltageWithinRange(float u) {
u = channel_dispatcher::getValuePrecision(*this, UNIT_VOLT, u);
float min =channel_dispatcher::getValuePrecision(*this, UNIT_VOLT, channel_dispatcher::getUMin(*this));
float max =channel_dispatcher::getValuePrecision(*this, UNIT_VOLT, channel_dispatcher::getUMax(*this));
u = channel_dispatcher::roundChannelValue(*this, UNIT_VOLT, u);
float min = channel_dispatcher::roundChannelValue(*this, UNIT_VOLT, channel_dispatcher::getUMin(*this));
float max = channel_dispatcher::roundChannelValue(*this, UNIT_VOLT, channel_dispatcher::getUMax(*this));
return u >= min && u <= max;
}

bool Channel::isVoltageLimitExceeded(float u) {
return channel_dispatcher::getValuePrecision(*this, UNIT_VOLT, u) >
channel_dispatcher::getValuePrecision(*this, UNIT_VOLT, channel_dispatcher::getULimit(*this));
return channel_dispatcher::roundChannelValue(*this, UNIT_VOLT, u) >
channel_dispatcher::roundChannelValue(*this, UNIT_VOLT, channel_dispatcher::getULimit(*this));
}

bool Channel::isCurrentWithinRange(float i) {
i = channel_dispatcher::getValuePrecision(*this, UNIT_AMPER, i);
float min =channel_dispatcher::getValuePrecision(*this, UNIT_AMPER, channel_dispatcher::getIMin(*this));
float max =channel_dispatcher::getValuePrecision(*this, UNIT_AMPER, channel_dispatcher::getIMax(*this));
i = channel_dispatcher::roundChannelValue(*this, UNIT_AMPER, i);
float min =channel_dispatcher::roundChannelValue(*this, UNIT_AMPER, channel_dispatcher::getIMin(*this));
float max =channel_dispatcher::roundChannelValue(*this, UNIT_AMPER, channel_dispatcher::getIMax(*this));
return i >= min && i <= max;
}

bool Channel::isCurrentLimitExceeded(float i) {
return channel_dispatcher::getValuePrecision(*this, UNIT_AMPER, i) >
channel_dispatcher::getValuePrecision(*this, UNIT_AMPER, channel_dispatcher::getILimit(*this));
return channel_dispatcher::roundChannelValue(*this, UNIT_AMPER, i) >
channel_dispatcher::roundChannelValue(*this, UNIT_AMPER, channel_dispatcher::getILimit(*this));
}


Expand Down
10 changes: 5 additions & 5 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2339,15 +2339,15 @@ void data_calibration_point_measured_value(DataOperationEnum operation, Cursor c
}
} else if (operation == DATA_OPERATION_GET_MIN) {
if (editPage->getCalibrationValueType() == calibration::CALIBRATION_VALUE_U) {
value = MakeValue(0 - channel_dispatcher::getUMax(channel) * 1.0f, UNIT_VOLT);
value = MakeValue(-1.0f, UNIT_VOLT);
} else {
value = MakeValue(0 - channel_dispatcher::getIMaxLimit(channel) * 1.0f, UNIT_AMPER);
value = MakeValue(-0.5f, UNIT_AMPER);
}
} else if (operation == DATA_OPERATION_GET_MAX) {
if (editPage->getCalibrationValueType() == calibration::CALIBRATION_VALUE_U) {
value = MakeValue(channel_dispatcher::getUMax(channel) * 2.0f, UNIT_VOLT);
value = MakeValue(channel_dispatcher::getUMax(channel) + 1.0f, UNIT_VOLT);
} else {
value = MakeValue(channel_dispatcher::getIMaxLimit(channel) * 2.0f, UNIT_AMPER);
value = MakeValue(channel_dispatcher::getIMaxLimit(channel) + 0.5f, UNIT_AMPER);
}
} else if (operation == DATA_OPERATION_GET_NAME) {
value = editPage->getCalibrationValueType() == calibration::CALIBRATION_VALUE_U ? "Voltage" : "Current";
Expand Down Expand Up @@ -6045,7 +6045,7 @@ void data_channel_voltage_ramp_duration(DataOperationEnum operation, Cursor curs
} else if (operation == DATA_OPERATION_GET_ALLOW_ZERO) {
value = 1;
} else if (operation == DATA_OPERATION_GET_MIN) {
value = MakeValue(RAMP_DURATION_MIN_VALUE, UNIT_SECOND);
value = MakeValue(Channel::get(cursor).params.U_RAMP_DURATION_MIN_VALUE, UNIT_SECOND);
} else if (operation == DATA_OPERATION_GET_MAX) {
value = MakeValue(RAMP_DURATION_MAX_VALUE, UNIT_SECOND);
} else if (operation == DATA_OPERATION_GET_LIMIT) {
Expand Down
3 changes: 3 additions & 0 deletions src/eez/modules/psu/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ static bool recallState(Parameters &profile, List *lists, int recallOptions, int
}

channel.u.rampDuration = profile.channels[i].u_rampDuration;
if (channel.u.rampDuration > 0 && channel.u.rampDuration < channel.params.U_RAMP_DURATION_MIN_VALUE) {
channel.u.rampDuration = channel.params.U_RAMP_DURATION_MIN_VALUE;
}
channel.i.rampDuration = profile.channels[i].i_rampDuration;

channel.outputDelayDuration = profile.channels[i].outputDelayDuration;
Expand Down
12 changes: 10 additions & 2 deletions src/eez/modules/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include <eez/modules/mcu/battery.h>
#include <eez/modules/mcu/eeprom.h>

#include <eez/modules/dcpX05/channel.h>
#include <eez/modules/dcpX05/ioexp.h>
#include <eez/modules/dcpX05/dac.h>
#include <eez/modules/dcpX05/adc.h>
Expand Down Expand Up @@ -182,14 +183,16 @@ osMessageQId g_psuMessageQueueId;
} // namespacee eez::psu

#if defined(EEZ_PLATFORM_STM32)

extern "C" void PSU_IncTick() {
g_tickCount++;

using namespace eez::psu;
if (ramp::isActive()) {
if (ramp::isActive() || eez::dcpX05::isDacRampActive()) {
osMessagePut(g_psuMessageQueueId, PSU_QUEUE_MESSAGE(PSU_QUEUE_MESSAGE_TYPE_TICK, 0), 0);
}
}

#endif

namespace eez {
Expand Down Expand Up @@ -243,8 +246,13 @@ void oneIter() {

if (type == PSU_QUEUE_MESSAGE_TYPE_TICK) {
#if defined(EEZ_PLATFORM_STM32)
uint32_t tickCount = micros();

ramp::tick(tickCount);

dcpX05::tickDacRamp(tickCount);

if (g_tickCount % 5) {
ramp::tick(micros());
return;
}
#endif
Expand Down
Loading

0 comments on commit c12d360

Please sign in to comment.