Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
1 result

Target

Select target project
  • guenter.quast/redpitaya-mcpha
  • ustta/redpitaya-mcpha
2 results
Select Git revision
  • main
  • ustta-main-patch-84861
2 results
Show changes
Commits on Source (36)
3-Feb-2024 initial commit
03-Feb-2024 initial commit
11-Apr-2024 added helper script peakFitter.py to fit peaks to spectrum
02-Jun-2024 added callback mechanism to analyse and store oscillogram data,
helper script read_npy.py to read exported data
10-Jun-2024 added mimoCoRB interface redP_mimoCoRB.py
16-Jun-2024 new app redPdaq.py for MCPHA and DAQ
......@@ -7,7 +7,7 @@ for physics laboratory courses
The RedPitaya is a small, credit-card sized single board computer with a dual-core ARM Cortex-A processor
and a XILINX Zynq 7010 FPGA. The board contains two fast ADCs and two DACs with 14 bit resolution running
at a sampling frequency of 125 MHz. Extension connector provide general purpose IO pins with
at a sampling frequency of 125 MHz. Extension connectors provide general purpose IO pins with
slow analog inputs and outputs and support for serial bus interfaces like I²C, SPI and UART.
The system runs under Ubuntu Linux, which provides network access and supports a wide range of
applications running on the board.
......@@ -15,101 +15,113 @@ applications running on the board.
Many laboratory instruments like oscilloscopes, logic analyzers, Bode plotters or a multi-channel pulse-height
analyzer can be realized on this board by simply changing the FPGA image and the Linux application.
![Image of the RedPitaya board (source: `redpitaya.com`).](images/RedPitayaBoard-1024x526.png)
![Image of the RedPitaya board (source: `redpitaya.com`).](images/RedPitayaBoard-1024x526.png){width=800px}
The MCPHA application for the RedPitaya by Pavel Demin provides a multi-channel pulse-height analyzer and
consists of an FPGA image and a server process running on the RedPitaya board. A client script controls
the server and pulls the data to the client computer.
The MCPHA application by Pavel Demin provides a multi-channel pulse-height analyzer as
well as an oscilloscope capable of transferring large data rates reaching the theoretical
limit of the Gbit ethernet port. The package consists of an FPGA image and a server process
running on the RedPitaya board. A client script controls the server and pulls the data
to the client computer.
The package provided here extends the original one by a possibility to record or export
waveform data and provides helper scripts to analyze recorded spectra or to read exported
waveform data. An interface to the buffer manager *mimoCoRB* for buffering and parallel
processing of large date volumes is also provided.
This package is in use for gamma-ray spectrography experiments in physics laboratory
courses at the Faculty of Physics at Karlsruhe Institute of Technology.
### Files:
- *README.md* this documentation
- *mchpa.py* the client program
- *mcpha.ui* qt5 graphical user interface for *mcpha* application
- *mcpha_gen.ui* qt5 tab for generator
- *mcpha_osc.ui* qt5 tab for oscilloscope
- *mcpha_hst.ui* qt5 tab for histogram display
- *mcpha_log.ui* qt5 tab for message display
- *rePosci.py* a simple oscilloscope and daq client using the mcpha server
- *rpControl.ui* qt5 tab for *redPosci* application
- *mcpha_daq.ui* qt5 tab for oscilloscope with daq mode
- *README.md* this documentation
- *mchpa.py* client program
- *examples/* recorded spectra
- *examples/peakFitter.py* code to find and fit peaks in spectum data
- *mcpha.ui* qt5 graphical user interface for *mcpha* application
- *mcpha_gen.ui* qt5 tab for generator
- *mcpha_osc.ui* qt5 tab for oscilloscope
- *mcpha_hst.ui* qt5 tab for histogram display
- *mcpha_log.ui* qt5 tab for message display
- RP-image directory with all files necessary to boot a RedPitaya and start the server
application based on the "small, simple and secure" linux distribution
[alpine-3.18-armv7-20240204](https://github.com/pavel-demin/red-pitaya-notes/releases/tag/20240204)
[alpine-3.18-armv7-20240204](https://github.com/pavel-demin/red-pitaya-notes/releases/tag/20240204)
- utility scripts in the sub-directory *helpers/*
## Credit:
This project essentially is a fork of the sub-directory *projects/mcpha* in a project by
[Pavel Demin, [red-pitaya-notes](https://pavel-demin.github.io/red-pitaya-notes).
## Multi-Channel Pulse-Height Analyzer for the RedPitaya FPGA board
A multi-channel pulse-height analyzer produces a histogram of the heights of pulses present in a signal supplied to the input. The MCPHA project uses the FPGA on the RedPitaya board to process the digitized input signal at very high rates. A server process on the ARM processor of the RedPitaya communicates with a client process via network. The client communicates with the server, starts and stops data recording and receives and displays the data. The client is also responsible for saving data to files.
The original version by Pavel Demin has been modified to better meet the usual standards for graphics
displays in physics. A command line interface has also been added to allow easy control of important
parameters at program start.
A special version of the original oscilloscope display, *redPosci.py*, with fast transfer of data to the client for data acquisition applications is also contained in this extended package.
*mcpha.py* is a fork of the sub-directory *projects/mcpha* in a project by
Pavel Demin, [red-pitaya-notes](https://pavel-demin.github.io/red-pitaya-notes).
*redPdaq.py* is an extension of the oscilloscope class enabling fast restart
and data export.
### Basic functionality
The *mcpha* application uses a rather simple, but straight-forward algorithm to determine the
height of pulses. When the signal voltage of a supplied input signal starts rising, the corresponding
ADC count is stored. A second ADC value is stored when the signal level starts falling again, and the difference of these two ADC values is histogrammed. The histogram is transferred to the client upon request.
# Users' Guide
The *mcpha* application also contains a signal generator that runs independently and parallel to the
pulse-height analyzer. It provides configurable signal shapes and signal rates at the *out1* connector
of the RedPitaya board. Connecting *out1* with a (short) cable to one of the inputs *in1* or *in2*
provides input signals that can be be used to familiarize with the functionality and to benchmark
the performance.
## Multi-Channel Pulse-Height Analyzer for the RedPitaya FPGA board
An oscilloscope with very basic functionality to set the trigger level and direction is also provided.
The timing is controlled by the so-called decimation factor that can be adjusted using the control
in the upper right corner of the graphical window. The RedPitaya samples data at a constant rate
of 125 MHz, and the decimation factor determines how many samples are averaged over and stored
in the internal ring buffer. This reduces the effective sampling rate accordingly. Only decimation
factors corresponding to powers of two are allowed. An example of randomly occurring exponential
signal pulses at an average rate of 10 kHz with a fall time of 10 µs is shown below; there is significant
A multi-channel pulse-height analyzer produces a histogram of the heights of pulses present
in a signal supplied to the input. The MCPHA project uses the FPGA on the RedPitaya board
to process the digitized input signal at very high rates. A server process on the ARM
processor of the RedPitaya communicates with a client process via network. The client
communicates with the server, starts and stops data recording and receives and displays
the data. The client is also responsible for saving data to files.
The original version by Pavel Demin has been modified to better meet the usual standards
for graphics displays in physics. A command line interface has also been added to allow
easy control of important parameters at program start.
A special version of the original oscilloscope display, *redPdaq.py*, with fast transfer
of data to the client for data acquisition applications is also contained in this extended
package.
### Basic functionality
The *mcpha* application uses a rather simple, but straight-forward algorithm to determine
the height of pulses. When the signal voltage of a supplied input signal starts rising,
the corresponding ADC count is stored. A second ADC value is stored when the signal level
starts falling again, and the difference of these two ADC values is histogrammed. The
histogram is transferred to the client upon request.
The *mcpha* application also contains a signal generator that runs independently and parallel
to the pulse-height analyzer. It provides configurable signal shapes and signal rates at the
*out1* connector of the RedPitaya board. Connecting *out1* with a (short) cable to one or both
of the inputs *in1* or *in2* provides input signals that can be be used to familiarize with
the functionality and to benchmark the performance.
An oscilloscope with very basic functionality to set the trigger level and direction is also
provided. The rate of samples transferred to the client is controlled by the so-called decimation
factor that can be adjusted using the control in the upper right corner of the graphical window.
The RedPitaya board samples data at a constant rate of 125 MHz, and the decimation factor determines
how many samples are averaged over and stored in the internal ring buffer. This reduces the e
ffective sampling rate accordingly. Only decimation factors corresponding to powers of two are
allowed. An example of randomly occurring exponential signal pulses at an average rate of 10 kHz
with a fall time of 10 µs is shown below; there is significant
signal overlap in this case, making pulse-height detection more complex.
![Oscilloscope display of signals with a fall time of 10µs at an average rate of 10 kHz](images/oscilloscope_10mus10kHz.png)
![Oscilloscope display of signals with a fall time of 10µs at an average rate of 10 kHz](images/oscilloscope_10mus10kHz.png){width=800px}
A spectrum of such pulses is shown below for input pulses at multiples of 62.5 mV between 62.5 mV
and 500 mV. The overlap of signal pulses leads to wrong pulse-height assignments below the actual
voltage and to entries above 500 mV when pulses become indistinguishable and therefore add up
to a single detected pulse.
![Spectrum signals with a fall time of 10 µs at an average rate of 10 kHz](images/spectrum_10mus10kHz.png)
![Spectrum signals with a fall time of 10 µs at an average rate of 10 kHz](images/spectrum_10mus10kHz.png){width=800px}
Note that spectra and waveforms are plotted with a very large number of channels, well exceeding
the resolution of a computer display. It is therefore possible to use the looking-glass button
of the *matplotlib*window to mark regions to zoom in for a detailed inspection of the data.
## Oscilloscope and data recorder
The script *redPosci.py* relies on the same server and FPGA image as the pulse-height analyzer.
The *oscilloscope* and *generator* tabs provide the same functionality as in *mcpha.py*.
In addition, however, there is a button "*Start DAQ*" to run the data acquisition for the the
oscilloscope independently of the Qt timing loop, i. e. in continuous mode. As soon as data is
received by the client, the oscilloscope is restarted. A dummy routine
*processData()* ist provided as an illustration; right now, it shows a graphical display once
per second and calculates and displays the trigger and data rates.
It is possible to transfer data over a 1Gbit network with a rate of 50 MB/s or about 500 waveforms/s.
## Installation
The sub-directory *RP-image* contains files to be transferred to a SD card for the RedPitaya board.
Proceed as follows:
- copy the contents of the directory *RP-image* to an empty SD card formatted as VFAT32.
- connect the RedPitaya to the network via the LAN port
- copy the contents of the directory *RP-image* to an empty SD card formatted as VFAT32;
- connect the RedPitaya to the network via the LAN port;
- insert the SD card in the RedPitaya and connect the power.
The RepPitaya directly starts the *mcpha* server application, requests an IP address via DHCP
......@@ -117,15 +129,15 @@ and waits for the client program to connect via network.
On the client computer, download the client software:
- clone the *mcpha* repository via `git clone https://gitlab.kit.edu/guenter.quast/redpitaya-mcpha`
- change directory to the installation directory and start the graphical interface of the client
software via `python3 mcpha.py` on the command line.
- clone the *redpitaya-mcpha* repository via `git clone https://gitlab.kit.edu/guenter.quast/redpitaya-mcpha`;
- change directory to the installation directory and start the graphical interface of the desired Python
client script on the command line.
The application program *mcpha.py* takes care of initializing the processes on the RedPitaya board
through the server process, initiates data transfers from the RedPitaya board to
the client computer and provides several tabs to visualize data, generate test data and
The application programs *mcpha.py* or *redPdaq.py* take care of initializing the processes on the
RedPitaya board through the server process, initiate data transfers from the RedPitaya board to
the client computer and provide several tabs to visualize data, generate test pulses and
to store the acquired spectra.
### Network connection to the RedPitaya Board
......@@ -147,21 +159,21 @@ and the server process on the RedPitaya board.
Then, on the client side:
- start the client program via `python3 mcpha.py`
- start the client program from within a terminal via `python3 mcpha.py` or `python3 redPdaq.py`;
- in the graphical interface, enter the network address of the RedPitaya in the
field next to the orange button and click *connect*;
watch out for connection errors in the *Messages* tab!
The message "*IO started*" is displayed if everything is ok, and the address turns green.
The message "*IO started*" is displayed if everything is ok, and the address turns green;
- click the *oscilloscope* tab, check the trigger level and then start the oscilloscope
to see whether signals are arriving at one or both of the RedPitaya inputs.
Adjust the *decimation factor* in the top-right corner of the main display to ensure
to see whether signals are arriving at one or both of the RedPitaya inputs;
adjust the *decimation factor* in the top-right corner of the main display to ensure
that the sampling rate is high enough for about 50 samples over the pulse duration.
- if no signal source is available, you may click the *generator* tab, set the desired
signal parameters and start the generator; connect *out1* of the RedPitaya to the
input *in1* with a (short) cable and then check for the presence of signals in
the *oscilloscpe* tab.
signal parameters and start the generator; connect *out1* of the RedPitaya to one of
rhe inputs with a (short) cable and then check for the presence of signals in
the *oscilloscpe* tab;
- now click the tab *spectrum histogram 1*; adjust the amplitude threshold and time
of exposure, then click the *Start* button and watch the spectrum building up.
of exposure, then click the *Start* button and watch the spectrum building up;
- when finished, use the *Save* button to save the spectrum to a file with a
meaningful name.
......@@ -171,22 +183,32 @@ Then, on the client side:
The directory *helpers/* contains helper scripts to read and visualize data from
files written by *mcpha.py*, for both spectrum histograms and exported waveforms.
Note that presently mcpha.py exports data in human-readable format using
*numpy.savetxt()*
*numpy.savetxt()*.
> *generate_spectrum_input.py* is a script to to generate input spectra for the signal
generator of mcpha.py The convention is to use 4096 channels for a range from 0 to 500 mV.
Pulse heights are drawn randomly from this spectrum, and pulses are formed according to the
frequency and the rise and fall times specified in the graphical interface. The signals are
available at the *out1* connector of the RedPitaya board.
Pulses can be generated at a fixed frequency, or with random timing corresponding to a
>
> Pulses can be generated at a fixed frequency, or with random timing corresponding to a
Poisson process with a mean pulse rate given by the chosen frequency. The latter option is
useful to study "pile-up" effects from overlapping pulses.
> *read_hst.py* illustrates how to read and plot spectrum data exported by mcpha.py.
> *read_hst.py* illustrates how to read and plot spectrum data exported by mcpha.py.
> *read_osc.py* demonstrates how to read and plot waveform data exported from the
oscilloscope tab of mcpha.py.
> *read_npy.py* illustrates how to read waveform recorded by `redPdaq.py`.
## Examples
The directory *examples/* contains some spectra recorded with *mchph.py* and the Python
program *peakFitter.py* to find and precisely fit peaks in recorded spectra. An example is
shown here:
> *read_osc.py* demonstrates how to read and plot waveform data exported from the
oscilloscope tab of mcpha.py.
![Spectrum with fitted peaks](images/Spectrum.png){width=800px}
## License
......@@ -196,6 +218,5 @@ Like the original code by Pavel Demin, this open-source code is provided under t
## Project status
This project has been developed for experiments in the physics lab courses at the Faculty of
Physics at Karlsruhe Institute of Technology. Presently, the code is under test. A public
β-release is in preparation.
This project has been developed for experiments in the physics lab courses at the Faculty of Physics
at Karlsruhe Institute of Technology. The code is already public, but presently still under test.
images/Spectrum.png

160 KiB

......@@ -305,14 +305,14 @@
<item>
<widget class="QPushButton" name="startButton">
<property name="text">
<string>Start</string>
<string>Start monitor</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="startDAQButton">
<property name="text">
<string>Start DAQ</string>
<string>Start DAQ mode</string>
</property>
</widget>
</item>
......
#!/usr/bin/env python3
"""read file from redPoscdaq (in npy format) and display data
"""
from npy_append_array import NpyAppendArray
import numpy as np
import sys
import matplotlib.pyplot as plt
data = np.load(sys.argv[1], mmap_mode='r')
print("data read sucessfully, shape = ", data.shape)
n_samples = len(data[0,0])
xplt = 0.5 + np.linspace(0, n_samples, num=n_samples, endpoint=True)
fig = plt.figure("Oscillogram", figsize=(8,6))
for d in data:
plt.plot(xplt, d[0], '-')
plt.plot(xplt, d[1], '-')
plt.xlabel("time bin")
plt.ylabel("Voltage")
plt.show()
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MCPHA</class>
<widget class="QMainWindow" name="MCPHA">
<widget class="QMainWindow" name="OscilloscopeDAQ">
<property name="geometry">
<rect>
<x>0</x>
......@@ -17,7 +17,7 @@
</size>
</property>
<property name="windowTitle">
<string>Multichannel Pulse Height Analyzer</string>
<string>Oscilloscope DAQ</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
......
# Configuration for recording two channels with mimoCoRB
# -----------------------------------------------------
#
# configure two buffers:
# - RB_1 for raw waveforms
# - RB_2 for derived pulse parameters
# data from RB_2, the result buffer, are saved to a file in csv (text) format.
#
# - data from RB_1 are also passed to an obsever process driving a real-time display
# - data from RB_2 are passed to a Reader process driving a real-time histogram display
#
# Notes:
#
# 1. additional config files controlling the user functions are
# located in the subdirectory config/
# 2. necessary application-specific user code is located
# in the subdirectory modules/
#
# ----------------------------------------------------------------------------
#
RingBuffer:
# define ring buffers
- RB_1:
# raw input data buffer (from picoScope, file or simulation)
number_of_slots: 100
channel_per_slot: 1000
data_type:
1: ['ch1', "float32"]
2: ['ch2', "float32"]
- RB_2:
# buffer with correct signature double pulse parameters
number_of_slots: 100
channel_per_slot: 1
data_type:
data_type:
1: ['ch1_height', "float32"]
2: ['ch1_position', "int32"]
3: ['ch1_integral', "float32"]
4: ['ch2_height', "float32"]
5: ['ch2_position', "int32"]
6: ['ch2_integral', "float32"]
Functions:
# define functions and ringbuffer assignment
- Fkt_main:
config_file: "config/spectrum_config.yaml"
- Fkt_1:
## for simulation with rbPut
file_name: "redP_mimoCoRB"
fkt_name: "redP_to_rb"
num_process: 1
RB_assign:
RB_1: "write"
- Fkt_2:
file_name: "modules/spectrum_filter"
fkt_name: "find_peaks"
num_process: 2
RB_assign:
RB_1: "read"
RB_2: "write"
- Fkt_3:
file_name: "modules/save_files"
fkt_name: "save_to_txt"
num_process: 1
RB_assign:
RB_2: "read"
# --- the following functions are optioal
- Fkt_4:
file_name: "modules/plot_waveform"
fkt_name: "plot_waveform"
num_process: 1
RB_assign:
RB_1: "observe"
- Fkt_5:
file_name: "modules/plot_histograms"
fkt_name: "plot_histograms"
num_process: 1
RB_assign:
RB_2: "read" # pulse parameters