Skip to content

Commit

Permalink
dlog view log scale
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 31, 2019
1 parent 13a50d4 commit 2551362
Show file tree
Hide file tree
Showing 16 changed files with 374 additions and 172 deletions.
78 changes: 69 additions & 9 deletions modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -1853,12 +1853,12 @@
"defaultValue": "200ms"
},
{
"name": "dlog_x_axis_range_max",
"name": "dlog_x_axis_max_value",
"type": "string",
"defaultValue": "8.34s"
},
{
"name": "dlog_x_axis_range_max_label",
"name": "dlog_x_axis_max_value_label",
"type": "string",
"defaultValue": "Total duration"
},
Expand Down Expand Up @@ -20521,7 +20521,7 @@
"inheritFrom": "default"
},
"data": "sys_output_protection_coupled",
"action": "",
"action": "sys_settings_protections_toggle_output_protection_couple",
"left": 179,
"top": 0,
"width": 57,
Expand All @@ -20532,7 +20532,7 @@
"style": {
"inheritFrom": "option_toggle_L_center"
},
"action": "sys_settings_protections_toggle_output_protection_couple",
"action": "",
"left": 0,
"top": 0,
"width": 57,
Expand All @@ -20545,7 +20545,7 @@
"style": {
"inheritFrom": "option_toggle_L_center"
},
"action": "sys_settings_protections_toggle_output_protection_couple",
"action": "",
"left": 0,
"top": 0,
"width": 57,
Expand Down Expand Up @@ -45197,7 +45197,7 @@
"activeColor": "status_line_background",
"activeBackgroundColor": "status_line_text"
},
"data": "dlog_x_axis_range_max_label",
"data": "dlog_x_axis_max_value_label",
"left": 160,
"top": 0,
"width": 80,
Expand All @@ -45217,7 +45217,7 @@
"activeColor": "status_line_background",
"activeBackgroundColor": "status_line_text"
},
"data": "dlog_x_axis_range_max",
"data": "dlog_x_axis_max_value",
"left": 160,
"top": 14,
"width": 80,
Expand Down Expand Up @@ -45345,7 +45345,7 @@
"activeColor": "status_line_background",
"activeBackgroundColor": "status_line_text"
},
"data": "dlog_x_axis_range_max",
"data": "dlog_x_axis_max_value",
"left": 0,
"top": 0,
"width": 100,
Expand Down Expand Up @@ -446319,6 +446319,29 @@
"type": "quoted-string"
}
},
{
"name": "SENSe:DLOG:TRACe:X:SCALe",
"parameters": [
{
"name": "type",
"type": [
{
"type": "discrete",
"enumeration": "ScaleType"
}
]
}
],
"response": {}
},
{
"name": "SENSe:DLOG:TRACe:X:SCALe?",
"parameters": [],
"response": {
"type": "discrete",
"enumeration": "ScaleType"
}
},
{
"name": "SENSe:DLOG:TRACe:X[:RANGe]:MIN",
"parameters": [
Expand Down Expand Up @@ -446447,6 +446470,29 @@
"type": "nr2"
}
},
{
"name": "SENSe:DLOG:TRACe:Y:SCALe",
"parameters": [
{
"name": "type",
"type": [
{
"type": "discrete",
"enumeration": "ScaleType"
}
]
}
],
"response": {}
},
{
"name": "SENSe:DLOG:TRACe:Y:SCALe?",
"parameters": [],
"response": {
"type": "discrete",
"enumeration": "ScaleType"
}
},
{
"name": "SENSe:DLOG:TRACe[:DATA]",
"parameters": [
Expand Down Expand Up @@ -450311,6 +450357,19 @@
"value": "3"
}
]
},
{
"name": "ScaleType",
"members": [
{
"name": "LINear",
"value": "1"
},
{
"name": "LOGarithmic",
"value": "2"
}
]
}
]
},
Expand Down Expand Up @@ -450470,7 +450529,8 @@
"showInToolbar": true,
"toolbarButtonPosition": 10,
"toolbarButtonColor": "#F2D74A",
"requiresConfirmation": true
"requiresConfirmation": true,
"selected": true
},
{
"id": "6bb41d10-15a9-478f-da75-dbccd0a0f38a",
Expand Down
32 changes: 21 additions & 11 deletions scripts/curve-tracer (N-type).py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import math
from utime import ticks_ms, ticks_add, ticks_diff, sleep_ms
from eez import scpi, setU, getOutputMode, getI, dlogTraceData

TIME_ON_MS = 15
TIME_OFF_MS = 15
TIME_OFF_MS = 6

# Ch1 G-S
Ugs = [3, 3.5, 4, 4.5, 5, 5.5, 6]
Ugs = [3, 3.5, 4, 4.5, 6, 8, 12]
Ig = 5.0

# Ch2 D-S
Uds_min = 0.1
NUM_U_DS_STEPS = 400

SIMULATOR = 0
Expand All @@ -20,7 +22,10 @@

def start(deviceName, Uds_max, Id_max):
try:
Uds_step = Uds_max / NUM_U_DS_STEPS
#Uds_step = Uds_max / NUM_U_DS_STEPS
Uds_logMin = math.log(Uds_min) / math.log(10)
Uds_logMax = math.log(Uds_max) / math.log(10)
Uds_step = (Uds_logMax - Uds_logMin) / (NUM_U_DS_STEPS - 1)

scpi("*SAV 10")
scpi("MEM:STAT:FREEze ON")
Expand All @@ -38,15 +43,19 @@ def start(deviceName, Uds_max, Id_max):
scpi("CURR " + str(Id_max))

scpi("SENS:DLOG:TRAC:X:UNIT VOLT")
scpi("SENS:DLOG:TRAC:X:RANG:MIN " + str(Uds_logMin))
scpi("SENS:DLOG:TRAC:X:RANG:MAX " + str(Uds_logMax))
scpi("SENS:DLOG:TRAC:X:STEP " + str(Uds_step))
scpi("SENS:DLOG:TRAC:X:RANG:MAX " + str(Uds_max))
scpi("SENS:DLOG:TRAC:X:SCALE LOG")
scpi('SENS:DLOG:TRAC:X:LABel "Uds"')

num_ugs_steps = len(Ugs)

scpi("SENS:DLOG:TRAC:Y:UNIT AMPER")
scpi("SENS:DLOG:TRAC:Y:RANG:MAX " + str(Id_max))
scpi("SENS:DLOG:TRAC:Y:RANG:MIN 0")
scpi("SENS:DLOG:TRAC:Y:RANG:MAX " + str(Id_max * 1.1))
scpi('SENS:DLOG:TRAC:Y:LABel "Id"')
scpi('SENS:DLOG:TRAC:Y:SCALe LOG')

for ugs_step_counter in range(num_ugs_steps):
scpi('SENS:DLOG:TRAC:Y' + str(ugs_step_counter+1) + ':LABel "Ugs=' + str(Ugs[ugs_step_counter]) + 'V"')
Expand All @@ -67,7 +76,10 @@ def start(deviceName, Uds_max, Id_max):

t = ticks_ms()
for uds_step_counter in range(NUM_U_DS_STEPS):
Uds = (uds_step_counter + 1) * Uds_step
Uds = math.pow(10, Uds_logMin + uds_step_counter * Uds_step)

print(Uds)

setU(2, Uds)

for ugs_step_counter in range(num_ugs_steps):
Expand Down Expand Up @@ -100,12 +112,10 @@ def start(deviceName, Uds_max, Id_max):
if ch1Model.startswith("DCP405") and ch2Model.startswith("DCP405"):
deviceName = scpi('DISP:INPUT? "Device name", TEXT, 1, 20, ""')
if deviceName != None:
Uds_max = scpi('DISP:INPUT? "Uds,max", NUMBER, VOLT, 1.0, 40.0, 20.0')
Uds_max = scpi('DISP:INPUT? "Uds,max", NUMBER, VOLT, 1.0, 40.0, 15.0')
if Uds_max != None:
Uds_max = float(Uds_max)
Id_max = scpi('DISP:INPUT? "Id,max", NUMBER, AMPER, 0.001, 5.0, 3.0')
Id_max = scpi('DISP:INPUT? "Id,max", NUMBER, AMPER, 0.001, 5.0, 2.0')
if Id_max != None:
Id_max = float(Id_max)
start(deviceName, Uds_max, Id_max)
start(deviceName, float(Uds_max), float(Id_max))
else:
scpi('DISP:INPUT? "Requires DCP405 or DCP405B on Ch1 and Ch2", MENU, BUTTON, "Close"')
2 changes: 1 addition & 1 deletion src/eez/gui/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,9 +1153,9 @@ void action_dlog_toggle() {
void action_show_dlog_view() {
dlog_view::g_showLatest = true;
if (dlog_record::isExecuting()) {
dlog_view::g_showLegend = false;
dlog_view::g_showLabels = false;
} else {
dlog_view::g_showLabels = true;
dlog_view::openFile(dlog_record::getLatestFilePath());
}
showPage(PAGE_ID_DLOG_VIEW);
Expand Down
6 changes: 4 additions & 2 deletions src/eez/gui/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ OnTouchFunctionType getTouchFunction(const WidgetCursor &widgetCursor) {
}

if (widgetCursor) {
if (g_onTouchFunctions[widgetCursor.widget->type]) {
return g_onTouchFunctions[widgetCursor.widget->type];
}

if (widgetCursor.widget->action) {
if (widgetCursor.appContext->isWidgetActionEnabled(widgetCursor)) {
return onWidgetDefaultTouch;
}
} else {
return g_onTouchFunctions[widgetCursor.widget->type];
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/eez/modules/mcu/simulator/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static SDL_Window *g_mainWindow;
static SDL_Renderer *g_renderer;

static uint32_t *g_buffer;
static uint32_t *g_lastBuffer;

static bool g_takeScreenshot;
static int g_screenshotY;
Expand Down Expand Up @@ -235,6 +236,8 @@ void updateBrightness() {
}

void updateScreen(uint32_t *buffer) {
g_lastBuffer = buffer;

if (!isOn()) {
return;
}
Expand Down Expand Up @@ -282,7 +285,7 @@ void animate() {
}

void doTakeScreenshot() {
uint8_t *src = (uint8_t *)(g_buffer + g_psuAppContext.y * DISPLAY_WIDTH + g_psuAppContext.x);
uint8_t *src = (uint8_t *)(g_lastBuffer + g_psuAppContext.y * DISPLAY_WIDTH + g_psuAppContext.x);
uint8_t *dst = SCREENSHOOT_BUFFER_START_ADDRESS;

int srcAdvance = (DISPLAY_WIDTH - 480) * 4;
Expand Down
37 changes: 24 additions & 13 deletions src/eez/modules/psu/dlog_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dlog_view::Parameters g_parameters = {
{ 0 },
{ },
{ },
dlog_view::SCALE_LINEAR,
0,
{{}, {}, {}, {}, {}, {}},
{false, false, false, false, false, false},
Expand All @@ -61,6 +62,7 @@ dlog_view::Parameters g_guiParameters = {
{ 0 },
{ },
{ },
dlog_view::SCALE_LINEAR,
0,
{{}, {}, {}, {}, {}, {}},
{true, false, false, false, false, false},
Expand Down Expand Up @@ -263,10 +265,20 @@ int checkDlogParameters(dlog_view::Parameters &parameters, bool doNotCheckFilePa
return SCPI_ERROR_EXECUTION_ERROR;
}

if (parameters.xAxis.range.min >= parameters.xAxis.range.max) {
return SCPI_ERROR_DATA_OUT_OF_RANGE;
}

if (parameters.numYAxes == 0) {
// TODO replace with more specific error
return SCPI_ERROR_EXECUTION_ERROR;
}

for (int i = 0; i < parameters.numYAxes; i++) {
if (parameters.yAxes[i].range.min >= parameters.yAxes[i].range.max) {
return SCPI_ERROR_DATA_OUT_OF_RANGE;
}
}
} else {
bool somethingToLog = false;
for (int i = 0; i < CH_NUM; ++i) {
Expand Down Expand Up @@ -339,6 +351,12 @@ int initiateTrace() {

float getValue(int rowIndex, int columnIndex, float *max) {
float value = *(float *)(DLOG_RECORD_BUFFER + (g_recording.dataOffset + (rowIndex * g_recording.parameters.numYAxes + columnIndex) * 4) % DLOG_RECORD_BUFFER_SIZE);

if (g_recording.parameters.yAxisScale == dlog_view::SCALE_LOGARITHMIC) {
float logOffset = 1 - g_recording.parameters.yAxes[columnIndex].range.min;
value = log10f(logOffset + value);
}

*max = value;
return value;
}
Expand Down Expand Up @@ -375,8 +393,8 @@ int startImmediately() {
g_recording.size = 0;
g_recording.pageSize = 480;

g_recording.timeOffset = 0.0f;
g_recording.timeDiv = g_recording.pageSize * g_recording.parameters.period / dlog_view::NUM_HORZ_DIVISIONS;
g_recording.xAxisOffset = 0.0f;
g_recording.xAxisDiv = g_recording.pageSize * g_recording.parameters.period / dlog_view::NUM_HORZ_DIVISIONS;

if (!g_traceInitiated) {
dlog_view::initAxis(g_recording);
Expand All @@ -397,6 +415,7 @@ int startImmediately() {
// meta fields
writeUint8Field(dlog_view::FIELD_ID_X_UNIT, g_recording.parameters.xAxis.unit);
writeFloatField(dlog_view::FIELD_ID_X_STEP, g_recording.parameters.xAxis.step);
writeUint8Field(dlog_view::FIELD_ID_X_SCALE, g_recording.parameters.xAxis.scale);
writeFloatField(dlog_view::FIELD_ID_X_RANGE_MIN, g_recording.parameters.xAxis.range.min);
writeFloatField(dlog_view::FIELD_ID_X_RANGE_MAX, g_recording.parameters.xAxis.range.max);
writeStringField(dlog_view::FIELD_ID_X_LABEL, g_recording.parameters.xAxis.label);
Expand Down Expand Up @@ -439,6 +458,8 @@ int startImmediately() {
}
}

writeUint8Field(dlog_view::FIELD_ID_Y_SCALE, g_recording.parameters.yAxisScale);

for (uint8_t channelIndex = 0; channelIndex < CH_MAX; channelIndex++) {
if (writeChannelFields[channelIndex]) {
Channel &channel = Channel::get(channelIndex);
Expand Down Expand Up @@ -485,21 +506,11 @@ void toggle() {
}

void resetParameters() {
memset(&g_parameters.xAxis, 0, sizeof(dlog_view::XAxis));
memset(&g_parameters.yAxis, 0, sizeof(dlog_view::YAxis));
g_parameters.numYAxes = 0;
memset(&g_parameters.yAxes[0], 0, dlog_view::MAX_NUM_OF_Y_AXES * sizeof(dlog_view::YAxis));

for (int i = 0; i < CH_NUM; ++i) {
g_parameters.logVoltage[i] = 0;
g_parameters.logCurrent[i] = 0;
g_parameters.logPower[i] = 0;
}
memset(&g_parameters, 0, sizeof(g_parameters));

g_parameters.period = PERIOD_DEFAULT;
g_parameters.time = TIME_DEFAULT;
g_parameters.triggerSource = trigger::SOURCE_IMMEDIATE;
g_parameters.filePath[0] = 0;
}

void finishLogging(bool flush) {
Expand Down
Loading

0 comments on commit 2551362

Please sign in to comment.