Skip to content

Commit

Permalink
cal. params and on time counters in module eeprom
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 23, 2019
1 parent 37a6347 commit fe105c3
Show file tree
Hide file tree
Showing 21 changed files with 513 additions and 282 deletions.
25 changes: 3 additions & 22 deletions src/eez/apps/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ float Channel::Simulator::getVoltProgExt() {

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

Channel::Channel()
: channelIndex(0), onTimeCounter(1)
{
}

void Channel::set(uint8_t slotIndex_, uint8_t subchannelIndex_, uint8_t boardRevision_) {
slotIndex = slotIndex_;
boardRevision = boardRevision_;
Expand Down Expand Up @@ -610,8 +605,6 @@ void Channel::tick(uint32_t tick_usec) {
setCcMode(channelInterface->isCvMode(subchannelIndex));
}

onTimeCounter.tick(tick_usec);

// update history values
uint32_t ytViewRateMicroseconds = (int)round(ytViewRate * 1000000L);
while (tick_usec - historyLastTick >= ytViewRateMicroseconds) {
Expand Down Expand Up @@ -828,12 +821,6 @@ void Channel::executeOutputEnable(bool enable) {
calibration::stop();
}
}

if (enable) {
onTimeCounter.start();
} else {
onTimeCounter.stop();
}
}

void Channel::doOutputEnable(bool enable) {
Expand Down Expand Up @@ -887,11 +874,7 @@ void Channel::update() {
return;
}

if (channelIndex == 0) {
doCalibrationEnable(persist_conf::devConf.flags.ch1CalEnabled && isCalibrationExists());
} else if (channelIndex == 1) {
doCalibrationEnable(persist_conf::devConf.flags.ch2CalEnabled && isCalibrationExists());
}
doCalibrationEnable(persist_conf::isChannelCalibrationEnabled(*this) && isCalibrationExists());

bool last_save_enabled = profile::enableSave(false);

Expand Down Expand Up @@ -1090,10 +1073,8 @@ void Channel::setCurrent(float value) {
}

bool Channel::isCalibrationExists() {
return (flags.currentCurrentRange == CURRENT_RANGE_HIGH &&
cal_conf.flags.i_cal_params_exists_range_high) ||
(flags.currentCurrentRange == CURRENT_RANGE_LOW &&
cal_conf.flags.i_cal_params_exists_range_low) ||
return (flags.currentCurrentRange == CURRENT_RANGE_HIGH && cal_conf.flags.i_cal_params_exists_range_high) ||
(flags.currentCurrentRange == CURRENT_RANGE_LOW && cal_conf.flags.i_cal_params_exists_range_low) ||
cal_conf.flags.u_cal_params_exists;
}

Expand Down
4 changes: 0 additions & 4 deletions src/eez/apps/psu/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,12 @@ class Channel {
ProtectionValue ocp;
ProtectionValue opp;

ontime::Counter onTimeCounter;

float ytViewRate;

#ifdef EEZ_PLATFORM_SIMULATOR
Simulator simulator;
#endif // EEZ_PLATFORM_SIMULATOR

Channel();

void set(uint8_t slotIndex, uint8_t subchannelIndex, uint8_t boardRevision);

void setChannelIndex(uint8_t channelIndex);
Expand Down
72 changes: 10 additions & 62 deletions src/eez/apps/psu/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,16 @@

#pragma once

/*! \page eeprom_map EEPROM map
/*! \page eeprom_map MCU EEPROM map
# Overview
|Address|Size|Description |
|-------|----|------------------------------------------|
|0 | 64|Not used |
|64 | 24|[Total ON-time counter](#ontime-counter) |
|128 | 24|[CH1 ON-time counter](#ontime-counter) |
|192 | 24|[CH2 ON-time counter](#ontime-counter) |
|256 | 24|[CH3 ON-time counter](#ontime-counter) |
|320 | 24|[CH4 ON-time counter](#ontime-counter) |
|384 | 24|[CH5 ON-time counter](#ontime-counter) |
|448 | 24|[CH6 ON-time counter](#ontime-counter) |
|1024 | 64|[Device configuration](#device) |
|1536 | 128|[Device configuration 2](#device2) |
|2048 | 144|CH1 [calibration parameters](#calibration)|
|2560 | 144|CH2 [calibration parameters](#calibration)|
|3072 | 144|CH3 [calibration parameters](#calibration)|
|3584 | 144|CH4 [calibration parameters](#calibration)|
|4096 | 144|CH5 [calibration parameters](#calibration)|
|4608 | 144|CH6 [calibration parameters](#calibration)|
|1536 | 128|[Device configuration 2](#device2) |
|5120 | 568|[Profile](#profile) 0 |
|6144 | 568|[Profile](#profile) 1 |
|7168 | 568|[Profile](#profile) 2 |
Expand Down Expand Up @@ -112,42 +100,6 @@
|11 |Force disabling of all outputs on power up |
|12 |Click sound enabled |
## <a name="calibration">Calibration parameters</a>
|Offset|Size|Type |Description |
|------|----|-----------------------|-----------------------------|
|0 |8 |[struct](#block-header)|[Block header](#block-header)|
|8 |4 |[bitarray](#cal-flags) |[Flags](#cal-flags) |
|12 |44 |[struct](#cal-points) |Voltage [points](#cal-points)|
|56 |44 |[struct](#cal-points) |Current [points](#cal-points)|
|100 |9 |string |Date |
|109 |33 |string |Remark |
#### <a name="cal-flags">Calibration flags</a>
|Bit|Description |
|---|-------------------|
|0 |Voltage calibrated?|
|1 |Current calibrated?|
#### <a name="cal-points">Value points</a>
|Offset|Size|Type |Description |
|------|----|--------------------|-----------------------|
|0 |12 |[struct](#cal-point)|Min [point](#cal-point)|
|12 |12 |[struct](#cal-point)|Mid [point](#cal-point)|
|24 |12 |[struct](#cal-point)|Max [point](#cal-point)|
|36 |4 |[struct](#cal-point)|Min. set value possible|
|40 |4 |[struct](#cal-point)|Max. set value possible|
#### <a name="cal-point">Value point</a>
|Offset|Size|Type |Description|
|------|----|-----|-----------|
|0 |4 |float|DAC value |
|4 |4 |float|Real value |
|8 |4 |float|ADC value |
## <a name="profile">Profile</a>
|Offset|Size|Type |Description |
Expand Down Expand Up @@ -190,16 +142,14 @@
|Bit|Description |
|---|-------------------|
|0 |Output enabled |
|1 |Sense enabled |
|2 |OVP enabled |
|3 |OCP enabled |
|3 |OPP enabled |
|5 |Calibration enabled|
|6 |RPROG enabled |
|7 |Reserved |
|8 |Reserved |
|9 |Params. valid |
|0-7|Module type |
|8 |Output enabled |
|9 |Sense enabled |
|10 |OVP enabled |
|11 |OCP enabled |
|12 |OPP enabled |
|13 |RPROG enabled |
|14 |Params. valid |
#### <a name="otp-conf">OTP configuration</a>
Expand Down Expand Up @@ -261,8 +211,6 @@ static const uint8_t READ = 3;
static const uint8_t WRITE = 2;

static const uint16_t EEPROM_ONTIME_START_ADDRESS = 64;
static const uint16_t EEPROM_ONTIME_SIZE = 64;
static const uint16_t EEPROM_START_ADDRESS = 1024;
static const uint16_t EEPROM_EVENT_QUEUE_START_ADDRESS = 16384;

void init();
Expand Down
15 changes: 8 additions & 7 deletions src/eez/apps/psu/event_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,18 @@ static const int EVENT_TYPE_ERROR = 3;
EVENT_WARNING(CH4_CALIBRATION_DISABLED, 3, "Ch4 calibration disabled") \
EVENT_WARNING(CH5_CALIBRATION_DISABLED, 4, "Ch5 calibration disabled") \
EVENT_WARNING(CH6_CALIBRATION_DISABLED, 5, "Ch6 calibration disabled") \
EVENT_WARNING(CH1_UNKNOWN_PWRGOOD_STATE, 10, "Ch1 unknown PWRGOOD") \
EVENT_WARNING(CH2_UNKNOWN_PWRGOOD_STATE, 11, "Ch2 unknown PWRGOOD") \
EVENT_WARNING(CH3_UNKNOWN_PWRGOOD_STATE, 12, "Ch3 unknown PWRGOOD") \
EVENT_WARNING(CH4_UNKNOWN_PWRGOOD_STATE, 13, "Ch4 unknown PWRGOOD") \
EVENT_WARNING(CH5_UNKNOWN_PWRGOOD_STATE, 14, "Ch5 unknown PWRGOOD") \
EVENT_WARNING(CH6_UNKNOWN_PWRGOOD_STATE, 15, "Ch6 unknown PWRGOOD") \
EVENT_WARNING(CH1_UNKNOWN_PWRGOOD_STATE, 10, "Ch1 unknown PWRGOOD") \
EVENT_WARNING(CH2_UNKNOWN_PWRGOOD_STATE, 11, "Ch2 unknown PWRGOOD") \
EVENT_WARNING(CH3_UNKNOWN_PWRGOOD_STATE, 12, "Ch3 unknown PWRGOOD") \
EVENT_WARNING(CH4_UNKNOWN_PWRGOOD_STATE, 13, "Ch4 unknown PWRGOOD") \
EVENT_WARNING(CH5_UNKNOWN_PWRGOOD_STATE, 14, "Ch5 unknown PWRGOOD") \
EVENT_WARNING(CH6_UNKNOWN_PWRGOOD_STATE, 15, "Ch6 unknown PWRGOOD") \
EVENT_WARNING(ETHERNET_NOT_CONNECTED, 20, "Ethernet not connected") \
EVENT_WARNING(AUTO_RECALL_VALUES_MISMATCH, 21, "Auto-recall mismatch") \
EVENT_WARNING(AUTO_RECALL_VALUES_MISMATCH, 21, "Auto-recall values mismatch") \
EVENT_WARNING(NTP_REFRESH_FAILED, 22, "NTP refresh failed") \
EVENT_WARNING(FILE_UPLOAD_ABORTED, 23, "File upload aborted") \
EVENT_WARNING(FILE_DOWNLOAD_ABORTED, 24, "File download aborted") \
EVENT_WARNING(AUTO_RECALL_MODULE_MISMATCH, 25, "Auto-recall module mismatch") \
EVENT_INFO(WELCOME, 0, "Welcome!") \
EVENT_INFO(POWER_UP, 1, "Power up") \
EVENT_INFO(POWER_DOWN, 2, "Power down") \
Expand Down
8 changes: 4 additions & 4 deletions src/eez/apps/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ void data_channel_on_time_total(data::DataOperationEnum operation, data::Cursor
Channel &channel = Channel::get(iChannel);
if (operation == data::DATA_OPERATION_GET) {
value =
data::Value((uint32_t)channel.onTimeCounter.getTotalTime(), VALUE_TYPE_ON_TIME_COUNTER);
data::Value((uint32_t)ontime::g_moduleCounters[channel.slotIndex].getTotalTime(), VALUE_TYPE_ON_TIME_COUNTER);
}
}

Expand All @@ -1650,7 +1650,7 @@ void data_channel_on_time_last(data::DataOperationEnum operation, data::Cursor &
Channel &channel = Channel::get(iChannel);
if (operation == data::DATA_OPERATION_GET) {
value =
data::Value((uint32_t)channel.onTimeCounter.getLastTime(), VALUE_TYPE_ON_TIME_COUNTER);
data::Value((uint32_t)ontime::g_moduleCounters[channel.slotIndex].getLastTime(), VALUE_TYPE_ON_TIME_COUNTER);
}
}

Expand Down Expand Up @@ -2338,14 +2338,14 @@ void data_channel_coupling_is_series(data::DataOperationEnum operation, data::Cu
void data_sys_on_time_total(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
value =
data::Value((uint32_t)g_powerOnTimeCounter.getTotalTime(), VALUE_TYPE_ON_TIME_COUNTER);
data::Value((uint32_t)ontime::g_mcuCounter.getTotalTime(), VALUE_TYPE_ON_TIME_COUNTER);
}
}

void data_sys_on_time_last(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
value =
data::Value((uint32_t)g_powerOnTimeCounter.getLastTime(), VALUE_TYPE_ON_TIME_COUNTER);
data::Value((uint32_t)ontime::g_mcuCounter.getLastTime(), VALUE_TYPE_ON_TIME_COUNTER);
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/eez/apps/psu/gui/page_user_profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <eez/gui/dialogs.h>
#include <eez/gui/document.h>

#include <scpi/scpi.h>

using namespace eez::psu::gui;

namespace eez {
Expand Down Expand Up @@ -76,10 +78,15 @@ void UserProfilesPage::toggleIsAutoRecallLocation() {

void UserProfilesPage::recall() {
if (g_selectedProfileLocation > 0 && profile::isValid(g_selectedProfileLocation)) {
if (profile::recall(g_selectedProfileLocation)) {
int err;
if (profile::recall(g_selectedProfileLocation, &err)) {
infoMessage("Profile parameters loaded");
} else {
errorMessage("Failed!");
if (err == SCPI_ERROR_PROFILE_MODULE_MISMATCH) {
errorMessage("Module mismatch in profile!");
} else {
errorMessage("Failed!");
}
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/eez/apps/psu/ontime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ namespace eez {
namespace psu {
namespace ontime {

ontime::Counter g_mcuCounter(ontime::ON_TIME_COUNTER_MCU);

ontime::Counter g_moduleCounters[] = {
ontime::Counter(ontime::ON_TIME_COUNTER_SLOT1),
ontime::Counter(ontime::ON_TIME_COUNTER_SLOT2),
ontime::Counter(ontime::ON_TIME_COUNTER_SLOT3)
};

void counterToString(char *str, size_t count, uint32_t counterTime) {
if (counterTime >= 24 * 60) {
uint32_t d = counterTime / (24 * 60);
Expand Down Expand Up @@ -93,10 +101,10 @@ void Counter::tick(uint32_t tick_usec) {
if (time > 0) {
lastTime += time;
fractionTime -= time * MIN_TO_MS;
}

if (writeInterval.test(tick_usec)) {
persist_conf::writeTotalOnTime(getType(), getTotalTime());
if (writeInterval.test(tick_usec)) {
persist_conf::writeTotalOnTime(getType(), getTotalTime());
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/eez/apps/psu/ontime.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ namespace ontime {

void counterToString(char *str, size_t count, uint32_t counterTime);

enum { ON_TIME_COUNTER_POWER, ON_TIME_COUNTER_CH1, ON_TIME_COUNTER_CH2, ON_TIME_COUNTER_CH3, ON_TIME_COUNTER_CH4, ON_TIME_COUNTER_CH5, ON_TIME_COUNTER_CH6 };
enum {
ON_TIME_COUNTER_MCU,
ON_TIME_COUNTER_SLOT1,
ON_TIME_COUNTER_SLOT2,
ON_TIME_COUNTER_SLOT3
};

class Counter {
public:
Expand Down Expand Up @@ -55,6 +60,9 @@ class Counter {
Interval writeInterval;
};

extern ontime::Counter g_mcuCounter;
extern ontime::Counter g_moduleCounters[];

} // namespace ontime
} // namespace psu
} // namespace eez
Loading

0 comments on commit fe105c3

Please sign in to comment.