Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
picsimlab
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
picsimlab
Commits
8edf0a7f
Commit
8edf0a7f
authored
Apr 13, 2024
by
lcgamboa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new: Increase oscilloscope time scale up to 1s/div.
parent
b6a11f2b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
49 deletions
+92
-49
src/lib/oscilloscope.cc
src/lib/oscilloscope.cc
+46
-23
src/lib/oscilloscope.h
src/lib/oscilloscope.h
+6
-8
src/picsimlab4.cc
src/picsimlab4.cc
+36
-17
src/picsimlab4.h
src/picsimlab4.h
+1
-0
src/picsimlab4_d.cc
src/picsimlab4_d.cc
+3
-1
No files found.
src/lib/oscilloscope.cc
View file @
8edf0a7f
...
...
@@ -39,7 +39,7 @@ COscilloscope::COscilloscope() {
triggerlv
=
2.5
;
chpin
[
0
]
=
0
;
chpin
[
1
]
=
1
;
t
offset
=
250
;
s
offset
=
250
;
run
=
1
;
fp
=
0
;
...
...
@@ -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
][
1
][
is
]
=
-
pins
[
1
]
+
((
1.0
*
rand
()
/
RAND_MAX
)
-
0.5
)
*
0.1
;
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
;
WindowCmd
(
PW_MAIN
,
"togglebutton7"
,
PWA_TOGGLEBGETCHECK
,
NULL
,
&
checked
);
if
(
tr
&&
checked
)
{
WindowCmd
(
PW_MAIN
,
"togglebutton6"
,
PWA_TOGGLEBSETCHECK
,
"1"
);
}
is
=
0
;
tr
=
0
;
t
=
0
;
ch
[
0
]
=
&
databuffer
[
fp
][
0
][
toffset
];
ch
[
1
]
=
&
databuffer
[
fp
][
1
][
toffset
];
if
(
tscale
>
30
)
{
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
update
=
1
;
// Request redraw screen
is
=
0
;
}
}
t
+=
Dt
;
// trigger
if
(
usetrigger
)
{
if
(
(
usetrigger
)
&&
(
tscale
<=
30
)
)
{
if
((
!
tr
)
&&
(
is
>=
NPOINTS
/
2
))
{
if
((
pins_
[
tch
]
<
triggerlv
)
&&
(
pins
[
tch
]
>=
triggerlv
))
{
tr
=
1
;
...
...
@@ -378,9 +398,8 @@ void COscilloscope::ReadPreferences(char* name, char* value) {
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
SetMeasure
(
i
,
measures
[
i
]);
}
}
SetBaseTimer
();
}
}
std
::
vector
<
std
::
string
>
COscilloscope
::
WritePreferencesList
(
void
)
{
...
...
@@ -388,7 +407,7 @@ std::vector<std::string> COscilloscope::WritePreferencesList(void) {
std
::
string
line
;
int
created
=
0
;
Oscilloscope
.
WindowCmd
(
PW_MAIN
,
NULL
,
PWA_WINDOWHASCREATED
,
NULL
,
&
created
);
WindowCmd
(
PW_MAIN
,
NULL
,
PWA_WINDOWHASCREATED
,
NULL
,
&
created
);
if
(
created
!=
1
)
{
return
list
;
...
...
@@ -592,7 +611,7 @@ void COscilloscope::SetBaseTimer(void) {
if
(
pboard
->
CpuInitialized
()
==
0
)
return
;
SetDT
(
1.0
/
pboard
->
MGetInstClockFreq
()
);
Dt
=
1.0
/
pboard
->
MGetInstClockFreq
(
);
int
chp
[
2
];
...
...
@@ -641,23 +660,27 @@ void COscilloscope::SetBaseTimer(void) {
}
else
WindowCmd
(
PW_MAIN
,
"combo2"
,
PWA_COMBOSETTEXT
,
"2"
);
float
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_SPINDSETMAX
,
std
::
to_string
(
5
*
tscale
).
c_str
());
float
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
,
...
...
src/lib/oscilloscope.h
View file @
8edf0a7f
...
...
@@ -85,8 +85,9 @@ public:
void
SetChannelPin
(
int
ch
,
int
pin
)
{
chpin
[
ch
]
=
pin
;
};
int
GetTimeOffset
(
void
)
{
return
toffset
;
};
void
SetTimeOffset
(
int
to
)
{
toffset
=
to
;
};
int
GetSampleOffset
(
void
)
{
return
soffset
;
};
void
SetTimeScaleAndOffset
(
float
tscale_
,
float
toffset_
);
int
GetRun
(
void
)
{
return
run
;
};
void
SetRun
(
int
r
)
{
run
=
r
;
};
...
...
@@ -95,13 +96,8 @@ public:
void
SetVMax
(
float
vm
)
{
vmax
=
vm
;
};
void
SetRT
(
double
rt
)
{
Rt
=
rt
;
};
double
GetRT
(
void
)
{
return
Rt
;
};
void
SetDT
(
double
dt
)
{
Dt
=
dt
;
};
double
GetDT
(
void
)
{
return
Dt
;
};
void
Setxz
(
double
xz_
)
{
xz
=
xz_
;
};
double
Getxz
(
void
)
{
return
xz
;
};
void
Reset
(
void
);
...
...
@@ -127,7 +123,7 @@ private:
int
usetrigger
;
double
triggerlv
;
int
tch
;
// trigger channel
int
t
offset
;
int
s
offset
;
int
chpin
[
2
];
double
databuffer
[
2
][
2
][
NPOINTS
];
// flip buffers + 2 channels + 700 points
int
fp
;
// actual flip buffer
...
...
@@ -142,6 +138,8 @@ private:
int
measures
[
5
];
float
vmax
;
double
xz
;
float
tscale
;
float
toffset
;
};
extern
COscilloscope
Oscilloscope
;
...
...
src/picsimlab4.cc
View file @
8edf0a7f
...
...
@@ -119,6 +119,10 @@ void CPWindow4::DrawScreen(void) {
}
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
if
(
Oscilloscope
.
GetUseTrigger
())
{
if
(
combo1
.
GetText
().
compare
(
"1"
)
==
0
)
...
...
@@ -139,9 +143,8 @@ void CPWindow4::DrawScreen(void) {
}
// draw toffset level
draw1
.
Canvas
.
SetFgColor
(
255
,
255
,
0
);
nivel
[
2
]
=
((
WMAX
-
Oscilloscope
.
Get
Tim
eOffset
())
*
xz
+
xz
)
-
((
NPOINTS
*
(
xz
-
1.0
))
/
4.0
);
nivel
[
2
]
=
((
WMAX
-
Oscilloscope
.
Get
Sampl
eOffset
())
*
xz
+
xz
)
-
((
NPOINTS
*
(
xz
-
1.0
))
/
4.0
);
pts
[
0
].
y
=
1
;
pts
[
0
].
x
=
nivel
[
2
]
-
3
;
pts
[
1
].
y
=
1
+
3
;
...
...
@@ -291,20 +294,38 @@ void CPWindow4::draw1_EvMouseButtonClick(CControl* control, unsigned int button,
}
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
)
{
Oscilloscope
.
Setxz
(
Oscilloscope
.
GetDT
()
/
Oscilloscope
.
GetRT
());
}
else
Oscilloscope
.
Setxz
(
1.0
);
if
(
inc
<
0.001000
)
{
spind5
.
SetInc
(
0.001000
);
}
else
if
(
inc
>=
1
)
{
spind5
.
SetInc
(
5
);
}
else
if
(
inc
>=
0.1
)
{
spind5
.
SetInc
(
0.5
);
}
else
{
spind5
.
SetInc
(
0.005
);
}
spind6
.
SetMin
(
-
5
*
spind5
.
GetValue
());
spind6
.
SetMax
(
5
*
spind5
.
GetValue
());
Oscilloscope
.
SetTimeScaleAndOffset
(
spind5
.
GetValue
(),
spind6
.
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
);
// printf("Dt=%e Rt=%e Rt/Dt=%f xz=%f\n",Dt,Rt,Rt/Dt,xz);
Oscilloscope
.
SetTimeScaleAndOffset
(
spind5
.
GetValue
(),
spind6
.
GetValue
());
}
void
CPWindow4
::
togglebutton5_EvOnToggleButton
(
CControl
*
control
)
{
...
...
@@ -318,7 +339,8 @@ void CPWindow4::spind7_EvOnChangeSpinDouble(CControl* control) {
void
CPWindow4
::
timer1_EvOnTime
(
CControl
*
control
)
{
static
int
count
=
0
;
if
(
Oscilloscope
.
GetUpdate
())
{
update_pos
=
Oscilloscope
.
GetUpdate
();
if
(
update_pos
)
{
Oscilloscope
.
SetUpdate
(
0
);
count
++
;
...
...
@@ -337,6 +359,7 @@ void CPWindow4::timer1_EvOnTime(CControl* control) {
}
}
DrawScreen
();
update_pos
=
0
;
#ifndef _WIN_
Draw
();
#endif
...
...
@@ -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
void
CPWindow4
::
button3_EvMouseButtonClick
(
CControl
*
control
,
unsigned
int
button
,
unsigned
int
x
,
unsigned
int
y
,
...
...
src/picsimlab4.h
View file @
8edf0a7f
...
...
@@ -125,6 +125,7 @@ public:
private:
CButton
*
ctrl
;
int
update_pos
;
};
extern
CPWindow4
Window4
;
...
...
src/picsimlab4_d.cc
View file @
8edf0a7f
...
...
@@ -126,7 +126,7 @@ CPWindow4::CPWindow4(void) {
spind5
.
SetPopupMenu
(
NULL
);
spind5
.
SetValue
(
10.000000
);
spind5
.
SetMin
(
0.001000
);
spind5
.
SetMax
(
2
00.000000
);
spind5
.
SetMax
(
10
00.000000
);
spind5
.
SetInc
(
0.001000
);
spind5
.
SetDigits
(
3
);
spind5
.
EvOnChangeSpinDouble
=
EVONCHANGESPINDOUBLE
&
CPWindow4
::
spind5_EvOnChangeSpinDouble
;
...
...
@@ -694,4 +694,6 @@ CPWindow4::CPWindow4(void) {
// lxrad automatic generated block end, don't edit above!
button1
.
SetColor
(
255
,
0
,
0
);
button2
.
SetColor
(
0
,
255
,
0
);
update_pos
=
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment