Skip to content

Commit

Permalink
more tool programs in examples
Browse files Browse the repository at this point in the history
fft... and plot... allow to visualize captured data from scope
set_cal_out_freq.py allows to set the output frequency freely
between 32 Hz and 100 kHz

Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
  • Loading branch information
Ho-Ro committed Feb 8, 2022
1 parent 078dffd commit 6c9d2d7
Show file tree
Hide file tree
Showing 16 changed files with 2,207 additions and 2,049 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ nosetests.xml

# Other test results
model*.conf
*.csv

# Backups
*~
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2022-02-05: Merge branch 'main' of github.com:Ho-Ro/Hantek6022API fix last commit [078dffd]
2022-02-05: fix github workflow [0966f8b]
2022-02-05: fix github workflow [5a50a99]
2022-02-05: more github workflow setup [0c97913]
2022-02-05: fix github workflow [5324872]
2022-02-05: replace "checkinstall" by "python3-stdeb" in github workflow setup [46962d4]
2022-02-05: change debian build from "checkinstall" to "stdeb" tool [de61c32]
Expand Down
File renamed without changes
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ include PyHT6022/Firmware/*/*.ihex
# tool scripts
include examples/calibrate_6022.py
include examples/capture_6022.py
include examples/plot_from_capture_6022.py
include examples/fft_from_capture_6022.py
include examples/fft_ft_from_capture_6022.py
include examples/set_cal_out_freq_6022.py
include examples/upload_6022_firmware_from_hex.py
include examples/upload_6022_firmware.py
include fx2upload/fx2upload
Expand Down
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,26 @@ changelog:

# create a debian binary package
.PHONY: deb
deb: all changelog
deb: all changelog distclean
DEB_BUILD_OPTIONS=nocheck python setup.py --command-packages=stdeb.command bdist_deb
ln `ls deb_dist/hantek6022api_*.deb | tail -1` .


# create a debian source package
.PHONY: dsc
dsc: all changelog
dsc: all changelog distclean
DEB_BUILD_OPTIONS=nocheck python setup.py --command-packages=stdeb.command sdist_dsc


.PHONY: debinstall
debinstall: deb
sudo dpkg -i `ls deb_dist/hantek6022api_*.deb | tail -1`
sudo dpkg -i hantek6022api_*.deb


# remove all compiler artefacts
.PHONY: clean
clean:
-rm *~ .*~
-rm -rf build/*
-rm -rf dist/*
( cd $(DSO6021) && make clean )
( cd $(DSO6022BE) && make clean )
( cd $(DSO6022BL) && make clean )
Expand All @@ -69,9 +68,9 @@ clean:

# remove all package build artefacts
.PHONY: distclean
distclean: clean
distclean:
python setup.py clean
rm -rf *~ .*~ deb_dist dist *.tar.gz *.egg* build tmp
-rm -rf *~ .*~ deb_dist dist *.tar.gz *.egg* *.deb build tmp


# transfer the needed hex files to OpenHantek
Expand Down
19 changes: 15 additions & 4 deletions PyHT6022/LibUsbScope.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,23 +890,34 @@ def set_ch2_voltage_range(self, range_index, timeout=0):
def set_calibration_frequency(self, cal_freq, timeout=0):
"""
Set the frequency of the calibration output.
:param cal_freq: The frequncy coded into one byte for the Oscilloscope object.
:param cal_freq: 32 Hz <= cal_freq <= 100 kHz
The frequency will be coded into one byte for the Oscilloscope object.
0 -> 100 Hz (be compatible with sigrok FW)
1..100 -> 1..100 kHz
101..102 -> do not use
103 -> 32 Hz (lowest possible calfreq due to 16bit HW counter)
104..200 -> 40..1000 Hz ( calfreq = 10*(freq-100) )
201..255 -> 100..5500 Hz ( calfreq = 100*(freq-200) )
104..200 -> 40..1000 Hz, step = 10 Hz ( calfreq = 10*(freq-100) )
201..255 -> 100..5500 Hz, step = 100 Hz ( calfreq = 100*(freq-200) )
:param timeout: (OPTIONAL).
:return: True if successful. This method may assert or raise various libusb errors if something went wrong.
"""
if cal_freq < 32 or cal_freq > 100000:
return False

if cal_freq < 1000:
cal_freq_byte = int(cal_freq / 10) + 100 # 103...199 -> 32...990 Hz
elif cal_freq < 5600:
cal_freq_byte = int(cal_freq / 100) + 200 # 201...255 -> 100...5500 Hz
else:
cal_freq_byte = ( cal_freq / 1000 ) # 1...100 -> 1...100 kHz

if not self.device_handle:
assert self.open_handle()

bytes_written = self.device_handle.controlWrite(0x40, self.SET_CAL_FREQ_REQUEST,
self.SET_CAL_FREQ_VALUE,
self.SET_CAL_FREQ_INDEX,
pack("B", cal_freq), timeout=timeout)
pack("B", cal_freq_byte), timeout=timeout)
assert bytes_written == 0x01
return True

Expand Down
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ This repo is based on the excellent work of [Robert](https://github.com/rpcope1/
and [Jochen](https://github.com/jhoenicke/Hantek6022API)
and focusses mainly on Hantek6022BE/BL under Linux (development system: debian buster).

__Hantek6022BE custom firmware is feature complete and usable for [OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022)__
## Hantek 6022 Firmware

__Hantek6022BL custom firmware is feature complete but not as intensively tested as the BE version__
* __Hantek6022BE custom firmware is feature complete and usable for [OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022)__

<img alt="Scope Visualisation Example" width="100%" src="HT6022BEBuiltInOscillator.png">
* __Hantek6022BL custom firmware is feature complete but not as intensively tested as the BE version__

## Hantek 6022 Python API for Linux

Hantek 6022 Python API for Linux. This is a API for Python for the
<img alt="Scope Visualisation Example" width="100%" src="plot_from_capture.png">

This is a API for Python for the
ultra-cheap, reasonably usable (and hackable) 6022 DSO, with a libusb implementation via libusb1 for Linux.

The scope can be accessed by instantiating an oscilloscope object with the correct scopeid (always 0 for one scope
Expand Down Expand Up @@ -76,8 +79,9 @@ The installed programs can also be uninstalled cleanly with

sudo dpkg -P hantek6022api

With the device plugged in, run `upload_6022_firmware.py` (installed into `/usr/bin`) to bootstrap the scope for use.
You can then write your own programs, or look at the current channel 1 scope trace via `python examples/scopevis.py`.
With the device plugged in, run `upload_firmware_6022.py` once to bootstrap the scope for use.
You can then look at the scope traces via `capture_6022.py -t 0.01 | plot_from_capture_6022.py`,
or write your own programs - look at the programs in `examples` as a start.

## It even works under Windows

Expand All @@ -99,17 +103,25 @@ You can then write your own programs, or look at the current channel 1 scope tra
You can also use the `libusb-1.0.dll` file from the
[libusb-1.0 version](https://github.com/OpenHantek/OpenHantek6022/blob/master/cmake/libusb-1.0.21-win.7z)
that is provided by [OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022).
The `libusb-1.0.dll` file should be found in the PATH, e.g. it could be in the `python.exe` directory or together with the example programs in the same directory.
The `libusb-1.0.dll` file should be found in the PATH, e.g. it could be in the `python.exe` directory
or together with the example programs in the same directory.

YMMV, I checked it only with a bare-bones virtual Win7 install under Debian.

## Create calibration values for OpenHantek

As you can see in the trace above the scope has a quite big zero point error (the measured real signal switches between 0.0 V and 2.0 V) - also the gain is defined by resistors with 5% tolerance in the frontend - in best case by two resistors R27/17 & R31/21 in the chain (x1), in worst case by four resistors R27/17 & R31/21 & R32/23 & R18/19/22 in the chain (x2, x5, x10).
<img alt="Uncalibrated scope data" width="50%" src="HT6022BE_uncalibrated.png">

As you can see in the trace above the scope has a quite big zero point error (the measured real signal
switches between 0.0 V and 2.0 V) - also the gain is defined by resistors with 5% tolerance
in the frontend - in best case by two resistors R27/17 & R31/21 in the chain (x1),
in worst case by four resistors R27/17 & R31/21 & R32/23 & R18/19/22 in the chain (x2, x5, x10).

-> https://github.com/Ho-Ro/Hantek6022API/blob/master/hardware/6022BE_Frontend_with_pinout.jpg

In the end you can have a statistical gain tolerance of about 7%...10% -> RSS analysis (root sum square, square all tolerances, sum them up und calculate the root of this sum) gives an expected tolerance range:
In the end you can have a statistical gain tolerance of about 7%...10% -> RSS analysis
(root sum square, square all tolerances, sum them up und calculate the root of this sum)
gives an expected tolerance range:

- sqrt( 2 * (5%)² ) = 1.4 * 5% = 7% for gain step x1
- sqrt( 4 * (5%)² ) = 2 * 5% = 10% for all other gains
Expand All @@ -121,7 +133,7 @@ or `%APPDATA%\OpenHantek\modelDSO6022.ini` for Windows.

Step 2 uses the factory offset calibration values in eeprom.
Out of the box only offset values are contained in eeprom,
the program `calibrate_6022.py` (installed in `/usr/local/bin`) allows to update these values in case the offset has changed over time.
the program `calibrate_6022.py` (installed in `/usr/bin`) allows to update these values in case the offset has changed over time.

Program to calibrate offset and gain of Hantek 6022BE/BL
1. Measure offset at low and high speed for the four gain steps x10, x5, x2, x1
Expand Down Expand Up @@ -179,10 +191,10 @@ Requested Voltage | Applied Voltage | Comment

## Use the device as a data logger ##

The program `capture_6022.py` (also in `/usr/local/bin/`) allows to capture both channels over a long time.
The program `capture_6022.py` (also in `/usr/bin/`) allows to capture both channels over a long time.

The 256 x downsampling option increases the SNR and effective resolution (8bit -> at least 12 bit) and allows very long time recording.
The program uses the offset and gain calibration from EEPROM.
The 256 x downsampling option increases the SNR and effective resolution (8bit -> at least 12 bit)
and allows very long time recording. The program uses the offset and gain calibration from EEPROM.
It writes the captured data into stdout or an outfile and calculates DC, AC and RMS of the data.

usage: capture_6022.py [-h] [-d DOWNSAMPLE] [-o OUTFILE] [-r RATE] [-t TIME]
Expand All @@ -200,6 +212,20 @@ It writes the captured data into stdout or an outfile and calculates DC, AC and
-y CH2, --ch2 CH2 gain of channel 2 (1, 2, 5, 10, default: 1)


The program `plot_from_capture_6022.py` takes the captured data (either from stdin
or from a file named as 1st command line argument) and presents them as seen on top of this page.

usage: plot_from_capture_6022.py [-h] [-i INFILE] [-o OUTFILE] [-c CHANNELS] [-s]

optional arguments:
-h, --help show this help message and exit
-i INFILE, --infile INFILE
read the data from INFILE
-c CHANNELS, --channels CHANNELS
show one (CH1) or two (CH1, CH2) channels, default: 2)
-s, --spectrum display the spectrum of the samples


## Other neat things you can do

While this scope isn't quite as poweful as your many-thousand dollar Tektronix or even your run of the mill Rigol 1102E,
Expand Down
1 change: 1 addition & 0 deletions examples/PyHT6022
Loading

0 comments on commit 6c9d2d7

Please sign in to comment.