Commit 8edf0a7f authored by lcgamboa's avatar lcgamboa

new: Increase oscilloscope time scale up to 1s/div.

parent b6a11f2b
...@@ -39,7 +39,7 @@ COscilloscope::COscilloscope() { ...@@ -39,7 +39,7 @@ COscilloscope::COscilloscope() {
triggerlv = 2.5; triggerlv = 2.5;
chpin[0] = 0; chpin[0] = 0;
chpin[1] = 1; chpin[1] = 1;
toffset = 250; soffset = 250;
run = 1; run = 1;
fp = 0; fp = 0;
...@@ -84,26 +84,46 @@ void COscilloscope::SetSample(void) { ...@@ -84,26 +84,46 @@ void COscilloscope::SetSample(void) {
databuffer[fp][0][is] = -pins[0] + ((1.0 * rand() / RAND_MAX) - 0.5) * 0.1; databuffer[fp][0][is] = -pins[0] + ((1.0 * rand() / RAND_MAX) - 0.5) * 0.1;
databuffer[fp][1][is] = -pins[1] + ((1.0 * rand() / RAND_MAX) - 0.5) * 0.1; databuffer[fp][1][is] = -pins[1] + ((1.0 * rand() / RAND_MAX) - 0.5) * 0.1;
is++; is++;
if (is >= NPOINTS) // buffer full
if ((tscale > 30) && is) {
databuffer[!fp][0][is - 1] = databuffer[fp][0][is - 1];
databuffer[!fp][1][is - 1] = databuffer[fp][1][is - 1];
ch[0] = &databuffer[!fp][0][0];
ch[1] = &databuffer[!fp][1][0];
update = is; // Request redraw screen
if (is >= WMAX) {
t = 0;
fp = !fp; // togle fp
is = 0;
}
} else if (is >= NPOINTS) // buffer full
{ {
int checked; int checked;
WindowCmd(PW_MAIN, "togglebutton7", PWA_TOGGLEBGETCHECK, NULL, &checked); WindowCmd(PW_MAIN, "togglebutton7", PWA_TOGGLEBGETCHECK, NULL, &checked);
if (tr && checked) { if (tr && checked) {
WindowCmd(PW_MAIN, "togglebutton6", PWA_TOGGLEBSETCHECK, "1"); WindowCmd(PW_MAIN, "togglebutton6", PWA_TOGGLEBSETCHECK, "1");
} }
is = 0;
tr = 0; tr = 0;
t = 0; t = 0;
ch[0] = &databuffer[fp][0][toffset]; if (tscale > 30) {
ch[1] = &databuffer[fp][1][toffset]; ch[0] = &databuffer[fp][0][0];
ch[1] = &databuffer[fp][1][0];
update = is; // Request redraw screen
} else {
ch[0] = &databuffer[fp][0][soffset];
ch[1] = &databuffer[fp][1][soffset];
update = is - soffset + 1; // Request redraw screen
}
fp = !fp; // togle fp fp = !fp; // togle fp
update = 1; // Request redraw screen is = 0;
} }
} }
t += Dt; t += Dt;
// trigger // trigger
if (usetrigger) { if ((usetrigger) && (tscale <= 30)) {
if ((!tr) && (is >= NPOINTS / 2)) { if ((!tr) && (is >= NPOINTS / 2)) {
if ((pins_[tch] < triggerlv) && (pins[tch] >= triggerlv)) { if ((pins_[tch] < triggerlv) && (pins[tch] >= triggerlv)) {
tr = 1; tr = 1;
...@@ -378,9 +398,8 @@ void COscilloscope::ReadPreferences(char* name, char* value) { ...@@ -378,9 +398,8 @@ void COscilloscope::ReadPreferences(char* name, char* value) {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
SetMeasure(i, measures[i]); SetMeasure(i, measures[i]);
} }
}
SetBaseTimer(); SetBaseTimer();
}
} }
std::vector<std::string> COscilloscope::WritePreferencesList(void) { std::vector<std::string> COscilloscope::WritePreferencesList(void) {
...@@ -388,7 +407,7 @@ std::vector<std::string> COscilloscope::WritePreferencesList(void) { ...@@ -388,7 +407,7 @@ std::vector<std::string> COscilloscope::WritePreferencesList(void) {
std::string line; std::string line;
int created = 0; int created = 0;
Oscilloscope.WindowCmd(PW_MAIN, NULL, PWA_WINDOWHASCREATED, NULL, &created); WindowCmd(PW_MAIN, NULL, PWA_WINDOWHASCREATED, NULL, &created);
if (created != 1) { if (created != 1) {
return list; return list;
...@@ -592,7 +611,7 @@ void COscilloscope::SetBaseTimer(void) { ...@@ -592,7 +611,7 @@ void COscilloscope::SetBaseTimer(void) {
if (pboard->CpuInitialized() == 0) if (pboard->CpuInitialized() == 0)
return; return;
SetDT(1.0 / pboard->MGetInstClockFreq()); Dt = 1.0 / pboard->MGetInstClockFreq();
int chp[2]; int chp[2];
...@@ -641,23 +660,27 @@ void COscilloscope::SetBaseTimer(void) { ...@@ -641,23 +660,27 @@ void COscilloscope::SetBaseTimer(void) {
} else } else
WindowCmd(PW_MAIN, "combo2", PWA_COMBOSETTEXT, "2"); WindowCmd(PW_MAIN, "combo2", PWA_COMBOSETTEXT, "2");
float tscale;
WindowCmd(PW_MAIN, "spind5", PWA_SPINDGETVALUE, NULL, &tscale); WindowCmd(PW_MAIN, "spind5", PWA_SPINDGETVALUE, NULL, &tscale);
SetRT((tscale * 1e-3 * 10) / WMAX);
if ((GetRT() / GetDT()) < 1.0) {
xz = GetDT() / GetRT();
} else
xz = 1.0;
WindowCmd(PW_MAIN, "spind6", PWA_SPINDSETMIN, std::to_string(-5 * tscale).c_str()); WindowCmd(PW_MAIN, "spind6", PWA_SPINDSETMIN, std::to_string(-5 * tscale).c_str());
WindowCmd(PW_MAIN, "spind6", PWA_SPINDSETMAX, std::to_string(5 * tscale).c_str()); WindowCmd(PW_MAIN, "spind6", PWA_SPINDSETMAX, std::to_string(5 * tscale).c_str());
float toffset;
WindowCmd(PW_MAIN, "spind6", PWA_SPINDGETVALUE, NULL, &toffset); WindowCmd(PW_MAIN, "spind6", PWA_SPINDGETVALUE, NULL, &toffset);
Oscilloscope.SetTimeOffset((WMAX / 2) - (((WMAX / 2) * toffset) / (5 * tscale))); SetTimeScaleAndOffset(tscale, toffset);
}
void COscilloscope::SetTimeScaleAndOffset(float tscale_, float toffset_) {
tscale = tscale_;
toffset = toffset_;
Rt = (tscale * 1e-3 * 10) / WMAX;
if ((Rt / Dt) < 1.0) {
xz = Dt / Rt;
} else
xz = 1.0;
soffset = (WMAX / 2) - (((WMAX / 2) * toffset) / (5 * tscale));
} }
int COscilloscope::WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, int COscilloscope::WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action,
......
...@@ -85,8 +85,9 @@ public: ...@@ -85,8 +85,9 @@ public:
void SetChannelPin(int ch, int pin) { chpin[ch] = pin; }; void SetChannelPin(int ch, int pin) { chpin[ch] = pin; };
int GetTimeOffset(void) { return toffset; }; int GetSampleOffset(void) { return soffset; };
void SetTimeOffset(int to) { toffset = to; };
void SetTimeScaleAndOffset(float tscale_, float toffset_);
int GetRun(void) { return run; }; int GetRun(void) { return run; };
void SetRun(int r) { run = r; }; void SetRun(int r) { run = r; };
...@@ -95,13 +96,8 @@ public: ...@@ -95,13 +96,8 @@ public:
void SetVMax(float vm) { vmax = vm; }; void SetVMax(float vm) { vmax = vm; };
void SetRT(double rt) { Rt = rt; };
double GetRT(void) { return Rt; }; double GetRT(void) { return Rt; };
void SetDT(double dt) { Dt = dt; };
double GetDT(void) { return Dt; }; double GetDT(void) { return Dt; };
void Setxz(double xz_) { xz = xz_; };
double Getxz(void) { return xz; }; double Getxz(void) { return xz; };
void Reset(void); void Reset(void);
...@@ -127,7 +123,7 @@ private: ...@@ -127,7 +123,7 @@ private:
int usetrigger; int usetrigger;
double triggerlv; double triggerlv;
int tch; // trigger channel int tch; // trigger channel
int toffset; int soffset;
int chpin[2]; int chpin[2];
double databuffer[2][2][NPOINTS]; // flip buffers + 2 channels + 700 points double databuffer[2][2][NPOINTS]; // flip buffers + 2 channels + 700 points
int fp; // actual flip buffer int fp; // actual flip buffer
...@@ -142,6 +138,8 @@ private: ...@@ -142,6 +138,8 @@ private:
int measures[5]; int measures[5];
float vmax; float vmax;
double xz; double xz;
float tscale;
float toffset;
}; };
extern COscilloscope Oscilloscope; extern COscilloscope Oscilloscope;
......
...@@ -119,6 +119,10 @@ void CPWindow4::DrawScreen(void) { ...@@ -119,6 +119,10 @@ void CPWindow4::DrawScreen(void) {
} }
draw1.Canvas.SetLineWidth(1); draw1.Canvas.SetLineWidth(1);
// draw update cursor
draw1.Canvas.SetFgColor(250, 250, 50);
draw1.Canvas.Line(update_pos, 0, update_pos, HMAX);
// draw trigger level // draw trigger level
if (Oscilloscope.GetUseTrigger()) { if (Oscilloscope.GetUseTrigger()) {
if (combo1.GetText().compare("1") == 0) if (combo1.GetText().compare("1") == 0)
...@@ -139,9 +143,8 @@ void CPWindow4::DrawScreen(void) { ...@@ -139,9 +143,8 @@ void CPWindow4::DrawScreen(void) {
} }
// draw toffset level // draw toffset level
draw1.Canvas.SetFgColor(255, 255, 0); draw1.Canvas.SetFgColor(255, 255, 0);
nivel[2] = ((WMAX - Oscilloscope.GetTimeOffset()) * xz + xz) - ((NPOINTS * (xz - 1.0)) / 4.0); nivel[2] = ((WMAX - Oscilloscope.GetSampleOffset()) * xz + xz) - ((NPOINTS * (xz - 1.0)) / 4.0);
pts[0].y = 1; pts[0].y = 1;
pts[0].x = nivel[2] - 3; pts[0].x = nivel[2] - 3;
pts[1].y = 1 + 3; pts[1].y = 1 + 3;
...@@ -291,20 +294,38 @@ void CPWindow4::draw1_EvMouseButtonClick(CControl* control, unsigned int button, ...@@ -291,20 +294,38 @@ void CPWindow4::draw1_EvMouseButtonClick(CControl* control, unsigned int button,
} }
void CPWindow4::spind5_EvOnChangeSpinDouble(CControl* control) { void CPWindow4::spind5_EvOnChangeSpinDouble(CControl* control) {
// spind5.SetMin ((Dt*WMAX)/10e-3); spind6.SetMin(-5 * spind5.GetValue());
spind6.SetMax(5 * spind5.GetValue());
Oscilloscope.SetRT((spind5.GetValue() * 1e-3 * 10) / WMAX); float inc = spind5.GetValue() / 100.0;
if ((Oscilloscope.GetRT() / Oscilloscope.GetDT()) < 1.0) { if (inc < 0.001000) {
Oscilloscope.Setxz(Oscilloscope.GetDT() / Oscilloscope.GetRT()); spind5.SetInc(0.001000);
} else } else if (inc >= 1) {
Oscilloscope.Setxz(1.0); spind5.SetInc(5);
} else if (inc >= 0.1) {
spind5.SetInc(0.5);
} else {
spind5.SetInc(0.005);
}
spind6.SetMin(-5 * spind5.GetValue()); Oscilloscope.SetTimeScaleAndOffset(spind5.GetValue(), spind6.GetValue());
spind6.SetMax(5 * spind5.GetValue()); }
void CPWindow4::spind6_EvOnChangeSpinDouble(CControl* control) {
float inc = fabs(spind6.GetValue() / 100.0);
if (inc < 0.001000) {
spind6.SetInc(0.001000);
} else if (inc >= 1) {
spind6.SetInc(5);
} else if (inc >= 0.1) {
spind6.SetInc(0.5);
} else {
spind6.SetInc(0.005);
}
spind6_EvOnChangeSpinDouble(this); Oscilloscope.SetTimeScaleAndOffset(spind5.GetValue(), spind6.GetValue());
// printf("Dt=%e Rt=%e Rt/Dt=%f xz=%f\n",Dt,Rt,Rt/Dt,xz);
} }
void CPWindow4::togglebutton5_EvOnToggleButton(CControl* control) { void CPWindow4::togglebutton5_EvOnToggleButton(CControl* control) {
...@@ -318,7 +339,8 @@ void CPWindow4::spind7_EvOnChangeSpinDouble(CControl* control) { ...@@ -318,7 +339,8 @@ void CPWindow4::spind7_EvOnChangeSpinDouble(CControl* control) {
void CPWindow4::timer1_EvOnTime(CControl* control) { void CPWindow4::timer1_EvOnTime(CControl* control) {
static int count = 0; static int count = 0;
if (Oscilloscope.GetUpdate()) { update_pos = Oscilloscope.GetUpdate();
if (update_pos) {
Oscilloscope.SetUpdate(0); Oscilloscope.SetUpdate(0);
count++; count++;
...@@ -337,6 +359,7 @@ void CPWindow4::timer1_EvOnTime(CControl* control) { ...@@ -337,6 +359,7 @@ void CPWindow4::timer1_EvOnTime(CControl* control) {
} }
} }
DrawScreen(); DrawScreen();
update_pos = 0;
#ifndef _WIN_ #ifndef _WIN_
Draw(); Draw();
#endif #endif
...@@ -375,10 +398,6 @@ void CPWindow4::_EvOnHide(CControl* control) { ...@@ -375,10 +398,6 @@ void CPWindow4::_EvOnHide(CControl* control) {
} }
} }
void CPWindow4::spind6_EvOnChangeSpinDouble(CControl* control) {
Oscilloscope.SetTimeOffset((WMAX / 2) - (((WMAX / 2) * spind6.GetValue()) / (5 * spind5.GetValue())));
}
// autoset // autoset
void CPWindow4::button3_EvMouseButtonClick(CControl* control, unsigned int button, unsigned int x, unsigned int y, void CPWindow4::button3_EvMouseButtonClick(CControl* control, unsigned int button, unsigned int x, unsigned int y,
......
...@@ -125,6 +125,7 @@ public: ...@@ -125,6 +125,7 @@ public:
private: private:
CButton* ctrl; CButton* ctrl;
int update_pos;
}; };
extern CPWindow4 Window4; extern CPWindow4 Window4;
......
...@@ -126,7 +126,7 @@ CPWindow4::CPWindow4(void) { ...@@ -126,7 +126,7 @@ CPWindow4::CPWindow4(void) {
spind5.SetPopupMenu(NULL); spind5.SetPopupMenu(NULL);
spind5.SetValue(10.000000); spind5.SetValue(10.000000);
spind5.SetMin(0.001000); spind5.SetMin(0.001000);
spind5.SetMax(200.000000); spind5.SetMax(1000.000000);
spind5.SetInc(0.001000); spind5.SetInc(0.001000);
spind5.SetDigits(3); spind5.SetDigits(3);
spind5.EvOnChangeSpinDouble = EVONCHANGESPINDOUBLE & CPWindow4::spind5_EvOnChangeSpinDouble; spind5.EvOnChangeSpinDouble = EVONCHANGESPINDOUBLE & CPWindow4::spind5_EvOnChangeSpinDouble;
...@@ -694,4 +694,6 @@ CPWindow4::CPWindow4(void) { ...@@ -694,4 +694,6 @@ CPWindow4::CPWindow4(void) {
// lxrad automatic generated block end, don't edit above! // lxrad automatic generated block end, don't edit above!
button1.SetColor(255, 0, 0); button1.SetColor(255, 0, 0);
button2.SetColor(0, 255, 0); button2.SetColor(0, 255, 0);
update_pos = 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment