experimental version busing the built-in DAC (kinda broken)
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
## GEX v1.0.0 on STM32F072-HUB
|
## GEX v1.0.0 on STM32F072-HUB
|
||||||
## built Jun 15 2018 at 13:45:28
|
## built Jun 15 2018 at 13:45:28
|
||||||
|
|
||||||
|
# Overwrite this file to change settings.
|
||||||
|
# Press the LOCK button to save them to Flash.
|
||||||
|
|
||||||
[UNITS]
|
[UNITS]
|
||||||
# Create units by adding their names next to a type (e.g. DO=A,B),
|
# 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.
|
# remove the same way. Reload to update the unit sections below.
|
||||||
@@ -31,7 +34,7 @@ TOUCH=
|
|||||||
# Simple PWM output
|
# Simple PWM output
|
||||||
PWMDIM=
|
PWMDIM=
|
||||||
# Two-channel analog output with waveforms
|
# Two-channel analog output with waveforms
|
||||||
DAC=
|
DAC=dac
|
||||||
|
|
||||||
[SPI:spi@2]
|
[SPI:spi@2]
|
||||||
# Peripheral number (SPIx)
|
# Peripheral number (SPIx)
|
||||||
@@ -55,7 +58,7 @@ first-bit=MSB
|
|||||||
# SS port name
|
# SS port name
|
||||||
port=A
|
port=A
|
||||||
# SS pins (comma separated, supports ranges)
|
# SS pins (comma separated, supports ranges)
|
||||||
pins=4
|
pins=3
|
||||||
|
|
||||||
[ADC:adc@4]
|
[ADC:adc@4]
|
||||||
# Enabled channels, comma separated
|
# Enabled channels, comma separated
|
||||||
@@ -73,7 +76,7 @@ frequency=1000
|
|||||||
# - defines the maximum pre-trigger size (divide by # of channels)
|
# - defines the maximum pre-trigger size (divide by # of channels)
|
||||||
# - captured data is sent in half-buffer chunks
|
# - captured data is sent in half-buffer chunks
|
||||||
# - buffer overrun aborts the data capture
|
# - buffer overrun aborts the data capture
|
||||||
buffer_size=512
|
buffer_size=800
|
||||||
|
|
||||||
# Enable continuous sampling with averaging
|
# Enable continuous sampling with averaging
|
||||||
# Caution: This can cause DAC output glitches
|
# Caution: This can cause DAC output glitches
|
||||||
@@ -81,4 +84,17 @@ averaging=N
|
|||||||
# Exponential averaging coefficient (permil, range 0-1000 ~ 0.000-1.000)
|
# Exponential averaging coefficient (permil, range 0-1000 ~ 0.000-1.000)
|
||||||
# - used formula: y[t]=(1-k)*y[t-1]+k*u[t]
|
# - used formula: y[t]=(1-k)*y[t-1]+k*u[t]
|
||||||
# - not available when a capture is running
|
# - 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 gex
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
use_native_dac = True
|
||||||
|
|
||||||
class ADG:
|
class ADG:
|
||||||
def __init__(self, client:gex.Client):
|
def __init__(self, client:gex.Client):
|
||||||
self.client = client
|
self.client = client
|
||||||
@@ -68,9 +70,12 @@ with gex.Client(gex.TrxRawUSB()) as client:
|
|||||||
|
|
||||||
|
|
||||||
# Frequency sweep parameters
|
# Frequency sweep parameters
|
||||||
f_0 = 5
|
#f_0 = 5
|
||||||
|
#f_1 = 5000
|
||||||
|
#f_step = 15
|
||||||
|
f_0 = 10
|
||||||
f_1 = 5000
|
f_1 = 5000
|
||||||
f_step = 15
|
f_step = 50
|
||||||
|
|
||||||
# Retry on failure
|
# Retry on failure
|
||||||
retry_count = 5
|
retry_count = 5
|
||||||
@@ -91,6 +96,15 @@ with gex.Client(gex.TrxRawUSB()) as client:
|
|||||||
|
|
||||||
adc = gex.ADC(client, 'adc')
|
adc = gex.ADC(client, 'adc')
|
||||||
|
|
||||||
|
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 = ADG(client)
|
||||||
gen.initialize()
|
gen.initialize()
|
||||||
|
|
||||||
@@ -99,7 +113,10 @@ with gex.Client(gex.TrxRawUSB()) as client:
|
|||||||
|
|
||||||
last_db = None
|
last_db = None
|
||||||
for f in range(f_0, f_1, f_step):
|
for f in range(f_0, f_1, f_step):
|
||||||
#dac.set_frequency(1, f)
|
|
||||||
|
if use_native_dac:
|
||||||
|
dac.set_frequency(1, f)
|
||||||
|
else:
|
||||||
gen.set_frequency(f)
|
gen.set_frequency(f)
|
||||||
|
|
||||||
max_allowed_shift_db += allowed_shift_compensation
|
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])
|
y1 = np.max(t[:,0]) - np.min(t[:,0])
|
||||||
y2 = np.max(t[:,1]) - np.min(t[:,1])
|
y2 = np.max(t[:,1]) - np.min(t[:,1])
|
||||||
|
print("\x1b[90mU %f, Y %f\x1b[0m" % (y1, y2))
|
||||||
gain_raw = y2/y1
|
gain_raw = y2/y1
|
||||||
gain_db = 20*math.log10(gain_raw)
|
gain_db = 20*math.log10(gain_raw)
|
||||||
|
|
||||||
@@ -179,6 +197,9 @@ with gex.Client(gex.TrxRawUSB()) as client:
|
|||||||
if not suc:
|
if not suc:
|
||||||
last_db = last_db_in_fail
|
last_db = last_db_in_fail
|
||||||
|
|
||||||
|
if use_native_dac:
|
||||||
|
dac.dc(1, 2000)
|
||||||
|
else:
|
||||||
gen.wfm_dc()
|
gen.wfm_dc()
|
||||||
|
|
||||||
t = np.reshape(np.array(table), [int(len(table) / 3), 3])
|
t = np.reshape(np.array(table), [int(len(table) / 3), 3])
|
||||||
|
|||||||
Reference in New Issue
Block a user