Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
pts
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
misc
pts
Commits
91217b36
Commit
91217b36
authored
Jun 01, 2012
by
Matthieu Cattin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test22: Uses common modules, added exception handling.
parent
311d72bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
110 deletions
+146
-110
test22.py
test/fmcadc100m14b4cha/python/test22.py
+146
-110
No files found.
test/fmcadc100m14b4cha/python/test22.py
View file @
91217b36
...
...
@@ -5,22 +5,33 @@
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
# Last modifications: 1/6/2012
# Import system modules
import
sys
import
rr
import
time
import
os
# 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
*
import
rr
import
csr
import
fmc_adc
import
spec_fmc_adc
import
calibr_box
# Import specific modules
from
fmc_adc_spec
import
*
from
fmc_adc
import
*
from
numpy
import
*
from
pylab
import
*
from
calibr_box
import
*
import
find_usb_tty
from
PAGE.Agilent33250A
import
*
from
PAGE.SineWaveform
import
*
"""
test13: Test FMC temperature stability
...
...
@@ -39,25 +50,6 @@ ACQ_LENGTH = 50000 # in samples
NB_CHANNELS
=
4
# 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
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
disconnect_channels
(
fmc
):
for
i
in
range
(
1
,
NB_CHANNELS
+
1
):
...
...
@@ -80,7 +72,7 @@ def fmc_adc_init(spec, fmc, box):
fmc
.
set_input_term
(
2
,
'ON'
)
box
.
select_output_ch
(
2
)
def
acq_channels
(
fmc
,
spec_fmc
):
def
acq_channels
(
fmc
,
carrier
):
# Make sure no acquisition is running
fmc
.
stop_acq
()
# Start acquisition
...
...
@@ -100,100 +92,144 @@ def acq_channels(fmc, spec_fmc):
# Retrieve data trough DMA
trig_pos
=
fmc
.
get_trig_pos
()
# 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
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
spec_fmc
.
set_irq_en_mask
(
0x0
)
carrier
.
set_irq_en_mask
(
0x0
)
return
0
def
main
(
default_directory
=
'.'
):
# Load firmware
load_firmware
(
default_directory
)
# Objects declaration
spec
=
rr
.
Gennum
()
# bind to the SPEC board
fmc
=
fmc_adc
.
CFmcAdc100Ms
(
spec
)
spec_fmc
=
spec_fmc_adc
.
CSpecFmcAdc100Ms
(
spec
)
usb_tty
=
find_usb_tty
.
CttyUSB
()
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
)
gen
=
Agilent33250A
(
device
=
awg_tty
[
0
],
bauds
=
AWG_BAUD
)
sine
=
SineWaveform
()
box
=
calibr_box
.
CCalibr_box
(
box_tty
[
0
])
# Initialise fmc adc
fmc_adc_init
(
spec
,
fmc
,
box
)
# Set AWG
sine
.
frequency
=
1E6
sine
.
amplitude
=
8.0
sine
.
dc
=
0
gen
.
connect
()
gen
.
play
(
sine
)
gen
.
output
=
True
print
"
\n
"
# Read SPEC unique ID and print to log
spec_unique_id
=
spec_fmc
.
get_unique_id
()
if
(
spec_unique_id
==
-
1
):
raise
PtsError
(
"Can't read DS18D20 1-wire thermometer on SPEC board."
)
else
:
#print "SPEC Unique ID: %.12X" % spec_unique_id
pass
# Read FMC unique ID and print to log
fmc_unique_id
=
fmc
.
get_unique_id
()
if
(
fmc_unique_id
==
-
1
):
raise
PtsError
(
"Can't read DS18D20 1-wire thermometer on SPEC board."
)
else
:
#print "FMC Unique ID: %.12X" % fmc_unique_id
pass
# Read SPEC temperature and print to log
spec_temp
=
[]
spec_temp
.
append
(
spec_fmc
.
get_temp
())
print
"SPEC temperature:
%3.3
f°C"
%
spec_temp
[
-
1
]
# Read FMC temperature and print to log
fmc_temp
=
[]
fmc_temp
.
append
(
fmc
.
get_temp
())
print
"FMC temperature:
%3.3
f°C"
%
fmc_temp
[
-
1
]
# Wait for the FMC temperature to reach threshold
print
"
\n
Wait for FMC temperature to reach
%2.1
f°C"
%
TEMP_THRES
t0
=
time
.
time
()
while
fmc_temp
[
-
1
]
<
TEMP_THRES
:
fmc_temp
.
append
(
fmc
.
get_temp
())
#print "FMC temperature: %3.3f°C" % fmc_temp[-1]
fmc_temp
.
pop
(
0
)
acq_channels
(
fmc
,
spec_fmc
)
time
.
sleep
(
MEAS_SLEEP
)
t1
=
time
.
time
()
print
"FMC temperature reached
%2.1
f°C after
%10.3
fs
\n
"
%
(
TEMP_THRES
,
t1
-
t0
)
# Wait for the FMC temperature to be stable
fmc_temp_cnt
=
0
while
True
:
fmc_temp
.
append
(
fmc
.
get_temp
())
if
fmc_temp_cnt
>
FIFO_SIZE
:
temp_diff
=
(
max
(
fmc_temp
)
-
min
(
fmc_temp
))
fmc_temp
.
pop
(
0
)
print
"
%4
d fmc temp:
%3.3
f°C temp diff:
%3.3
f°C"
%
(
fmc_temp_cnt
,
fmc_temp
[
-
1
],
temp_diff
)
if
temp_diff
<
TEMP_RIPPLE
:
print
"
\n
Temperature difference in the last
%
d measurements is less than
%2.1
f°C"
%
(
FIFO_SIZE
,
TEMP_RIPPLE
)
break
# Constants declaration
TEST_NB
=
22
FMC_ADC_BITSTREAM
=
'../firmwares/spec_fmcadc100m14b4cha.bin'
FMC_ADC_BITSTREAM
=
os
.
path
.
join
(
default_directory
,
FMC_ADC_BITSTREAM
)
EXPECTED_BITSTREAM_TYPE
=
0x1
# 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
()
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
)
gen
=
Agilent33250A
(
device
=
awg_tty
[
0
],
bauds
=
AWG_BAUD
)
sine
=
SineWaveform
()
box
=
CCalibr_box
(
box_tty
[
0
])
# Initialise fmc adc
fmc_adc_init
(
spec
,
fmc
,
box
)
# Set AWG
sine
.
frequency
=
1E6
sine
.
amplitude
=
8.0
sine
.
dc
=
0
gen
.
connect
()
gen
.
play
(
sine
)
gen
.
output
=
True
# Read SPEC unique ID and print to log
spec_unique_id
=
carrier
.
get_unique_id
()
if
(
spec_unique_id
==
-
1
):
raise
PtsError
(
"Can't read DS18D20 1-wire thermometer on SPEC board."
)
else
:
# print "SPEC Unique ID: %.12X" % spec_unique_id
pass
# Read FMC unique ID and print to log
fmc_unique_id
=
fmc
.
get_unique_id
()
if
(
fmc_unique_id
==
-
1
):
raise
PtsError
(
"Can't read DS18D20 1-wire thermometer on SPEC board."
)
else
:
print
"
%4
d fmc temp:
%3.3
f°C"
%
(
fmc_temp_cnt
,
fmc_temp
[
-
1
])
fmc_temp_cnt
+=
1
acq_channels
(
fmc
,
spec_fmc
)
time
.
sleep
(
MEAS_SLEEP
)
t2
=
time
.
time
()
print
"FMC temperature is stable after
%10.3
fs"
%
(
t2
-
t0
)
# print "FMC Unique ID: %.12X" % fmc_unique_id
pass
# Read SPEC temperature and print to log
spec_temp
=
[]
spec_temp
.
append
(
carrier
.
get_temp
())
print
"SPEC temperature:
%3.3
f°C"
%
spec_temp
[
-
1
]
# Read FMC temperature and print to log
fmc_temp
=
[]
fmc_temp
.
append
(
fmc
.
get_temp
())
print
"FMC temperature:
%3.3
f°C"
%
fmc_temp
[
-
1
]
# Wait for the FMC temperature to reach threshold
print
"
\n
Wait for FMC temperature to reach
%2.1
f°C"
%
TEMP_THRES
t0
=
time
.
time
()
while
fmc_temp
[
-
1
]
<
TEMP_THRES
:
fmc_temp
.
append
(
fmc
.
get_temp
())
# print "FMC temperature: %3.3f°C" % fmc_temp[-1]
fmc_temp
.
pop
(
0
)
acq_channels
(
fmc
,
carrier
)
time
.
sleep
(
MEAS_SLEEP
)
t1
=
time
.
time
()
print
"FMC temperature reached
%2.1
f°C after
%10.3
fs
\n
"
%
(
TEMP_THRES
,
t1
-
t0
)
# Wait for the FMC temperature to be stable
fmc_temp_cnt
=
0
while
True
:
fmc_temp
.
append
(
fmc
.
get_temp
())
if
fmc_temp_cnt
>=
FIFO_SIZE
:
temp_diff
=
(
max
(
fmc_temp
)
-
min
(
fmc_temp
))
fmc_temp
.
pop
(
0
)
print
"[
%4
d] fmc temp:
%3.3
f°C, temp diff:
%3.3
f°C"
%
(
fmc_temp_cnt
,
fmc_temp
[
-
1
],
temp_diff
)
if
temp_diff
<
TEMP_RIPPLE
:
print
"
\n
Temperature difference in the last
%
d measurements is less than
%2.1
f°C"
%
(
FIFO_SIZE
,
TEMP_RIPPLE
)
break
else
:
print
"
%4
d fmc temp:
%3.3
f°C"
%
(
fmc_temp_cnt
,
fmc_temp
[
-
1
])
fmc_temp_cnt
+=
1
acq_channels
(
fmc
,
carrier
)
time
.
sleep
(
MEAS_SLEEP
)
t2
=
time
.
time
()
print
"FMC temperature is stable after
%10.3
fs"
%
(
t2
-
t0
)
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__'
:
...
...
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