Commit b507a63a authored by Marek Gumiński's avatar Marek Gumiński

Fixed indentation error in test01.

Added sampling frequency value to binary output data of fald-acq tool.
Read samples functions return both data and time vectors.
read_samples.py plot x axis in us insted of sample number
Described changes in User Guide
parent 5e3ad9d8
......@@ -322,7 +322,6 @@ class Suite(object):
adc_data_files=get_files("/tmp","mfdata*")
adc_read_script=os.path.abspath("../python/read_samples.py")
print adc_read_script
ziplist = ziplist + adc_data_files + [ adc_read_script ]
make_zip(zipfilename, ziplist)
......
......@@ -90,6 +90,8 @@ class fmcmasterfip:
# Masterfip core registers
MASTERFIP_CORE_ADDR = CROSSBAR_MAIN + 0x8000
SAMPLING_FREQ_ADDR_IN_BINARY_DATA = 72;
freq_options = [ 31250, 1e6, 25e5, 5e6 ]
adc_sampling_freq = 100e6
......@@ -148,7 +150,7 @@ class fmcmasterfip:
self.adc_def_conf = adc_conf()
self.busfreq = self.get_bus_freq()
# Returns FMC unique ID
def get_unique_id(self):
return self.fmc_ds18b20.read_serial_number()
......@@ -280,7 +282,17 @@ class fmcmasterfip:
custom_conf.samples_after = int( samples )
return custom_conf
def save_sampling_freq( self, freq ):
# modify standard binary output file to store inforation about sampling frequency
try:
with open( self.adc_def_conf.output_file, "r+b") as fin:
fin.seek( self.SAMPLING_FREQ_ADDR_IN_BINARY_DATA)
fin.write(freq)
fin.close()
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
util.info_msg('File containing ADC samples not found')
def read_adc_samples( self ):
try:
......@@ -296,7 +308,16 @@ class fmcmasterfip:
# integer (that is interesting) is stored in address 0
# number of samples must be divided by number of channels
nsamples = nsamples[0]/4
# in order to know timescale i had to add information about sampling frequency to binary file
# it is stred in uint32_t reserverd on byte 76
sampling_freq = struct.unpack("I",header[ self.SAMPLING_FREQ_ADDR_IN_BINARY_DATA : self.SAMPLING_FREQ_ADDR_IN_BINARY_DATA+4 ] )
if ( sampling_freq[0] == 0):
util.info_msg( "Sampling frequency is not stored in given file." )
sampling_period = 1
else:
sampling_period = 1e6 / sampling_freq[0];
# read data from file
d=numpy.fromfile(file=fin,dtype=numpy.uint16).reshape(nsamples,4)
......@@ -311,11 +332,13 @@ class fmcmasterfip:
transmission = numpy.int32( numpy.int32(positive_samples) - numpy.int32(negative_samples) );
return [transmission, positive_samples, negative_samples ]
time = numpy.linspace(0, sampling_period*len(transmission),len(transmission))
return [transmission, positive_samples, negative_samples, time ]
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
util.info_msg('File containing ADC samples not found')
return [ -1, -1, -1]
return [ -1, -1, -1, -1]
def save_transmission(self, path ):
......
......@@ -4,6 +4,9 @@ import numpy
import matplotlib.pyplot as plt
SAMPLING_FREQ_ADDR_IN_BINARY_DATA = 72
def u2int16(val):
if val & 0x8000:
val = numpy.int16( numpy.uint16( val ) ^ numpy.uint16( 0xfffff ) + 1 )
......@@ -15,11 +18,11 @@ def u2int16arr(arr):
return arr
def read_adc_samples( filepath ):
def read_adc_samples( file ):
try:
with open( filepath, "rb") as fin:
with open( file, "rb") as fin:
# header
......@@ -30,7 +33,16 @@ def read_adc_samples( filepath ):
# integer (that is interesting) is stored in address 0
# number of samples must be divided by number of channels
nsamples = nsamples[0]/4
# in order to know timescale i had to add information about sampling frequency to binary file
# it is stred in uint32_t reserverd on byte 76
sampling_freq = struct.unpack("I",header[ SAMPLING_FREQ_ADDR_IN_BINARY_DATA : SAMPLING_FREQ_ADDR_IN_BINARY_DATA+4 ] )
if ( sampling_freq[0] == 0):
print "Sampling frequency is not stored in given file."
sampling_period = 1
else:
sampling_period = 1e6 / sampling_freq[0];
# read data from file
d=numpy.fromfile(file=fin,dtype=numpy.uint16).reshape(nsamples,4)
......@@ -45,31 +57,32 @@ def read_adc_samples( filepath ):
transmission = numpy.int32( numpy.int32(positive_samples) - numpy.int32(negative_samples) );
return [transmission, positive_samples, negative_samples ]
time = numpy.linspace(0, sampling_period*len(transmission),len(transmission))
return [transmission, positive_samples, negative_samples, time ]
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
print 'File containing acquired data not found'
return [ -1, -1, -1]
print 'File containing ADC samples not found'
return [ -1, -1, -1, -1]
def show(data):
plt.plot( 1000.0*data/ 2.0**16)
def show(time, data):
plt.plot( time, 1000.0*data/ 2.0**16)
plt.ylabel("Signal [mV]")
plt.xlabel("Time [samples]")
plt.xlabel("Time [us]")
plt.show()
def show2(data, data2):
def show2(time, data, data2):
if len(data) != len(data2):
print "Data sets differ in length"
return -1
t = range( len( data ) )
plt.plot( t, 1000.0*data/ 2.0**16, label = 'data1')
plt.plot( t, 1000.0*data2/ 2.0**16, label = 'data2')
plt.plot( time, 1000.0*data/ 2.0**16, label = 'data1')
plt.plot( time, 1000.0*data2/ 2.0**16, label = 'data2')
plt.ylabel("Signal [mV]")
plt.xlabel("Time [samples]")
plt.xlabel("Time [us]")
plt.legend()
plt.show()
......@@ -71,7 +71,7 @@ def test_running_led( dut ):
util.ask_user("Are you ready to start a test?" )
for j in xrange(2):
dut.fipcore.write_regname( 'led', 1 << 1 )
dut.fipcore.write_regname( 'led', 1 << 1 )
time.sleep(0.7)
dut.fipcore.write_regname( 'led', 1 << 2 )
time.sleep(0.7)
......
......@@ -259,9 +259,11 @@ def test_transmission( dut, transmission, should_succed = True, primary = True )
# waiting will be terminated
wait_acquisition( proc, should_succed )
dut.save_sampling_freq( numpy.int32( dut.adc_sampling_freq / customconf.undersampling ) )
# read file with ADC samples
# make lists of positive, negative and differential transmission samples
[diff, pos, neg ] = dut.read_adc_samples( )
[diff, pos, neg, time ] = dut.read_adc_samples( )
......@@ -273,21 +275,21 @@ def test_transmission( dut, transmission, should_succed = True, primary = True )
else:
result[ 'Captured ADC transmission' ] = 1
# ADC sampling freq is constant, but undersampling is changed depending on bus speed
# result sampling frequency is lower
# 1e6 to get [us]
sampleperiod = 1e6/ (dut.adc_sampling_freq / customconf.undersampling)
# create time vector
xxrange=numpy.linspace(0, sampleperiod*len(diff),len(diff))
# make plot
plt.plot( xxrange, 1000.0*diff/ 2.0**16)
plt.plot( time, 1000.0*diff/ 2.0**16)
#make is look good
plt.title("Differential WordFIP signal (ADC CH1-CH2)")
plt.ylabel("Signal [mV]")
plt.xlabel("Time [us]")
# plt.show()
plt.savefig("/tmp/image.png")
plt.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment