Compare commits

...

1 Commits

  1. 24
      UNITS.INI
  2. 35
      main.py

@ -2,6 +2,9 @@
## GEX v1.0.0 on STM32F072-HUB
## built Jun 15 2018 at 13:45:28
# Overwrite this file to change settings.
# Press the LOCK button to save them to Flash.
[UNITS]
# Create units by adding their names next to a type (e.g. DO=A,B),
# remove the same way. Reload to update the unit sections below.
@ -31,7 +34,7 @@ TOUCH=
# Simple PWM output
PWMDIM=
# Two-channel analog output with waveforms
DAC=
DAC=dac
[SPI:spi@2]
# Peripheral number (SPIx)
@ -55,7 +58,7 @@ first-bit=MSB
# SS port name
port=A
# SS pins (comma separated, supports ranges)
pins=4
pins=3
[ADC:adc@4]
# Enabled channels, comma separated
@ -73,7 +76,7 @@ frequency=1000
# - defines the maximum pre-trigger size (divide by # of channels)
# - captured data is sent in half-buffer chunks
# - buffer overrun aborts the data capture
buffer_size=512
buffer_size=800
# Enable continuous sampling with averaging
# Caution: This can cause DAC output glitches
@ -81,4 +84,17 @@ averaging=N
# Exponential averaging coefficient (permil, range 0-1000 ~ 0.000-1.000)
# - used formula: y[t]=(1-k)*y[t-1]+k*u[t]
# - not available when a capture is running
avg_factor=800
avg_factor=80
[DAC:dac@1]
# Enabled channels (1:A4, 2:A5)
ch1_enable=Y
ch2_enable=N
# Enable output buffer
ch1_buff=Y
ch2_buff=Y
# Superimposed noise type (NONE,WHITE,TRIANGLE) and nbr. of bits (1-12)
ch1_noise=NONE
ch1_noise-level=3
ch2_noise=NONE
ch2_noise-level=3

@ -7,6 +7,8 @@ from matplotlib import pyplot as plt
import gex
import time
use_native_dac = True
class ADG:
def __init__(self, client:gex.Client):
self.client = client
@ -68,9 +70,12 @@ with gex.Client(gex.TrxRawUSB()) as client:
# Frequency sweep parameters
f_0 = 5
#f_0 = 5
#f_1 = 5000
#f_step = 15
f_0 = 10
f_1 = 5000
f_step = 15
f_step = 50
# Retry on failure
retry_count = 5
@ -91,16 +96,28 @@ with gex.Client(gex.TrxRawUSB()) as client:
adc = gex.ADC(client, 'adc')
gen = ADG(client)
gen.initialize()
dac = None
gen = None
if use_native_dac:
print('Using native GEX DAC')
dac = gex.DAC(client, 'dac')
dac.waveform(1, 'SINE')
else:
print('Using AD9833 via SPI')
gen = ADG(client)
gen.initialize()
table = []
last_db = None
for f in range(f_0, f_1, f_step):
#dac.set_frequency(1, f)
gen.set_frequency(f)
if use_native_dac:
dac.set_frequency(1, f)
else:
gen.set_frequency(f)
max_allowed_shift_db += allowed_shift_compensation
@ -148,6 +165,7 @@ with gex.Client(gex.TrxRawUSB()) as client:
y1 = np.max(t[:,0]) - np.min(t[:,0])
y2 = np.max(t[:,1]) - np.min(t[:,1])
print("\x1b[90mU %f, Y %f\x1b[0m" % (y1, y2))
gain_raw = y2/y1
gain_db = 20*math.log10(gain_raw)
@ -179,7 +197,10 @@ with gex.Client(gex.TrxRawUSB()) as client:
if not suc:
last_db = last_db_in_fail
gen.wfm_dc()
if use_native_dac:
dac.dc(1, 2000)
else:
gen.wfm_dc()
t = np.reshape(np.array(table), [int(len(table) / 3), 3])

Loading…
Cancel
Save