Commit 4ec6d9fe authored by Matthieu Cattin's avatar Matthieu Cattin

Use adc acquisition DMA + averaging instead of current adc value register.

parent a41d44f0
......@@ -9,9 +9,11 @@ import sys
import rr
import time
import os
from numpy import *
from ptsexcept import *
import spec_fmc_adc
import fmc_adc
"""
......@@ -21,12 +23,84 @@ Note: Requires test00.py to run first to load the firmware!
"""
NB_CHANNELS = 4
OFFSET_POS = 0xFFFF
OFFSET_NEG = 0x0000
ADC_POS = 0x0000
ADC_MID = 0x8000
ADC_NEG = 0xFFFC
ADC_TOL = 0x150
PRE_TRIG_SAMPLES = 1000
POST_TRIG_SAMPLES = 100000
NB_SHOTS = 1
ACQ_LENGTH = 50000 # in samples
ACQ_TIMEOUT = 10
# Values for offset DAC
# Note:
# values < 0x8000 represents positive offset
# values > 0x8000 represents negative offset
OFFSET_POS = 0x0000
OFFSET_NEG = 0xFFFF
DAC_SET_SLEEP = 0.1 # in [s]
# Expected ADC values
ADC_NEG = -32768.0
ADC_MID = 0.0
ADC_POS = 32764.0 # not 32767.0 because the ADC is 14-bit left-shifted by 2, the last 3 bit are always 0
ADC_TOL = 200.0
def hex2signed(value):
if(value & 0x8000):
return -((~value & 0xFFFF) + 1)
else:
return value
def acq_config(fmc):
print('Initialise FMC board\n')
# Set trigger
fmc.set_soft_trig()
# Set acquisition
fmc.set_pre_trig_samples(PRE_TRIG_SAMPLES)
fmc.set_post_trig_samples(POST_TRIG_SAMPLES)
fmc.set_shots(NB_SHOTS)
def acq_channels(fmc, spec_fmc):
# Make sure no acquisition is running
fmc.stop_acq()
# Start acquisition
fmc.start_acq()
time.sleep(0.01)
# Trigger
fmc.sw_trig()
# Wait end of acquisition
timeout = 0
while('IDLE' != fmc.get_acq_fsm_state()):
time.sleep(.1)
timeout += 1
if(ACQ_TIMEOUT < timeout):
print "Acquisition timeout. Missing trigger?."
print "Acq FSm state: %s"%fmc.get_acq_fsm_state()
return 1
# Retrieve data trough DMA
trig_pos = fmc.get_trig_pos()
# Enable "DMA done" iinterrupt
spec_fmc.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)
# Disable "DMA done" iinterrupt
spec_fmc.set_irq_en_mask(0x0)
channels_data = [hex2signed(item) for item in channels_data]
return channels_data
def acq_mean(acq_data):
mean_d = []
for channel in range(1,NB_CHANNELS+1):
# calculate mean value for each channel
mean_d.append(mean(acq_data[channel-1::4]))
return mean_d
def main (default_directory='.'):
"""
......@@ -43,8 +117,12 @@ def main (default_directory='.'):
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
spec_fmc = spec_fmc_adc.CSpecFmcAdc100Ms(spec)
fmc = fmc_adc.CFmcAdc100Ms(spec)
# Configuration
acq_config(fmc)
error = 0
# All inputs in calibration mode
......@@ -54,52 +132,63 @@ def main (default_directory='.'):
# Disable test pattern (just in case)
fmc.testpat_dis()
#---------------------------------------------------------------------------
# Set a positive offset on all channels
#---------------------------------------------------------------------------
print('Set positive offset: %.4X' % OFFSET_POS)
for i in range(1, NB_CHANNELS+1):
fmc.dc_offset_calibr(i, OFFSET_POS)
time.sleep(1)
# Read channels current data register
for i in range(1,NB_CHANNELS+1):
adc_value = fmc.get_current_adc_value(i)
print('ADC channel %d value:%d expected value:%d') % (i, adc_value, ADC_POS)
if(ADC_POS != adc_value):
time.sleep(DAC_SET_SLEEP)
# Read channels
acq_data = acq_channels(fmc, spec_fmc)
acq_data_mean = acq_mean(acq_data)
for i in range(len(acq_data_mean)):
print('ADC channel %d value:%d expected value:%d') % (i+1, acq_data_mean[i], ADC_POS)
if(ADC_POS != acq_data_mean[i]):
print('Channel %d offset circuit is malfunctioning')%(i)
error += 1
#raise PtsError('Channel %d offset circuit is malfunctioning'%i)
# Reset offset DACs
#---------------------------------------------------------------------------
# Reset offset DACs, will output mid-range value (0x8000)
#---------------------------------------------------------------------------
print('Reset offset')
fmc.dc_offset_reset()
time.sleep(1)
# Read channels current data register
for i in range(1,NB_CHANNELS+1):
adc_value = fmc.get_current_adc_value(i)
print('ADC channel %d value:%d expected value:%d tolerance:%d') % (i, adc_value, ADC_MID, ADC_TOL)
if((ADC_MID-ADC_TOL > adc_value) | (ADC_MID+ADC_TOL < adc_value)):
time.sleep(DAC_SET_SLEEP)
# Read channels
acq_data = acq_channels(fmc, spec_fmc)
acq_data_mean = acq_mean(acq_data)
for i in range(len(acq_data_mean)):
print('ADC channel %d value:%d expected value:%d +/-%d') % (i+1, acq_data_mean[i], ADC_MID, ADC_TOL)
if((ADC_MID-ADC_TOL > acq_data_mean[i]) | (ADC_MID+ADC_TOL < acq_data_mean[i])):
print('Channel %d offset circuit is malfunctioning')%(i)
error += 1
#raise PtsError('Channel %d offset circuit is malfunctioning'%i)
#---------------------------------------------------------------------------
# Set a negative offset on all channels
#---------------------------------------------------------------------------
print('Set negative offset: %.4X' % OFFSET_NEG)
for i in range(1, NB_CHANNELS+1):
fmc.dc_offset_calibr(i, OFFSET_NEG)
time.sleep(1)
# Read channels current data register
for i in range(1,NB_CHANNELS+1):
adc_value = fmc.get_current_adc_value(i)
print('ADC channel %d value:%d expected value:%d') % (i, adc_value, ADC_NEG)
if(ADC_NEG != adc_value):
time.sleep(DAC_SET_SLEEP)
# Read channels
acq_data = acq_channels(fmc, spec_fmc)
acq_data_mean = acq_mean(acq_data)
for i in range(len(acq_data_mean)):
print('ADC channel %d value:%d expected value:%d') % (i+1, acq_data_mean[i], ADC_NEG)
if(ADC_NEG != acq_data_mean[i]):
print('Channel %d offset circuit is malfunctioning')%(i)
error += 1
#raise PtsError('Channel %d offset circuit is malfunctioning'%i)
# Reset offset DACs
fmc.dc_offset_reset()
time.sleep(DAC_SET_SLEEP)
# Check if an error occured during offset DAC test
if(error != 0):
......
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