Commit 0ebb73e1 authored by Ross Millar's avatar Ross Millar

Add script fo

parent 6f3b026c
#!/bin/sh
# Copyright CERN, 2011
# Author: Ross Millar <ross.millar@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
LOGDIR=./log_fmcadc200k16b11cha
mkdir -p $LOGDIR
sudo rm -fr $LOGDIR/pts*
serial=$1
if [ x$1 = x"" ]; then
echo -n "Please, input SERIAL number: "
read serial
fi
if [ x$serial = x"" ]; then
serial=0000
fi
extra_serial=$2
if [ x$2 = x"" ]; then
echo -n "Please, input extra SERIAL number: "
read extra_serial
fi
if [ x$extra_serial = x"" ]; then
extra_serial=0000
fi
echo -n "--------------------------------------------------------------\n"
sudo ./pts.py -b FmcAdc200k16b11cha -s $serial -e $extra_serial -t./test/fmcadc200k16b11cha/python -l $LOGDIR 08 01 09 03 04 05 06
echo -n "Press enter to exit... "
read tmp
#! /usr/bin/env python
# coding: utf8
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc
from pylab import *
if __name__ == '__main__':
"""
Channel order test:
Forces ADC channel values digitally to their channel number, i.e. 1 - 16
Does acquisitions and checks all the channel orders are correct
"""
GN4124_CSR = 0x0
test_data =0
error_position =[]
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
gn4124 = gn4124.CGN4124(spec, GN4124_CSR)
fmc = fmc_adc.CFmcAdc100ks(spec)
# Set up memory pages
pages = gn4124.get_physical_addr()
chan = 1
post_trig = 9
pre_trig = 10
fmc.channel_order_en()
iteration_number = int(raw_input(" Number of iterations : "))
for iteration in range(iteration_number):
print "Iteration Number : %s"%iteration
channel_data = fmc.do_acq(1, "camera_link" ,"N", post_trig ,pre_trig,0)
for i in range(len(channel_data)):
for j in range(len(channel_data[0])):
if channel_data[i][j]!= i+1:
print "Error : Expected %d... %d found"%( i+1, channel_data[i][j])
raw_input(" Error Found : Press enter to continue ")
fmc.channel_order_dis()
print '\nBye bye ...'
sys.exit()
#! /usr/bin/env python
# coding: utf8
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc
#import fmc_adc_test_suite
from pylab import *
if __name__ == '__main__':
"""
Does successive burst writes to DDR3 controller. Requires hdl in 'misc' on ohwr for this project
Functions remain in fmc_adc.py
bug : ddr test contrroler hdl doesnt run on first attempt
"""
GN4124_CSR = 0x0
test_data = 1
ddr3_calib_done = 0x3 <<2
error_position =[]
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
gn4124 = gn4124.CGN4124(spec, GN4124_CSR)
fmc = fmc_adc.CFmcAdc100ks(spec)
#PAGES
write_size = int(raw_input("How many 16 bit writes ? : "))
fmc.ram_write_config(1,1,0x1)
fmc.ram_write_start()
while fmc.ram_wr_finished()!=1:
time.sleep(.1)
print "clearing ram"
raw_input("\nPress Enter for Ram Write")
# Do a number of 16 byte writes
for i in range(write_size):
start_write = i*8
end_write = (i*8)+7
fmc.ram_write_config(start_write,end_write,2)
fmc.ram_write_start()
while fmc.ram_wr_finished()!=1:
time.sleep(.025)
print "Finished Ram Write"
print "Last address position = %d" %((write_size*8)-1)
print '\nBye bye ...'
sys.exit()
#! /usr/bin/env python
# coding: utf8
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc
#import fmc_adc_test_suite
from pylab import *
if __name__ == '__main__':
"""
Does writes to DDR3 controller. Requires hdl in 'misc' on ohwr for this project
Functions remain in fmc_adc.py
bug : ddr test contrroler hdl doesnt run on first attempt
"""
GN4124_CSR = 0x0
test_data = 1
# OFFSETS for CSR1
ddr3_calib_done = 0x3 <<2
# Address of CSR2
error_position =[]
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
gn4124 = gn4124.CGN4124(spec, GN4124_CSR)
fmc = fmc_adc.CFmcAdc100ks(spec)
# Set local bus frequency
gn4124.set_local_bus_freq(160)
#print("GN4124 local bus frequency: %d") % gn4124.get_local_bus_freq()
#PAGES STUFF
pages = gn4124.get_physical_addr()
integer_plot = int(raw_input("integer plot : "))
start_write = int(raw_input("start position for write : "))
end_write = int(raw_input("end position for write : "))
print " 1 = Clear RAM, 2 = Write addr value, 3 = Write ABCDABCD, 4 = Write addr val to all addresses "
mode = int(raw_input("mode of operation : ")) & 0x7
# FMC RAM WRITE CONFIG
fmc.ram_write_config(start_write,end_write,mode)
time.sleep(.1)
# START THE RAM WRITE
fmc.ram_write_start()
time.sleep(.1)
# WAIT FOR THE WRITE TO FINISH
while fmc.ram_wr_finished()!=1:
time.sleep(.1)
print "waiting for ram write finish"
# SET UP THE DMA
print '\nReading data from memory page 1 (before)'
page1_data_before = gn4124.get_memory_page(1)
# print '\nPreparing DMA'
dma_length = 0x1000 # DMA length in bytes
gn4124.add_dma_item((start_write<<2)+(0*dma_length),pages[1], dma_length, 0,1)
gn4124.add_dma_item((start_write<<2)+(1*dma_length),pages[2], dma_length, 0,1)
gn4124.add_dma_item((start_write<<2)+(2*dma_length),pages[3], dma_length, 0,0)
page0_data = gn4124.get_memory_page(0)
gn4124.start_dma()
while('Done' != gn4124.get_dma_status()):
#print("DMA controller status : %s") % gn4124.get_dma_status()
time.sleep(.5)
print '\nWaiting for interrupt'
gn4124.wait_irq() # what genereates this interupt?
print '\nInterrupt received'
print("DMA controller status : %s") % gn4124.get_dma_status()
print "DDR calibration", fmc.check_ddr3_calib()
page1_data = gn4124.get_memory_page(1)
page2_data = gn4124.get_memory_page(2)
page3_data = gn4124.get_memory_page(3)
channels = []
channels_test=[]
for i in range(2**10):
channels_test.append(page1_data[i]&0xFFFFFFFF)
for i in range(2**10):
channels_test.append(page2_data[i]&0xFFFFFFFF)
print "\n\nexpected start position",hex(start_write)
print "start address read", hex(channels_test[0])
print "number of address locations out by", hex(start_write - channels_test[0]),"\n\n"
for i in range(2**10):
channels.append(page1_data[i] >>16 )
channels.append(page1_data[i] & 0xFFFF)
#channels.append(page1_data[i] & 0xFFFFFFFF)
for i in range(2**10):
channels.append(page2_data[i]>>16)
channels.append(page2_data[i] & 0xFFFF)
#CONVERT FROM 2s COMPLIMENT
#if integer_plot==1:
# for i in range(len(channels)):
# if(channels[i] & 0x8000):
# channels[i] = -0x10000 + channels[i]
# SORT INTO CHANNELS
time_base = arange(0,(len(channels)/16),1)
channel1 = channels[0::16]
channel2 = channels[1::16]
channel3 = channels[2::16]
channel4 = channels[3::16]
channel5 = channels[4::16]
channel6 = channels[5::16]
channel7 = channels[6::16]
channel8 = channels[7::16]
channel9 = channels[8::16]
channel10 = channels[9::16]
channel11 = channels[10::16]
channel12 = channels[11::16]
channel13 = channels[12::16]
channel14 = channels[13::16]
channel15 = channels[14::16]
channel16 = channels[15::16]
# WRITE TO FILE
file = open("adc_100k_acq.txt", 'w')
for i in range(len(channel1)):
if integer_plot==1:
file.write("%5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d\n" % (time_base[i], channel1[i], channel2[i], channel3[i], channel4[i], channel5[i], channel6[i], channel7[i], channel8[i], channel9[i], channel10[i], channel11[i], channel12[i], channel13[i], channel14[i], channel15[i], channel16[i]))
else:
file.write("%5d, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X\n" % (time_base[i], channel1[i], channel2[i], channel3[i], channel4[i], channel5[i], channel6[i], channel7[i], channel8[i], channel9[i], channel10[i], channel11[i], channel12[i], channel13[i], channel14[i], channel15[i], channel16[i]))
print '\nBye bye ...'
sys.exit()
#! /usr/bin/env python
# coding: utf8
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc
from pylab import *
if __name__ == '__main__':
GN4124_CSR = 0x0
addr_type = int(raw_input("decimal address -1 , hex addr - 2 : ")) & 0x3
if addr_type == 2:
hex_input_start = raw_input("Enter a start address in hex : ")
dma_start = int(hex_input_start, 16) & 0b1111111111111111111111111
hex_input_end = raw_input("Enter the end address in hex : ")
dma_end = int(hex_input_end, 16) & 0b1111111111111111111111111
else:
dma_start = int(raw_input("input start position : "))
dma_end = int(raw_input("input end position : "))
integer_plot = 1
print "dma start address selected", dma_start
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
gn4124 = gn4124.CGN4124(spec, GN4124_CSR)
fmc = fmc_adc.CFmcAdc100ks(spec)
fmc.stop_acq()
# Function in fmc_adc.py
pages_returned = fmc.dma_access(dma_start,dma_end)
channels = []
for j in range(len(pages_returned)):
for i in range(len(pages_returned[j])):
channels.append(pages_returned[j][i] & 0xFFFFFFFF)
#CONVERT FROM 2s COMPLIMENT
if integer_plot==1:
for i in range(len(channels)):
if(channels[i] & 0x8000):
channels[i] = -0x10000 + channels[i]
# Channels data kept in 32 bits so addr
channel1 = channels[0::8]
channel2 = channels[1::8]
channel3 = channels[2::8]
channel4 = channels[3::8]
channel5 = channels[4::8]
channel6 = channels[5::8]
channel7 = channels[6::8]
channel8 = channels[7::8]
time_base = arange(0,len(channel1),1 )
# WRITE TO FILE
file = open("adc_100k_acq.txt", 'w')
for i in range(len(channel1)):
if integer_plot==1:
file.write("%5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d\n" % (time_base[i], channel1[i], channel2[i], channel3[i], channel4[i], channel5[i], channel6[i], channel7[i], channel8[i]))
else:
file.write("%5d, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X\n" % (time_base[i], channel1[i], channel2[i], channel3[i], channel4[i], channel5[i], channel6[i], channel7[i], channel8[i]))
print '\nBye bye ...'
sys.exit()
This diff is collapsed.
#! /usr/bin/env python
# coding: utf8
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
if __name__ == '__main__':
"""
This generates a GNUPLOT file for a text file generated by an ADC
Based on the output of the 16 bit 200k ADC,
Assumes the generated text file has data from 16 chanels
Currently required the text file to be called ... adc_100k_acq.txt
"""
# GNU PLOT GENERATION FUNCTIONS
class Plot_options:
def __init__(self,numero):
self.title=raw_input("Enter your Plot title : ")
self.xlabel=raw_input("Enter the label for your X-Axis : ")
self.ylabel=raw_input("Enter the label for your Y-Axis : ")
self.numero=numero
def area(self):
return self.numero * 2
def file_write(num_plots,array):
anotherarray=["Default Settings","New Settings"]
settings=simple_menu(anotherarray,"\nGNUPLOT OPTIONS")
if settings==1:
options=["dots","lines","curves"]
graph_style=simple_menu(options,"Select plot style")
style=options[graph_style-1]
filename_choice=simple_menu(["Write to file \"adcfmc200kdata.plot\"","write to a different file"],"Choose write file")
if filename_choice==1:
filename="adcfmc200kdata.plot"
elif filename_choice==2:
filename=str(raw_input("\n\nGive the name of the file you wish to write to, ending in .plot \n\n"))
file=open(filename,'w')
file.write("# Gnuplot script file for plotting data in file \"adc_acq.txt\" \n\n")
file.write("set autoscale # scale axes automatically \n")
file.write("unset log # remove any log-scaling \n")
file.write("unset label # remove any previous labels \n")
file.write("set title \"Adc-Fmc-200ks\" \n")
file.write("set xlabel \"Sample number\" \n")
file.write("set ylabel \"ADC raw data\" \n\n")
file.write("plot ")
elif settings==2:
plotinfo=Plot_options(2)
options=["dots","lines","curves"]
graph_style=simple_menu(options,"Select plot style")
style=options[graph_style-1]
filename_choice=simple_menu(["Write to file \"adc_fmc_100k_acq2.plot\"","write to a different file"],"Choose write file")
if filename_choice==1:
filename="adcfmc200kdata.plot"
elif filename_choice==2:
filename=str(raw_input("\n\nGive the name of the file you wish to write to, ending in .plot \n\n"))
file=open(filename,'w')
file.write("# Gnuplot script file for plotting data in file \"adc_acq.txt\" \n\n")
file.write("set autoscale # scale axes automatically \n")
file.write("unset log # remove any log-scaling \n")
file.write("unset label # remove any previous labels \n")
file.write("set title \"%s\" \n" %(plotinfo.title) )
file.write("set xlabel \"%s\" \n" %(plotinfo.xlabel) )
file.write("set ylabel \"%s\" \n\n" %(plotinfo.ylabel) )
file.write("plot ")
for i in range(num_plots):
file.write("\"adc_100k_acq.txt\" using 1:%d title \"Channel %d\" with %s" %((array[i]+1),array[i],style))
if i<=(num_plots-2):
file.write(",\\\n")
file.write("\n\npause -1 \"Hit return to continue\"")
print "\n\nFile \"%s\" has been written \n\n" % (filename)
def simple_menu(array,Description):
print Description
for i in range(len(array)):
print i+1,")", array[i]
return int(raw_input("please choose an option : "))
# CREATE GNUPLOT FILE
array=[]
num_of_channels=16
channel_selections=["All Channels","First ADC chip","Second ADC chip","Custom"]
print "\nCREATING THE PLOT FILE.....\n"
channel_choice=simple_menu(channel_selections,"Choose which channels to Plot")
if channel_choice==1:
for chans in range(num_of_channels):
array.append(chans+1)
k=num_of_channels
if channel_choice==2:
for chans in range(0,num_of_channels/2,1):
array.append(chans+1)
k=num_of_channels/2
if channel_choice==3:
for chans in range(num_of_channels/2,num_of_channels,1):
array.append(chans+1)
k=num_of_channels/2
if channel_choice==4:
k=int(raw_input("How many ADC channels do you wish to plot? "))
print "Select which channels you want to plot"
for h in range(k):
array.append(int(raw_input("choice %d :" %(h+1))))
print array
file_write(k,array)
print '\nBye bye ...'
sys.exit()
#! /usr/bin/env python
# coding: utf8
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc
from pylab import *
if __name__ == '__main__':
"""
Checks that the number of pre and post trigger samples are written to RAM.
Sets firmware to the a test mode which writes the value of the addr to that addr location
Reads the data back from the pre trig position and checks that the numbers are consecutive
right through to the end of post trig data.
After every acquisiton in the mode mentioned previously, it switches back to the normal mode,
and allows a longer time before the acq so that the list of consecutive addresses are overwritten
in ram
"""
GN4124_CSR = 0x0
ddr3_calib_done = 0x3 <<2
# Commands and variables
acq_start = 0x01
acq_stop = 0x02
decim_val = 1
trig_delay_val = 0
sw_trig = 0x00000001
adc_cont_start = 1
attempt_trig_read = 1
software_trigger = 0
integer_plot = 1
thresh_trig = 0
#Threshold Conditions
trigger_threshold=0x0001
slope=0
channel_for_thresh_trig=0x6
sw_trig_en=1
hw_trig_en=0
# acquires settings from user
shots_num = int(raw_input("input shots number : "))
pre_trig_val = int(raw_input(" input pre trig number : "))
post_trig_val =int(raw_input(" input post trig number : "))
num_it = int(raw_input("set number of test loop iterations : "))
test_data =0
error_position =[]
#trigger_register=((trigger_threshold<<16)+(0x0<<8)+(slope<<7)+(channel_for_thresh_trig<<2)+(sw_trig_en<<1) +hw_trig_en)
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
gn4124 = gn4124.CGN4124(spec, GN4124_CSR)
fmc = fmc_adc.CFmcAdc100ks(spec)
# Why am i not using the test suite version and does it matter?
# Set up memory pages
pages = gn4124.get_physical_addr()
# CSR CONFIGURATION
fmc.set_shots(shots_num)
time.sleep(.1)
fmc.set_pre_trig_samples(pre_trig_val)
time.sleep(.1)
fmc.set_post_trig_samples(post_trig_val)
time.sleep(.1)
fmc.set_decimation(decim_val)
time.sleep(.1)
fmc.set_trig_config(hw_trig_en, sw_trig_en, channel_for_thresh_trig, trigger_threshold, slope,trig_delay_val,thresh_trig)
time.sleep(.1)
fmc.set_decimation(1)
time.sleep(.1)
for iteration in range(num_it):
# Toggle between test data and normal mode
test_data=~test_data & 0x1
if test_data==1:
fmc.test_data_en()
time.sleep(.1)
else:
fmc.test_data_dis()
time.sleep(.1)
print "Test data %d"%test_data
# Stop Acq
fmc.stop_acq()
fmc.get_status()
while fmc.get_status()!=0x1:
time.sleep(.1)
# Start Acq
fmc.start_acq()
fmc.start_adc_cont()
time.sleep(.1)
# If a software trigger test
if sw_trig_en==1:
# Wait for State machine to reach correct state
while fmc.get_status() !=3: #"WAIT_TRIG"
time.sleep(.1)
if test_data == 1:
time.sleep(1)
print "Sleep for 0.5 second"
else:
time.sleep(3)
print "Sleep for 3 seconds - allows test results to be erased"
if sw_trig_en==1:
if shots_num>1:
for i in range(shots_num-1):
fmc.sw_trig()
smething=raw_input("Press Enter once you have changed signal type")
while fmc.get_status()!=0x3:
time.sleep(.2)
fmc.sw_trig()
else:
fmc.sw_trig()
print "Single Shot Trigger Applied"
fmc.get_shots()
else:
while fmc.get_status()!=0x1:
time.sleep(1)
time.sleep(.1)
# CHECK IF DDR3 SYNCED PROPERLY:
while fmc.check_ddr3_calib()!=0x1:
time.sleep(.5)
print "DDR not calibrated..."
# Find trigger position - bottom 16 bits of register
trigger_position=fmc.get_trig_pos() & 0xFFFFFFFF
# Define Where the acquisition starts
dma_start = trigger_position - (pre_trig_val*8)
dma_end = trigger_position + 7 +(post_trig_val*8)
page1_data_before = gn4124.get_memory_page(1)
dma_length = 0x1000 # DMA length in bytes
# READ FROM DDR TO MEMORY PAGES
#if (dma_end-dma_start)<=dma_length:
print "DMA LENGTH: ", dma_length
print "DMA START :", dma_start
print "DMA START (hex): ", hex(dma_start)
print "DMA END: ", dma_end
print "DMA END (hex): ", hex(dma_end)
print "trigger_position: ", trigger_position
print "trigger position (hex): ", hex(trigger_position)
print "DMA ACCESS LENGTH REQUIRED = ", dma_end-dma_start +1
# Retrieve 3 Pages of Data
if shots_num>1:
print "DMA from Start of RAM"
gn4124.add_dma_item(0*dma_length,pages[1], dma_length, 0,1)
gn4124.add_dma_item(1*dma_length,pages[2], dma_length, 0,1)
gn4124.add_dma_item(1*dma_length,pages[3], dma_length, 0,0)
else:
gn4124.add_dma_item((dma_start<<2)+(0*dma_length),pages[1], dma_length, 0,1)
gn4124.add_dma_item((dma_start<<2)+(1*dma_length),pages[2], dma_length, 0,1)
gn4124.add_dma_item((dma_start<<2)+(2*dma_length),pages[3], dma_length, 0,0)
# DMA
page0_data = gn4124.get_memory_page(0)
print("DMA controller status : %s") % gn4124.get_dma_status()
print '\n Start DMA transfer'
gn4124.start_dma()
while('Done' != gn4124.get_dma_status()):
print("DMA controller status : %s") % gn4124.get_dma_status()
time.sleep(.5)
print '\nWaiting for interrupt'
gn4124.wait_irq()
print '\nInterrupt received'
print("DMA controller status : %s") % gn4124.get_dma_status()
page1_data = gn4124.get_memory_page(1)
page2_data = gn4124.get_memory_page(2)
page3_data = gn4124.get_memory_page(3)
channels = []
channels_test = []
for i in range(2**10):
channels_test.append(page1_data[i]&0xFFFFFFFF)
for i in range(2**10):
channels_test.append(page2_data[i]&0xFFFFFFFF)
if test_data == 1:
print "\n\nExpected start position",hex(dma_start)
print "Start address read", hex(channels_test[0])
if hex(dma_start) !=hex(channels_test[0] ):
print "Error : Data received from address does not equal address value"
raw_input("Examine data : Press Enter to continue ")
for i in range(2**10):
channels.append(page1_data[i] >>16 )
channels.append(page1_data[i] & 0xFFFF)
for i in range(2**10):
channels.append(page2_data[i]>>16)
channels.append(page2_data[i] & 0xFFFF)
#CONVERT FROM 2s COMPLIMENT
if integer_plot==1:
for i in range(len(channels)):
if(channels[i] & 0x8000):
channels[i] = -0x10000 + channels[i]
# SORT INTO CHANNELS
time_base = arange(0,(len(channels)/16),1)
channel1 = channels[0::16]
channel2 = channels[1::16]
channel3 = channels[2::16]
channel4 = channels[3::16]
channel5 = channels[4::16]
channel6 = channels[5::16]
channel7 = channels[6::16]
channel8 = channels[7::16]
channel9 = channels[8::16]
channel10 = channels[9::16]
channel11 = channels[10::16]
channel12 = channels[11::16]
channel13 = channels[12::16]
channel14 = channels[13::16]
channel15 = channels[14::16]
channel16 = channels[15::16]
# WRITE TO FILE
file = open("adc_100k_acq.txt", 'w')
for i in range(len(channel1)):
if integer_plot==1:
file.write("%5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d, %5d\n" % (time_base[i], channel1[i], channel2[i], channel3[i], channel4[i], channel5[i], channel6[i], channel7[i], channel8[i], channel9[i], channel10[i], channel11[i], channel12[i], channel13[i], channel14[i], channel15[i], channel16[i]))
else:
file.write("%5d, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X, %5X\n" % (time_base[i], channel1[i], channel2[i], channel3[i], channel4[i], channel5[i], channel6[i], channel7[i], channel8[i], channel9[i], channel10[i], channel11[i], channel12[i], channel13[i], channel14[i], channel15[i], channel16[i]))
# Length of acq in terms of 32 bit words
length_of_acq = (pre_trig_val*8)+8+(post_trig_val*8)
print "length of acquisition in 32bit words: ", length_of_acq
print "num of acqs = ",(length_of_acq/8)
pos_of_break = []
# Loop just passed the acq lenghts
if test_data==1:
for j in range(length_of_acq+10):
# Look for break in consecutive numbers
if channels_test[j]!=channels_test[j+1]-1 :
# Note the position of the break
pos_of_break.append(j)
print pos_of_break
if (pos_of_break[0]+1)==length_of_acq:
print "No problems"
else:
error_position.append(pos_of_break[0])
raw_input("Press Enter Once the data has been examined")
print "Number of errors = ",len(error_position)
print "Iteration number ",iteration
print "Number of errors", len(error_position)
print "Position of Errors", error_position
print "Predicted positon of change : ",length_of_acq
print '\nBye bye ...'
sys.exit()
#! /usr/bin/env python
# coding: utf8
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc
from pylab import *
import math
if __name__ == '__main__':
"""
Sinewave test
Requires sinewave input
Takes an acquired sinewave and compares to 2 ideal sinewaves,
an upper threshold and a lower threshold. If the acquired
sinewave is not within this an error is produced and the data is written to a file
"""
glitch_count = 0
error_threshold = 10
hw_en =1
sw_en =0
chan = 0xB
int_thresh = 0x0001
slope = 0
delay = 0
edge_detect =1
iteration = 0
thresh_trig_en = 1
edge_detection = 1
pre_trig = 0
post_trig = 500
# Acquires settings from user
for i in range(11):
print ("Chan %d - Camera Link %d")%(i+1,i+1)
# Obtain Data from user
chan = int(raw_input("Which Channel is the Sinewave input to? :"))
frequency_of_wave = int(raw_input("Please input the frequency of the sine wave : "))
num_of_loops = int(raw_input("Please select the number of iterations for the test : "))
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
gn4124 = gn4124.CGN4124(spec, 0x0)
fmc = fmc_adc.CFmcAdc100ks(spec)
# Carry out acquisition on channel with the sinewave input -
#channel_data = fmc.do_acq(chan, "chan_select" ,"N",post_trig ,pre_trig,thresh_trig_en,edge_detection)
# Set trigger Register
fmc.set_trig_config(hw_en,sw_en,chan,int_thresh,slope,delay,edge_detect)
for loop in range(num_of_loops):
channel_data = fmc.do_acq(chan, "chan_select" ,"n",500,0,1)
sine_wave=[]
time_base=[]
# Generated sinewave constants
amplitude = max(channel_data)
perfect_sine_high =[]
perfect_sine_low =[]
rad = 2*math.pi
sampling_rate = 200000
num_acq = post_trig + pre_trig + 1
no_samples_per_period = float(sampling_rate)/float(frequency_of_wave)
num_waves = float(num_acq)/no_samples_per_period
ideal_wave_size = (num_acq/num_waves)
position_of_ideal_peak = (num_acq/(4*num_waves))
# Detect Position of Peak
i = 0
peak_pos =0
num_1 = channel_data[0]
num_2 = channel_data[1]
if num_1<num_2:
i=0
while (num_1<num_2):
num_1=channel_data[i]
num_2=channel_data[i+1]
i=i+1
peak_pos = i
elif num_1>num_2:
i = 0
while (num_1>num_2):
num_1=channel_data[i]
num_2=channel_data[i+1]
i=i+1
trough_pos = i
peak_pos = trough_pos + (ideal_wave_size/2)
for i in range(int(num_acq)+1):
argument = (((float(i)*num_waves)/float(num_acq))*float(rad))
#print argument
sine_wave.append( int(amplitude*math.sin(argument)))
time_base.append(i)
# generate a couple of sine waves, an upper bound and a lower bound
# calculate their amplitude by measuring the the channel6 sine wave with min and max functions
for i in range(int(num_acq)):
argument = (((float(i)*num_waves)/float(num_acq))*float(rad))
perfect_sine_high.append( int(amplitude*math.sin(argument)) +1000 )
perfect_sine_low.append( int(amplitude*math.sin(argument)) -1000 )
time_base.append(i)
size_sine_list = len(perfect_sine_high)
# Align waves
if peak_pos >position_of_ideal_peak:
align_wave = (ideal_wave_size - (peak_pos - position_of_ideal_peak) )
elif peak_pos <=position_of_ideal_peak:
#align_wave = 26 - peak_pos
align_wave = position_of_ideal_peak - peak_pos
else:
align_wave = 0
"""
print "Wave aligned by...", int(align_wave)
print "Ideal peak : ",int(position_of_ideal_peak)
print "Real peak : ", peak_pos
print "Ideal wave size : ",ideal_wave_size
"""
glitch_found = 0
if len(channel_data)<len(perfect_sine_high):
loop_val = len(channel_data)
else:
loop_val = len(perfect_sine_high)
for i in range(loop_val):
real_val = channel_data[i]
upper_bound = perfect_sine_high[i+int(align_wave)]
lower_bound = perfect_sine_low[i+int(align_wave)]
if real_val<lower_bound or real_val>upper_bound:
glitch_found = 1
if glitch_found ==1:
print "glitch found in result"
else:
print "\n Valid Result\n"
"""
for i in range(len(channel_data)):
channel_data[i] = channel_data[i] * 0.000152
for i in range(len(perfect_sine_high)):
perfect_sine_high[i] = perfect_sine_high[i] * 0.000152
for i in range(len(perfect_sine_low)):
perfect_sine_low[i] = perfect_sine_low[i] * 0.000152
"""
if glitch_found ==1:
iteration = iteration +1
file_string = "adc_100k_acq_" + str(glitch_count) +".txt"
if iteration ==1:
file_string = "adc_100k_acq.txt"
# WRITE TO FILE
file = open(file_string, 'w')
for i in range(len(channel_data)):
file.write("%5d, %5f, %5f, %5f\n" % (time_base[i], channel_data[i], perfect_sine_high[i+int(align_wave)], perfect_sine_low[i+int(align_wave)]))
if iteration == error_threshold:
print "Error threshold reached...Please examine results "
break
print " %d Errors found from %d iterations"%(iteration,num_of_loops)
print "Examine results"
print '\nBye bye ...'
sys.exit()
#! /usr/bin/env python
# coding: utf8
# Copyright CERN, 2011
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
import sys
import rr
import time
import os
import fmc_adc_test_suite
from ptsexcept import *
import csr
"""
test00: Load firmware and test mezzanine presence line.
For test suite boards with 6ch adcs this test is required to be run first
"""
def main (default_directory='.'):
path_fpga_loader = '../firmwares/fpga_loader';
path_firmware = '../firmwares/TestSuite_6ch_ref.bin';
firmware_loader = os.path.join(default_directory, path_fpga_loader)
bitstream = os.path.join(default_directory, path_firmware)
os.system( firmware_loader + ' ' + bitstream)
time.sleep(2);
# Objects declaration
spec = rr.Gennum()
fmc = fmc_adc_test_suite.CFmcAdc100ks(spec)
# Check bitsteam type
bitstream_type = fmc.bitstream_type()
print('bitstream type:%.8X') % bitstream_type
if(bitstream_type == 0xFFFFFFFF):
raise PtsCritical ("Firmware not properly loaded.")
print "Pts Critical - firmware not loaded properly"
if(bitstream_type != 0x1):
raise PtsCritical ("Wrong bitstream type.")
print "Pts Critical - wrong bitstream"
# Dump carrier CSR to log
print("PCB version : %d") % ( fmc.pcb_version() ) # used to be a mask here
print("Carrier type : %d") % ( fmc.carrier_type()) # and here
print("Bitstream type : 0x%.8X") % (fmc.bitstream_type())
print("Bitstream date : 0x%.8X") % (fmc.bitstream_date())
print("Status : 0x%.8X") % (fmc.carrier_csr_sta())
print("Control : 0x%.8X") % (fmc.carrier_csr_ctl())
# Check mezzanine presence flag
status = fmc.check_mez_present()
print('carrier csr :%.8X') % status
if(status & 0x1):
print "Pts Critical - mez not pres"
raise PtsCritical ("Mezzanine not present or PRSNT_M2C_L faulty.")
if __name__ == '__main__' :
main()
#! /usr/bin/env python
# coding: utf8
# Copyright CERN, 2011
# Author: Ross Millar <ross.millar@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
## TEST FOR VCXO
import sys
import os
import os.path
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc_test_suite
from pylab import *
from ptsexcept import *
"""
Same as Test Suite test02 - however for FMCs with 6ch ADCs
Counts set number of clock ticks on the mez clock, in terms of the system clock.
Writes a new value to the DAC, which alters the mezzanine clock speed
Counts the same number of clock ticks on the mezzanine clock again
Compares the 2 resuls to see if the mez clock has changed appropriately
"""
def main(default_directory='.') :
# Objects declaration
spec = rr.Gennum()
fmc = fmc_adc_test_suite.CFmcAdc100ks(spec)
# Reset DAC register - Set VCXO to lowest frequency
fmc.spi_dac_write(0x0000)
# Number of sys clock ticks for counter on mezzanine clock to complete count
result = fmc.clock_comparison()
time.sleep(.1)
fmc.spi_dac_write(0xFFFF)
time.sleep(.1)
# Number of sys clock ticks for counter on mezzanine clock to complete count
result_1 = fmc.clock_comparison()
print "VCXO at lowest frequency - Number of system clock ticks for mezzanine clock count : %d" %result
print "VCXO at highest frequency - Number of system clock ticks for mezzanine clock count : %d" %result_1
if (result - result_1) >10:
print "DAC and VCXO fully working"
else:
print "Potential problem with the DAC"
print "Potential problem with the VCXO"
raise PtsError("VCXO or DAC operation failed")
if __name__ == '__main__':
main()
#!/usr/bin/env python
#coding: utf8
# Copyright CERN, 2011
# Author: Ross Millar <ross.millar@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc_test_suite
import fmc_adc
import cp210x_gpio
from pylab import *
#from ptsexcept import *
import fcntl, struct, termios, os
import time
import array
def main (default_directory='.'):
"""
path_fpga_loader = '../firmwares/fpga_loader';
path_firmware = '../main_firmware_8ch_ref.bin';
firmware_loader = os.path.join(default_directory, path_fpga_loader)
bitstream = os.path.join(default_directory, path_firmware)
os.system( firmware_loader + ' ' + bitstream)
time.sleep(2);
#main_firmware_8ch_ref.bin
#Requires sinewave input
#Does an acquisition with a threshold trigger,
#checks the acquired data to see if it matches the result expected.
"""
hw_en =1
sw_en =0
chan_for_thresh = 0xB # check that this is masked in the fmc class
int_thresh = 0xF000 # 16 bit in twos comp
slope = 1 # 1 for positive, 0 for negative
delay = 0 # Trigger delay
edge_detect = 1 # Trig on Rising or falling edges, depends on slope
pre_trig_val = 100
post_trig_val = 500
thresh_negative = 0
thresh_positive = 0
error=0
print int(int_thresh)
# Object Declaration
spec = rr.Gennum() # bind to the SPEC board
fmc = fmc_adc.CFmcAdc100ks(spec)
# Set trigger Register
fmc.set_trig_config(hw_en,sw_en,chan_for_thresh,int_thresh,slope,delay,edge_detect)
#print bin(fmc.get_trig_config())
# Do acq on the same channel as selected channel for thresh trig
result = fmc.do_acq(chan_for_thresh, "chan_select" ,"n",post_trig_val,pre_trig_val,1)
#print bin(fmc.get_trig_config())
#print result
if (int_thresh & 0x8000) >> 15 ==0x1:
int_thresh = -0x10000 + int_thresh
print "converted int_thresh", int_thresh
thresh_negative = 1
else:
thresh_positive = 1
if thresh_positive and (slope == 0):
print "Thresh positive and slope positive"
if result[pre_trig_val-1]>int_thresh:
error = 1
if result[pre_trig_val]<=int_thresh:
error = 1
elif thresh_positive and (slope == 1):
if result[pre_trig_val-1]<int_thresh:
error = 1
if result[pre_trig_val]>=int_thresh:
error = 1
elif thresh_negative and (slope == 0):
if result[pre_trig_val-1]>int_thresh:
error = 1
if result[pre_trig_val]<=int_thresh:
error = 1
elif thresh_negative and (slope == 1):
if result[pre_trig_val-1]<int_thresh:
error = 1
if result[pre_trig_val]>=int_thresh:
error = 1
if error == 1:
print "Error with threshold trigger"
else:
print "Thresh Trig as expected"
for i in range(len(result)):
result[i] = result[i]*0.000152
time_base = arange(0,len(result),1)
#Change to Voltage level (depends on 'range setting in adc')
int_thresh=int_thresh*0.000152
# WRITE TO FILE
file = open("adc_100k_acq.txt", 'w')
for i in range(len(result)):
file.write("%5d, %5f, %5f\n" % (time_base[i], int_thresh, result[i]))
if __name__ == '__main__':
main()
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