Skip to content

Commit 0de6fe4

Browse files
committed
300ms ramp in survive mode
1 parent bf01f5c commit 0de6fe4

File tree

3 files changed

+99
-19
lines changed

3 files changed

+99
-19
lines changed

src/eez/modules/dib-dcp405/dac.cpp

+59-12
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ namespace psu {
4040
////////////////////////////////////////////////////////////////////////////////
4141

4242
#if defined(EEZ_PLATFORM_STM32)
43+
4344
static const uint8_t DATA_BUFFER_A = 0B00010000;
4445
static const uint8_t DATA_BUFFER_B = 0B00100100;
4546

4647
static const uint32_t CONF_DCP405_R2B11_RAMP_DURATION_USEC = 4000; // 4 ms
48+
49+
#if CONF_SURVIVE_MODE
50+
static const uint32_t CONF_I_RAMP_DURATION_USEC = 300000; // 300 ms
4751
#endif
4852

53+
#endif // EEZ_PLATFORM_STM32
54+
4955
#if defined(EEZ_PLATFORM_SIMULATOR)
5056
extern float g_uSet[CH_MAX];
5157
extern float g_iSet[CH_MAX];
@@ -120,28 +126,47 @@ bool DigitalAnalogConverter::test(IOExpander &ioexp, AnalogDigitalConverter &adc
120126

121127
void DigitalAnalogConverter::tick() {
122128
#if defined(EEZ_PLATFORM_STM32)
123-
if (m_isRampActive) {
129+
if (m_uIsRampActive) {
124130
uint16_t value;
125131

126132
uint32_t tickCountUsec = micros();
127133

128-
uint32_t diff = tickCountUsec - m_rampStartTimeUsec;
134+
uint32_t diff = tickCountUsec - m_uRampStartTimeUsec;
129135
if (diff >= CONF_DCP405_R2B11_RAMP_DURATION_USEC) {
130-
value = m_rampTargetValue;
131-
m_isRampActive = false;
136+
value = m_uRampTargetValue;
137+
m_uIsRampActive = false;
132138
} else {
133-
value = m_rampTargetValue * diff / CONF_DCP405_R2B11_RAMP_DURATION_USEC;
139+
value = m_uRampTargetValue * diff / CONF_DCP405_R2B11_RAMP_DURATION_USEC;
134140
}
135141

136142
set(DATA_BUFFER_B, value, FROM_RAMP);
137143
}
138-
#endif
144+
145+
#if CONF_SURVIVE_MODE
146+
if (m_iIsRampActive) {
147+
uint16_t value;
148+
149+
uint32_t tickCountUsec = micros();
150+
151+
uint32_t diff = tickCountUsec - m_iRampStartTimeUsec;
152+
if (diff >= CONF_I_RAMP_DURATION_USEC) {
153+
value = m_iRampTargetValue;
154+
m_iIsRampActive = false;
155+
} else {
156+
value = (uint64_t)m_iRampTargetValue * diff / CONF_I_RAMP_DURATION_USEC;
157+
}
158+
159+
set(DATA_BUFFER_A, value, FROM_RAMP);
160+
}
161+
#endif // CONF_SURVIVE_MODE
162+
163+
#endif // EEZ_PLATFORM_STM32
139164
}
140165

141166
bool DigitalAnalogConverter::isOverHwOvpThreshold() {
142167
static const float CONF_OVP_HW_VOLTAGE_THRESHOLD = 1.0f;
143168
Channel &channel = Channel::get(channelIndex);
144-
float u_set = remap(m_rampLastValue, (float)DAC_MIN, channel.params.U_MIN, (float)DAC_MAX, channel.params.U_MAX);
169+
float u_set = remap(m_uRampLastValue, (float)DAC_MIN, channel.params.U_MIN, (float)DAC_MAX, channel.params.U_MAX);
145170
return u_set > channel.getCalibratedVoltage(CONF_OVP_HW_VOLTAGE_THRESHOLD);
146171
}
147172

@@ -206,19 +231,41 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp
206231
g_slots[slotIndex]->moduleRevision <= MODULE_REVISION_DCP405_R2B11 &&
207232
!ramp::isActive(channel)
208233
) {
209-
m_isRampActive = true;
210-
m_rampTargetValue = value;
234+
m_uIsRampActive = true;
235+
m_uRampTargetValue = value;
211236
value = 0;
212237
rampOption = FROM_RAMP;
213-
m_rampStartTimeUsec = micros();
238+
m_uRampStartTimeUsec = micros();
239+
}
240+
241+
m_uRampLastValue = value;
242+
243+
if (rampOption != FROM_RAMP) {
244+
m_uIsRampActive = false;
245+
}
246+
}
247+
#if CONF_SURVIVE_MODE
248+
else {
249+
if (
250+
rampOption != FROM_RAMP &&
251+
!m_testing &&
252+
CONF_I_RAMP_DURATION_USEC > 0 &&
253+
!ramp::isActive(channel)
254+
) {
255+
m_iIsRampActive = true;
256+
m_iRampTargetValue = value;
257+
value = m_iRampLastValue;
258+
rampOption = FROM_RAMP;
259+
m_iRampStartTimeUsec = micros();
214260
}
215261

216-
m_rampLastValue = value;
262+
m_iRampLastValue = value;
217263

218264
if (rampOption != FROM_RAMP) {
219-
m_isRampActive = false;
265+
m_iIsRampActive = false;
220266
}
221267
}
268+
#endif // CONF_SURVIVE_MODE
222269

223270
uint8_t data[3];
224271
uint8_t result[3];

src/eez/modules/dib-dcp405/dac.h

+21-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class DigitalAnalogConverter {
3333
uint8_t slotIndex;
3434
uint8_t channelIndex;
3535
TestResult testResult;
36-
bool m_isRampActive = false;
3736

3837
void init();
3938
bool test(IOExpander &ioexp, AnalogDigitalConverter &adc);
@@ -58,13 +57,30 @@ class DigitalAnalogConverter {
5857

5958
bool isOverHwOvpThreshold();
6059

60+
bool isRampActive() {
61+
#if CONF_SURVIVE_MODE
62+
return m_uIsRampActive|| m_iIsRampActive;
63+
#else
64+
return m_uIsRampActive;
65+
#endif
66+
}
67+
6168
private:
6269
bool m_testing;
6370

64-
// ramp
65-
uint16_t m_rampLastValue;
66-
uint16_t m_rampTargetValue;
67-
uint32_t m_rampStartTimeUsec;
71+
// U ramp
72+
bool m_uIsRampActive = false;
73+
uint16_t m_uRampLastValue;
74+
uint16_t m_uRampTargetValue;
75+
uint32_t m_uRampStartTimeUsec;
76+
77+
// I ramp
78+
#if CONF_SURVIVE_MODE
79+
bool m_iIsRampActive = false;
80+
uint16_t m_iRampLastValue;
81+
uint16_t m_iRampTargetValue;
82+
uint32_t m_iRampStartTimeUsec;
83+
#endif
6884

6985
#if defined(EEZ_PLATFORM_STM32)
7086
void set(uint8_t buffer, uint16_t value, RampOption rampOption = NO_RAMP);

src/eez/modules/dib-dcp405/dib-dcp405.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct DcpChannel : public Channel {
8080
uint32_t dpNegMonitoringTimeMs;
8181

8282
float uSet = 0;
83+
#if CONF_SURVIVE_MODE
84+
float iSet = 0;
85+
#endif
8386

8487
float uBeforeBalancing = NAN;
8588
float iBeforeBalancing = NAN;
@@ -210,6 +213,9 @@ struct DcpChannel : public Channel {
210213
Channel::reset();
211214

212215
uSet = 0;
216+
#if CONF_SURVIVE_MODE
217+
iSet = 0;
218+
#endif
213219
dpOn = false;
214220
uBeforeBalancing = NAN;
215221
iBeforeBalancing = NAN;
@@ -493,12 +499,16 @@ struct DcpChannel : public Channel {
493499
if (enable) {
494500
// OE
495501
if (tasks & OUTPUT_ENABLE_TASK_OE) {
502+
ioexp.changeBit(IOExpander::IO_BIT_OUT_OVP_ENABLE, false);
496503
ioexp.changeBit(IOExpander::IO_BIT_OUT_OUTPUT_ENABLE, true);
497504
}
498505

499506
// DAC
500507
if (tasks & OUTPUT_ENABLE_TASK_DAC) {
501508
dac.setVoltage(uSet, DigitalAnalogConverter::WITH_RAMP);
509+
#if CONF_SURVIVE_MODE
510+
dac.setCurrent(iSet);
511+
#endif
502512
}
503513

504514
// Current range
@@ -543,6 +553,9 @@ struct DcpChannel : public Channel {
543553
// DAC
544554
if (tasks & OUTPUT_ENABLE_TASK_DAC) {
545555
dac.setDacVoltage(0);
556+
#if CONF_SURVIVE_MODE
557+
dac.setDacCurrent(0);
558+
#endif
546559
}
547560

548561
// OE
@@ -679,6 +692,10 @@ struct DcpChannel : public Channel {
679692
}
680693
}
681694

695+
#if CONF_SURVIVE_MODE
696+
iSet = value;
697+
#endif
698+
682699
dac.setCurrent(value);
683700

684701
if (!valueBalancing) {
@@ -1070,7 +1087,7 @@ bool isDacRampActive() {
10701087
for (int i = 0; i < CH_NUM; i++) {
10711088
auto &channel = Channel::get(i);
10721089
if (g_slots[channel.slotIndex]->moduleType == MODULE_TYPE_DCP405) {
1073-
if (((DcpChannel&)channel).dac.m_isRampActive) {
1090+
if (((DcpChannel&)channel).dac.isRampActive()) {
10741091
return true;
10751092
}
10761093
}
@@ -1082,7 +1099,7 @@ void tickDacRamp() {
10821099
for (int i = 0; i < CH_NUM; i++) {
10831100
auto &channel = Channel::get(i);
10841101
if (g_slots[channel.slotIndex]->moduleType == MODULE_TYPE_DCP405) {
1085-
if (((DcpChannel&)channel).dac.m_isRampActive) {
1102+
if (((DcpChannel&)channel).dac.isRampActive()) {
10861103
((DcpChannel&)channel).dac.tick();
10871104
}
10881105
}

0 commit comments

Comments
 (0)