Commit 42357774 authored by Jan Pospisil's avatar Jan Pospisil

moved AD9512 Config/Check methods to proper class

parent 5a5ceb58
from Spi import *
from CommonFunctions import *
class AD9512(Spi):
Ad9512Config = {
_SpiConfig = {
"Channel": 0,
"CPol": 0,
"CPha": 0,
......@@ -13,7 +14,7 @@ class AD9512(Spi):
}
def __init__(self, wbOverlay, SpiBaseAddress, SpiOffset = 0):
super(AD9512, self).__init__(wbOverlay, self.Ad9512Config, SpiBaseAddress, SpiOffset)
super(AD9512, self).__init__(wbOverlay, self._SpiConfig, SpiBaseAddress, SpiOffset)
def Write(self, Address, Data, SelfCommit = False):
RnW = 0
......@@ -38,4 +39,26 @@ class AD9512(Spi):
return Data
def Commit(self):
self.Write(0x5a, 1)
\ No newline at end of file
self.Write(0x5a, 1)
def Config(self, Config):
for Register in Config:
Address = Register[0]
Data = Register[1]
self.Write(Address, Data)
self.Commit()
def Check(self, Config):
print "Checking AD9512 configuration..."
errors = 0
for Register in Config:
Address = Register[0]
Data = Register[1]
DataRead = self.Read(Address)
if Data <> DataRead:
ErrorMsg("Data at address 0x%02x are different! Data read = 0x%02x, should be 0x%02x" % (Address, DataRead, Data))
errors += 1
if errors == 0:
OkMsg("no error found")
else:
ErrorMsg("found %d errors!" % errors)
......@@ -51,7 +51,6 @@
##-----------------------------------------------------------------------------
import time
from CommonFunctions import *
from Ffpg import *
# triggerPhase = 53.76 # same for both channels in the test setup
......@@ -62,9 +61,9 @@ calibrationData = [ # -1 = uncalibrated
]
fmcSlot = 1 # 0 | 1
channel = 2 # 1 | 2
channel = 1 # 1 | 2
ad9512ConfigOriginal = (
ad9512Config = (
(0x34, 0x01),
(0x35, 0x00),
(0x36, 0x00),
......@@ -83,47 +82,6 @@ ad9512ConfigOriginal = (
(0x58, 0x20)
)
ad9512Config = (
(0x34, 0x01),
(0x35, 0x00),
(0x36, 0x00),
(0x3f, 0x03),
(0x45, 0x05),
(0x4a, 0x00),
(0x4c, 0x00),
(0x4e, 0x00),
(0x50, 0x00),
(0x52, 0x00),
(0x4b, 0x40),
(0x4d, 0x40),
(0x4f, 0x40),
(0x51, 0x40),
(0x53, 0x40),
(0x58, 0x20)
)
def Ad9512Config(pg, Config):
for Register in Config:
Address = Register[0]
Data = Register[1]
pg.ad9512.Write(Address, Data)
pg.ad9512.Commit()
def Ad9512Check(pg, Config):
print "Checking AD9512 configuration..."
errors = 0
for Register in Config:
Address = Register[0]
Data = Register[1]
DataRead = pg.ad9512.Read(Address)
if Data <> DataRead:
ErrorMsg("Data at address 0x%02x are different! Data read = 0x%02x, should be 0x%02x" % (Address, DataRead, Data))
errors += 1
if errors == 0:
OkMsg("no error found")
else:
ErrorMsg("found %d errors!" % errors)
def Init(pg):
global calibrationData
global ad9512Config
......@@ -132,7 +90,7 @@ def Init(pg):
pg.SelectClock("external", 400.789)
pg.SetRatio(2)
Ad9512Config(pg, ad9512Config)
pg.ad9512.Config(ad9512Config)
pg.SetOverflow(17820)
pg.Ad9512Sync()
......@@ -150,7 +108,7 @@ def Init(pg):
def TestSinglePulse(pg, channel):
pg.ResetBadState(channel)
pg.CreateSinglePulse(channel, start = 0, width = 50, polarity = 1)
pg.CreateSinglePulse(channel, start = 10*(channel-1), width = 10, polarity = 1)
pg.EnableChannel(channel)
pg.StartChannel(channel)
......@@ -181,12 +139,12 @@ pg = Ffpg(fmcSlot)
# pg.wb.SetDebugSv("wb_trace.svh")
# initialize the driver
# Init(pg)
Init(pg)
# create single pulse
# TestSinglePulse(pg, channel)
# TestSinglePulse(pg, 1)
# TestSinglePulse(pg, 2)
TestSinglePulse(pg, 1)
TestSinglePulse(pg, 2)
# create bunched pulses
# TestBunchPulses(pg, channel)
......@@ -202,6 +160,8 @@ pg.PrintControl()
pg.PrintStatus()
pg.PrintDebug()
# pg.ad9512.Check(ad9512Config)
# pg.ad9512.debug = True
# pg.wb.SetDebug(True)
......
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