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)