Hi,
We have a spectrometer giving out 256 FFT channels. But I am having a bit
problem in reading out the brams using ipython.
I am trying to just read the bram once and see the bram values on a plot.
The command I am using for reading the 32 bit values stored at each address
in BRAM (size = 2048) is :
f = np.fromstring(u.read(bram,1024*4),dtype='int32').byteswap()
plt.figure(aa);plt.plot(f/(2.0**5));
But this will show the data in the BRAM every once in a while (1 in 10), the
same script works fine for the same design giving out 128 FFT channels.
Has anyone encountered this problem before? I have attached the python
script to look at.
Can anyone tell what could be the problem - is it in the script or in the
design?
Thanks for the help.
--
Vikas Asthana
Research Assistant,
Radio Astronomy Systems Research Group,
Brigham Young University,
480, Clyde building,
Provo, UT, USA - 84602.
Email: *[email protected]*
import corr
import numpy as np
from matplotlib import pyplot as plt
import matplotlib
import pylab as p
import time
import itertools
import os
import struct,sys,logging
class Poco():
def __init__(self):
print " Doing Init"
self.u = corr.katcp_wrapper.FpgaClient('169.254.145.13')
self.did_rst =0
self.chipssyncd =0
self.brams=['bram02'] #,'bram13','bram46','bram57','bram810','bram911','bram1214','bram1315']
# def set_params(self,gain=1,acc_len=4,cnt_rst=0)
# u = self.u
# u.write_int('gain',gain)
# u.write_int('acc_len',acc_len)
# u.write_int('cnt_rst',cnt_rst)
def check_chipsync(self):
print " Doing Check Chipsync"
u =self.u
c0 = u.read_int('check_bits1')
c0 = np.bitwise_and(16,c0)
if c0 == 16:
self.chipssyncd = 1
else:
self.chipssyncd =0
print "Done Check Chipsync"
return self.chipssyncd
def rerun_cal(self):
print " Doing Rerun Cal"
os.system('python adc_softcal_dump_jack.py roach030113')
self.did_rst = 0
self.adc_reset()
self.check_chipsync()
if self.chipssyncd == 1:
print "Chips syncd"
else:
print "Chips not syncd"
print " Done Rerun Cal"
def adc_reset(self):
print " Doing Adc reset"
u = self.u
u.write_int('ctrl',0)
u.write_int('ctrl',1)
u.write_int('ctrl',0)
time.sleep(3.0)
u.write_int('ctrl',16)
u.write_int('ctrl',0)
u.write_int('gain',4)
u.write_int('acc_len',1996608)
u.write_int('cnt_rst',0)
u.write_int('cnt_rst',1)
self.did_rst = 1
print " Done Adc Reset"
def set_gain(self,gain=1):
print " Doing Set Gain"
u = self.u
u.write_int('gain',gain)
print " Done Set Gain"
def read_bram(self):
print "doing read Bram"
fpga = self.u
a = dict()
acc_n = [0,0] #,0,0,0,0,0,0]
acc_n[0] = fpga.read_uint('Subsystem03_acc_cnt02')
acc_n[1] = fpga.read_uint('Subsystem03_acc_cnt13')
#acc_n[2] = fpga.read_uint('Subsystem47_acc_cnt02')
#acc_n[3] = fpga.read_uint('Subsystem47_acc_cnt13')
#acc_n[4] = fpga.read_uint('Subsystem811_acc_cnt02')
#acc_n[5] = fpga.read_uint('Subsystem811_acc_cnt13')
#acc_n[6] = fpga.read_uint('Subsystem1215_acc_cnt02')
#acc_n[7] = fpga.read_uint('Subsystem1215_acc_cnt13')
for bram in self.brams:
a[bram]=struct.unpack('>1024l',fpga.read(bram,1024*4,0))
print " Done Reading Bram"
return acc_n, a
def plot_spectrum(self):
print " Doing Plotting"
#matplotlib.pyplot.clf()
u = self.brams
ii = 0
jj = 0
ant = dict()
nn = 1
acc_n, a = self.read_bram()
for bram in u:
print (bram)
for ll in range(0,1):
print (ll)
mm = 0
matplotlib.pylab.figure(nn)
matplotlib.pylab.clf()
matplotlib.pylab.suptitle('Channels \n Integration Number: %i.'%acc_n[ll])
for kk in range(0,1):
ant[ii] = np.asarray(a[bram][jj:jj+256])
#print('ant %d size is : '%(ii),)
#print( np.shape(np.asarray(ant[ii])))
#print(jj)
#print(bram)
#matplotlib.pylab.figure(nn)
#matplotlib.pylab.subplot(1,1,mm+1)
matplotlib.pylab.plot(10*np.log10(np.asarray(ant[ii])+1))
matplotlib.pylab.title('ant %d' %ii )
#matplotlib.pylab.ylim(22,50)
#matplotlib.pylab.xlim(0,256)
jj = jj+512
ii = ii+1
mm = mm+1
jj=256
nn = nn+1
jj=0
self.fig0.canvas.manager.window.after(100, self.plot_spectrum)
print " Done PLotting"
def anim(self):
print " Doing Anim"
plt.close('all')
u = self.u
u.write_int('cnt_rst',0)
u.write_int('cnt_rst',1)
#set up the figure with a subplot to be plotted
self.fig0 = matplotlib.pyplot.figure(1)
self.ax0 = self.fig0.add_subplot(1,1,1)
# start the process
self.fig0.canvas.manager.window.after(100, self.plot_spectrum)
matplotlib.pyplot.show()
print 'Plot started.'
print " Done anim"
def get_data(self):
print " doing get Data"
plt.close('all')
u = self.u
if self.did_rst == 0:
self.adc_reset()
self.check_chipsync()
if self.chipssyncd == 1:
print "Chips Syncd"
else:
print "Chips not syncd"
while self.chipssyncd == 0:
print " Chips not sync'd. Resetting adc"
self.adc_reset()
if self.chipssyncd == 0:
print "Chips not sync'd. Re-running cal script"
self.rerun_cal()
else:
print "Chips syncd"
self.adc_reset()
u.write_int('ctrl',0)
u.write_int('ctrl',14)
aa=0
for bram in self.brams:
#f = np.fromstring(struct.unpack('>1024l',u.read(bram,1024*4,0)))
f = np.fromstring(u.read(bram,1024*4),dtype='int32').byteswap()
print(f[79])
print(f[80])
print(f[81])
print(f[82])
plt.figure(aa);plt.plot(f/(2.0**5)); #plt.xlim(25,50);
#plt.figure(aa+1);plt.plot(f/(2.0**5)); plt.xlim(29,37);
aa = aa+2
plt.show()
print " done get data"