Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Production Test Suite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Production Test Suite
Commits
311d72bb
Commit
311d72bb
authored
May 30, 2012
by
Matthieu Cattin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test12: Uses common modules, added exception handling.
parent
46f1c6c4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
176 additions
and
138 deletions
+176
-138
test12.py
test/fmcadc100m14b4cha/python/test12.py
+176
-138
No files found.
test/fmcadc100m14b4cha/python/test12.py
View file @
311d72bb
...
@@ -5,19 +5,28 @@
...
@@ -5,19 +5,28 @@
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later.
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
# Website: http://www.ohwr.org
# Last modifications: 30/5/2012
# Import system modules
import
sys
import
sys
import
rr
import
time
import
time
import
os
import
os
from
numpy
import
*
from
pylab
import
*
# Add common modules and libraries location to path
sys
.
path
.
append
(
'../../../'
)
sys
.
path
.
append
(
'../../../gnurabbit/python/'
)
sys
.
path
.
append
(
'../../../common/'
)
# Import common modules
from
ptsexcept
import
*
from
ptsexcept
import
*
import
rr
import
spec_fmc_adc
# Import specific modules
import
fmc_adc
from
fmc_adc_spec
import
*
import
calibr_box
from
fmc_adc
import
*
from
numpy
import
*
from
pylab
import
*
from
calibr_box
import
*
import
find_usb_tty
import
find_usb_tty
from
PAGE.Agilent33250A
import
*
from
PAGE.Agilent33250A
import
*
from
PAGE.SineWaveform
import
*
from
PAGE.SineWaveform
import
*
...
@@ -30,14 +39,6 @@ test12: Takes an aqcuisition of all channels and print it to a file and on the s
...
@@ -30,14 +39,6 @@ test12: Takes an aqcuisition of all channels and print it to a file and on the s
Note: Requires test00.py to run first to load the firmware!
Note: Requires test00.py to run first to load the firmware!
"""
"""
# Calibration box vendor and product IDs
BOX_USB_VENDOR_ID
=
0x10c4
# Cygnal Integrated Products, Inc.
BOX_USB_PRODUCT_ID
=
0xea60
# CP210x Composite Device
# Agilent AWG serial access vendor and product IDs
AWG_USB_VENDOR_ID
=
0x0403
# Future Technology Devices International, Ltd
AWG_USB_PRODUCT_ID
=
0x6001
# FT232 USB-Serial (UART) IC
AWG_BAUD
=
57600
NB_CHANNELS
=
4
NB_CHANNELS
=
4
...
@@ -54,23 +55,13 @@ NB_SHOTS = 1
...
@@ -54,23 +55,13 @@ NB_SHOTS = 1
ACQ_LENGTH
=
10000
# in samples
ACQ_LENGTH
=
10000
# in samples
def
load_firmware
(
default_directory
):
print
(
'Load firmware to FPGA'
)
path_fpga_loader
=
'../../../gnurabbit/user/fpga_loader'
;
path_firmware
=
'../firmwares/spec_fmcadc100m14b4cha.bin'
;
firmware_loader
=
os
.
path
.
join
(
default_directory
,
path_fpga_loader
)
bitstream
=
os
.
path
.
join
(
default_directory
,
path_firmware
)
print
firmware_loader
+
' '
+
bitstream
os
.
system
(
firmware_loader
+
' '
+
bitstream
)
time
.
sleep
(
2
);
def
open_all_channels
(
fmc
):
def
open_all_channels
(
fmc
):
for
i
in
range
(
1
,
NB_CHANNELS
+
1
):
for
i
in
range
(
1
,
NB_CHANNELS
+
1
):
fmc
.
set_input_range
(
i
,
'OPEN'
)
fmc
.
set_input_range
(
i
,
'OPEN'
)
time
.
sleep
(
SSR_SET_SLEEP
)
time
.
sleep
(
SSR_SET_SLEEP
)
def
fmc_adc_init
(
spec
,
fmc
):
def
fmc_adc_init
(
spec
,
fmc
):
print
(
'Initialise FMC board.'
)
print
"Initialise FMC board.
\n
"
# Reset offset DACs
# Reset offset DACs
fmc
.
dc_offset_reset
()
fmc
.
dc_offset_reset
()
# Make sure all switches are OFF
# Make sure all switches are OFF
...
@@ -93,7 +84,7 @@ def hex2signed(value):
...
@@ -93,7 +84,7 @@ def hex2signed(value):
def
digital2volt
(
value
,
full_scale
,
nb_bit
):
def
digital2volt
(
value
,
full_scale
,
nb_bit
):
return
float
(
value
)
*
float
(
full_scale
)
/
2
**
nb_bit
return
float
(
value
)
*
float
(
full_scale
)
/
2
**
nb_bit
def
acq_channels
(
fmc
,
spec_fmc
,
adc_fs
,
pause
):
def
acq_channels
(
fmc
,
carrier
,
adc_fs
,
pause
):
# Make sure no acquisition is running
# Make sure no acquisition is running
fmc
.
stop_acq
()
fmc
.
stop_acq
()
time
.
sleep
(
pause
)
time
.
sleep
(
pause
)
...
@@ -114,11 +105,11 @@ def acq_channels(fmc, spec_fmc, adc_fs, pause):
...
@@ -114,11 +105,11 @@ def acq_channels(fmc, spec_fmc, adc_fs, pause):
# Retrieve data trough DMA
# Retrieve data trough DMA
trig_pos
=
fmc
.
get_trig_pos
()
trig_pos
=
fmc
.
get_trig_pos
()
# Enable "DMA done" iinterrupt
# Enable "DMA done" iinterrupt
spec_fmc
.
set_irq_en_mask
(
0x1
)
carrier
.
set_irq_en_mask
(
0x1
)
# Read ACQ_LENGTH samples after the trigger for all channels
# Read ACQ_LENGTH samples after the trigger for all channels
channels_data
=
spec_fmc
.
get_data
((
trig_pos
<<
3
),
ACQ_LENGTH
*
8
)
channels_data
=
carrier
.
get_data
((
trig_pos
<<
3
),
ACQ_LENGTH
*
8
)
# Disable "DMA done" iinterrupt
# Disable "DMA done" iinterrupt
spec_fmc
.
set_irq_en_mask
(
0x0
)
carrier
.
set_irq_en_mask
(
0x0
)
channels_data
=
[
hex2signed
(
item
)
for
item
in
channels_data
]
channels_data
=
[
hex2signed
(
item
)
for
item
in
channels_data
]
channels_data
=
[
digital2volt
(
item
,
adc_fs
,
16
)
for
item
in
channels_data
]
channels_data
=
[
digital2volt
(
item
,
adc_fs
,
16
)
for
item
in
channels_data
]
return
channels_data
return
channels_data
...
@@ -142,38 +133,75 @@ def plot_channels(ch_data, ch_mean, ylimit):
...
@@ -142,38 +133,75 @@ def plot_channels(ch_data, ch_mean, ylimit):
def
main
(
default_directory
=
'.'
):
def
main
(
default_directory
=
'.'
):
# Load firmware
# Constants declaration
load_firmware
(
default_directory
)
TEST_NB
=
12
FMC_ADC_BITSTREAM
=
'../firmwares/spec_fmcadc100m14b4cha.bin'
# Objects declaration
FMC_ADC_BITSTREAM
=
os
.
path
.
join
(
default_directory
,
FMC_ADC_BITSTREAM
)
spec
=
rr
.
Gennum
()
# bind to the SPEC board
EXPECTED_BITSTREAM_TYPE
=
0x1
spec_fmc
=
spec_fmc_adc
.
CSpecFmcAdc100Ms
(
spec
)
fmc
=
fmc_adc
.
CFmcAdc100Ms
(
spec
)
# Calibration box vendor and product IDs
BOX_USB_VENDOR_ID
=
0x10c4
# Cygnal Integrated Products, Inc.
BOX_USB_PRODUCT_ID
=
0xea60
# CP210x Composite Device
# Agilent AWG serial access vendor and product IDs
AWG_USB_VENDOR_ID
=
0x0403
# Future Technology Devices International, Ltd
AWG_USB_PRODUCT_ID
=
0x6001
# FT232 USB-Serial (UART) IC
AWG_BAUD
=
57600
start_test_time
=
time
.
time
()
print
"================================================================================"
print
"Test
%02
d start
\n
"
%
TEST_NB
# SPEC object declaration
print
"Loading hardware access library and opening device.
\n
"
spec
=
rr
.
Gennum
()
# Load FMC ADC firmware
print
"Loading FMC ADC firmware:
%
s
\n
"
%
FMC_ADC_BITSTREAM
spec
.
load_firmware
(
FMC_ADC_BITSTREAM
)
time
.
sleep
(
2
)
# Carrier object declaration (SPEC board specific part)
# Used to check that the firmware is loaded.
try
:
carrier
=
CFmcAdc100mSpec
(
spec
,
EXPECTED_BITSTREAM_TYPE
)
except
FmcAdc100mSpecOperationError
as
e
:
raise
PtsCritical
(
"Carrier init failed, test stopped:
%
s"
%
e
)
# Mezzanine object declaration (FmcAdc100m14b4cha board specific part)
try
:
fmc
=
CFmcAdc100m
(
spec
)
except
FmcAdc100mOperationError
as
e
:
raise
PtsCritical
(
"Mezzanine init failed, test stopped:
%
s"
%
e
)
try
:
# Others objects declaration
usb_tty
=
find_usb_tty
.
CttyUSB
()
usb_tty
=
find_usb_tty
.
CttyUSB
()
awg_tty
=
usb_tty
.
find_usb_tty
(
AWG_USB_VENDOR_ID
,
AWG_USB_PRODUCT_ID
)
awg_tty
=
usb_tty
.
find_usb_tty
(
AWG_USB_VENDOR_ID
,
AWG_USB_PRODUCT_ID
)
box_tty
=
usb_tty
.
find_usb_tty
(
BOX_USB_VENDOR_ID
,
BOX_USB_PRODUCT_ID
)
box_tty
=
usb_tty
.
find_usb_tty
(
BOX_USB_VENDOR_ID
,
BOX_USB_PRODUCT_ID
)
gen
=
Agilent33250A
(
device
=
awg_tty
[
0
],
bauds
=
AWG_BAUD
)
gen
=
Agilent33250A
(
device
=
awg_tty
[
0
],
bauds
=
AWG_BAUD
)
sine
=
SineWaveform
()
sine
=
SineWaveform
()
box
=
calibr_box
.
CCalibr_box
(
box_tty
[
0
])
box
=
CCalibr_box
(
box_tty
[
0
])
# Initialise fmc adc
# Initialise fmc adc
fmc_adc_init
(
spec
,
fmc
)
fmc_adc_init
(
spec
,
fmc
)
# Use test data instead of data from ADC
# Use test data instead of data from ADC
#
fmc.test_data_en()
#
fmc.test_data_en()
# Use data pattern instead of ADC data
# Use data pattern instead of ADC data
#
fmc.testpat_en(0x2000)
#
fmc.testpat_en(0x2000)
# Set UTC
# Set UTC
current_time
=
time
.
time
()
current_time
=
time
.
time
()
utc_seconds
=
int
(
current_time
)
utc_seconds
=
int
(
current_time
)
spec_fmc
.
set_utc_second_cnt
(
utc_seconds
)
carrier
.
set_utc_second_cnt
(
utc_seconds
)
print
(
'UTC core seconds counter:
%
d'
)
%
spec_fmc
.
get_utc_second_cnt
()
print
"UTC core seconds counter initialised to :
%
d"
%
carrier
.
get_utc_second_cnt
()
utc_coarse
=
int
((
current_time
-
utc_seconds
)
/
8E-9
)
utc_coarse
=
int
((
current_time
-
utc_seconds
)
/
8E-9
)
spec_fmc
.
set_utc_coarse_cnt
(
utc_coarse
)
carrier
.
set_utc_coarse_cnt
(
utc_coarse
)
print
(
'UTC core coarse counter:
%
d'
)
%
spec_fmc
.
get_utc_coarse_cnt
()
print
"UTC core coarse counter initialised to :
%
d"
%
carrier
.
get_utc_coarse_cnt
()
# Print configuration
# Print configuration
fmc
.
print_adc_core_config
()
fmc
.
print_adc_core_config
()
...
@@ -192,7 +220,7 @@ def main (default_directory='.'):
...
@@ -192,7 +220,7 @@ def main (default_directory='.'):
sine
.
frequency
=
1E6
sine
.
frequency
=
1E6
sine
.
amplitude
=
0.8
*
ADC_FS
[
IN_RANGE
]
sine
.
amplitude
=
0.8
*
ADC_FS
[
IN_RANGE
]
sine
.
dc
=
0
sine
.
dc
=
0
print
(
'
\n
Sine frequency:
%3.3
fMHz amplitude:
%2.3
fVp offset:
%2.3
fV'
)
%
(
sine
.
frequency
/
1E6
,
sine
.
amplitude
,
sine
.
dc
)
print
"
\n
Sine frequency:
%3.3
fMHz amplitude:
%2.3
fVp offset:
%2.3
fV"
%
(
sine
.
frequency
/
1E6
,
sine
.
amplitude
,
sine
.
dc
)
# Set AWG
# Set AWG
gen
.
connect
()
gen
.
connect
()
...
@@ -212,13 +240,13 @@ def main (default_directory='.'):
...
@@ -212,13 +240,13 @@ def main (default_directory='.'):
box
.
select_output_ch
(
ch
+
1
)
box
.
select_output_ch
(
ch
+
1
)
time
.
sleep
(
BOX_SET_SLEEP
)
time
.
sleep
(
BOX_SET_SLEEP
)
# Perform an acquisition
# Perform an acquisition
acq_data
=
acq_channels
(
fmc
,
spec_fmc
,
ADC_FS
[
IN_RANGE
],
ACQ_PAUSE
)
acq_data
=
acq_channels
(
fmc
,
carrier
,
ADC_FS
[
IN_RANGE
],
ACQ_PAUSE
)
channels_data
[
ch
]
=
acq_data
[
ch
::
4
]
channels_data
[
ch
]
=
acq_data
[
ch
::
4
]
# Get time-tags
# Get time-tags
trig_tag
=
spec_fmc
.
get_utc_trig_tag
()
trig_tag
=
carrier
.
get_utc_trig_tag
()
start_tag
=
spec_fmc
.
get_utc_start_tag
()
start_tag
=
carrier
.
get_utc_start_tag
()
stop_tag
=
spec_fmc
.
get_utc_stop_tag
()
stop_tag
=
carrier
.
get_utc_stop_tag
()
end_tag
=
spec_fmc
.
get_utc_end_tag
()
end_tag
=
carrier
.
get_utc_end_tag
()
print
(
'Acq stop time-tag :
%10.10
f [s]'
)
%
(
stop_tag
[
2
]
+
(
stop_tag
[
3
]
*
8E-9
))
print
(
'Acq stop time-tag :
%10.10
f [s]'
)
%
(
stop_tag
[
2
]
+
(
stop_tag
[
3
]
*
8E-9
))
print
(
'Acq start time-tag :
%10.10
f [s]'
)
%
(
start_tag
[
2
]
+
(
start_tag
[
3
]
*
8E-9
))
print
(
'Acq start time-tag :
%10.10
f [s]'
)
%
(
start_tag
[
2
]
+
(
start_tag
[
3
]
*
8E-9
))
print
(
'Trigger time-tag :
%10.10
f [s]'
)
%
(
trig_tag
[
2
]
+
(
trig_tag
[
3
]
*
8E-9
))
print
(
'Trigger time-tag :
%10.10
f [s]'
)
%
(
trig_tag
[
2
]
+
(
trig_tag
[
3
]
*
8E-9
))
...
@@ -249,9 +277,19 @@ def main (default_directory='.'):
...
@@ -249,9 +277,19 @@ def main (default_directory='.'):
gen
.
close
()
gen
.
close
()
# Check if an error occured during frequency response test
# Check if an error occured during frequency response test
#
if(error != 0):
#
if(error != 0):
# raise PtsError('An error occured, check log for details.')
# raise PtsError('An error occured, check log for details.')
except
(
FmcAdc100mSpecOperationError
,
FmcAdc100mOperationError
,
CalibrBoxOperationError
)
as
e
:
raise
PtsError
(
"Test failed:
%
s"
%
e
)
print
""
print
"==> End of test
%02
d"
%
TEST_NB
print
"================================================================================"
end_test_time
=
time
.
time
()
print
"Test
%02
d elapsed time:
%.2
f seconds
\n
"
%
(
TEST_NB
,
end_test_time
-
start_test_time
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment