Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
redpitaya-MCPHA
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Günter Quast
redpitaya-MCPHA
Commits
980aea97
Commit
980aea97
authored
1 year ago
by
Guenter Quast
Browse files
Options
Downloads
Patches
Plain Diff
mcpha.py: better factorization
parent
5a314ab4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mcpha.py
+37
-22
37 additions, 22 deletions
mcpha.py
with
37 additions
and
22 deletions
mcpha.py
+
37
−
22
View file @
980aea97
#!/usr/bin/env python3
"""
mcpha: Multi-Channel Pulse Height Analyser
"""
mcpha: Multi-Channel Pulse Height Analyser
Client script for displaying the output of the MCPHA application
running on a RedPitaya FPGA board
Modified version of mcphy.py by Pavel Demin
Client script for displaying the output of the MCPHA application
running on a RedPitaya FPGA board
"""
# differences w.r.t. original version marked with " # !gq"
import
argparse
# !gq
import
os
...
...
@@ -57,7 +61,10 @@ class MCPHA(QMainWindow, Ui_MCPHA):
# !gq get command line arguments
self
.
parse_args
()
self
.
get_physical_units
()
# !gq end
# initialize variables
self
.
idle
=
True
self
.
waiting
=
[
False
for
i
in
range
(
3
)]
...
...
@@ -87,7 +94,6 @@ class MCPHA(QMainWindow, Ui_MCPHA):
self
.
rateValue
.
lineEdit
().
setAlignment
(
Qt
.
AlignRight
)
for
i
in
range
(
self
.
rateValue
.
count
()):
self
.
rateValue
.
setItemData
(
i
,
Qt
.
AlignRight
,
Qt
.
TextAlignmentRole
)
# !gq self.rateValue.setCurrentIndex(0)
self
.
rateValue
.
setCurrentIndex
(
1
)
self
.
rateValue
.
currentIndexChanged
.
connect
(
self
.
set_rate
)
# address validator
...
...
@@ -110,7 +116,7 @@ class MCPHA(QMainWindow, Ui_MCPHA):
self
.
readTimer
=
QTimer
(
self
)
self
.
readTimer
.
timeout
.
connect
(
self
.
read_timeout
)
# !gq set defaults
# !gq set defaults
and units
self
.
osc
.
levelValue
.
setValue
(
self
.
trigger_level
)
# !gq end
...
...
@@ -126,6 +132,14 @@ class MCPHA(QMainWindow, Ui_MCPHA):
self
.
ip_address
=
args
.
ip_address
# !gq end
def
get_physical_units
(
self
):
"""
get physical units corresponding to ADC units and channel numbers
"""
# Voltages: 4096 channels/Volt
self
.
adc_unit
=
1000
/
4096
# time per sample at sampling rate of 125 MHz / decimation_factor
self
.
time_bin
=
0.008
def
start
(
self
):
self
.
socket
.
connectToHost
(
self
.
addrValue
.
text
(),
1001
)
self
.
startTimer
.
start
(
5000
)
...
...
@@ -433,12 +447,12 @@ class HstDisplay(QWidget, Ui_HstDisplay):
def
adc2mV
(
self
,
c
):
"""
convert adc-count to Voltage in mV
"""
return
c
*
1000
/
4096
*
self
.
factor
return
c
*
self
.
mcpha
.
adc_unit
*
self
.
factor
def
mV2adc
(
self
,
v
):
"""
convert voltage in mV to adc-count
"""
return
v
*
4096
/
(
1000
*
self
.
factor
)
return
v
/
(
self
.
mcpha
.
adc_unit
*
self
.
factor
)
# !gq end helper
def
start
(
self
):
...
...
@@ -687,8 +701,8 @@ class OscDisplay(QWidget, Ui_OscDisplay):
self
.
ax
=
self
.
figure
.
add_subplot
(
111
)
self
.
ax
.
grid
()
self
.
ax
.
set_ylim
(
-
4500
,
4500
)
self
.
ax
.
set_xlabel
(
"
time bin
"
)
self
.
ax
.
set_ylabel
(
"
ADC
co
unts
"
)
self
.
ax
.
set_xlabel
(
"
sample number
"
)
self
.
ax
.
set_ylabel
(
"
ADC un
i
ts
"
)
# gq
self
.
ax_x2
=
self
.
ax
.
secondary_xaxis
(
'
top
'
,
functions
=
(
self
.
tbin2t
,
self
.
t2tbin
))
self
.
ax_x2
.
set_xlabel
(
"
time [µs]
"
,
color
=
'
grey
'
,
size
=
'
x-large
'
)
...
...
@@ -739,26 +753,26 @@ class OscDisplay(QWidget, Ui_OscDisplay):
def
tbin2t
(
self
,
tbin
):
"""
convert time bin to time in µs
"""
i
df
=
self
.
mcpha
.
rateValue
.
currentIndex
()
df
=
1
if
i
df
==
-
1
else
MCPHA
.
rates
[
idf
]
return
(
tbin
-
self
.
pre
)
*
df
*
0.008
df
i
=
self
.
mcpha
.
rateValue
.
currentIndex
()
# current decimation factor index
df
=
4
if
df
i
==
-
1
else
MCPHA
.
rates
[
dfi
]
# decimation factor
return
(
tbin
-
self
.
pre
)
*
self
.
mcpha
.
time_bin
*
df
def
t2tbin
(
self
,
t
):
"""
convert time in µs to time bin
"""
i
df
=
self
.
mcpha
.
rateValue
.
currentIndex
()
df
=
1
if
i
df
==
-
1
else
MCPHA
.
rates
[
idf
]
return
t
/
(
df
*
0.008
)
+
self
.
pre
df
i
=
self
.
mcpha
.
rateValue
.
currentIndex
()
# current decimation factor index
df
=
4
if
df
i
==
-
1
else
MCPHA
.
rates
[
dfi
]
# decimation factor
return
t
/
(
self
.
mcpha
.
time_bin
*
df
)
+
self
.
pre
def
adc2mV
(
self
,
c
):
"""
convert adc-count to Voltage in mV
"""
return
c
*
1000
/
4096
return
c
*
self
.
mcpha
.
adc_unit
def
mV2adc
(
self
,
v
):
"""
convert voltage in mV to adc-count
"""
return
v
*
4096
/
1000
return
v
/
self
.
mcpha
.
adc_unit
# gq end
def
start
(
self
):
...
...
@@ -888,14 +902,15 @@ class GenDisplay(QWidget, Ui_GenDisplay):
# gq
def
adc2mV
(
self
,
c
):
"""
convert adc-count to Voltage in mV
"""
convert adc-count to Voltage in mV
!!! there is a factor of two betwenn channel definition here and in hstDisplay !
"""
return
c
*
500
/
4096
return
c
*
self
.
mcpha
.
adc_unit
/
2
def
mV2adc
(
self
,
v
):
"""
convert voltage in mV to adc-count
"""
return
v
*
4096
/
500
return
v
*
self
.
mcpha
.
adc_unit
*
2
# gq end
def
start
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment