#!/usr/bin/env python # coding: utf8 ##----------------------------------------------------------------------------- ## Title : Driver example ## Project : FMC DEL 1ns 2cha (FFPG) ## URL : http://www.ohwr.org/projects/fmc-del-1ns-2cha ##----------------------------------------------------------------------------- ## File : FFPG_driver.py ## Author(s) : Jan Pospisil ## Company : CERN (BE-BI-QP) ## Created : 2016-08-09 ## Last update: 2016-08-24 ## Standard : Python ##----------------------------------------------------------------------------- ## Description: Example functions how to operate the FFPG gateware via its ## Wishbone interface. ##----------------------------------------------------------------------------- ## Copyright (c) 2016 CERN (BE-BI-QP) ##----------------------------------------------------------------------------- ## GNU LESSER GENERAL PUBLIC LICENSE ##----------------------------------------------------------------------------- ## This source file is free software; you can redistribute it and/or modify it ## under the terms of the GNU Lesser General Public License as published by the ## Free Software Foundation; either version 2.1 of the License, or (at your ## option) any later version. This source is distributed in the hope that it ## will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty ## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ## See the GNU Lesser General Public License for more details. You should have ## received a copy of the GNU Lesser General Public License along with this ## source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html ##----------------------------------------------------------------------------- ## Revisions : ## Date Version Author Comment ## 2016-08-24 1.0 Jan Pospisil ## 2016-09-01 1.1 Jan Pospisil added version numbers (major.minor.rev) ## added clock_stable status bit ## added option for negative pulses ## 2016-09-02 1.2 Michael Betz added reset of MC100EP140 bad state; ## better configuration; better debugging; ## comments; attempt for better trigger ## latency calibration (not working yet) ## 2016-09-05 1.3 Jan Pospisil Independent Trigger Latency for the two ## channels (issue 1389) ## added version check ## 2016-09-06 1.4 Jan Pospisil fixed OneWire code ## convert to OOP ## divided into more files ## simplified interface ## 2016-09-21 1.5 Jan Pospisil added calibration example code ##----------------------------------------------------------------------------- import time from Ffpg import * # triggerPhase = 53.76 # same for both channels in the test setup calibrationData = [ # -1 = uncalibrated # channel 1, channel 2 [51.29, 51.03], # FMC slot 0 [51.29, 51.11] # FMC slot 1 ] fmcSlot = 1 # 0 | 1 channel = 1 # 1 | 2 ad9512Config = ( (0x34, 0x01), (0x35, 0x00), (0x36, 0x00), (0x3f, 0x03), (0x45, 0x05), (0x4a, 0x00), (0x4c, 0x00), (0x4e, 0x00), (0x50, 0x00), (0x52, 0x00), (0x4b, 0x00), (0x4d, 0x00), (0x4f, 0x00), (0x51, 0x00), (0x53, 0x00), (0x58, 0x20) ) def Init(pg): global calibrationData pg.Reset() pg.SelectClock("external", 400.789) pg.SetRatio(2) pg.SetOverflow(17820) pg.Ad9512Sync() pg.SetTriggerThreshold(0.5) pg.SetVcxoFrequency(-0.2105) # 125.0000 MHz # calibration fmcSlot = pg.GetFmcSlot() for channel in [1,2]: triggerPhase = calibrationData[fmcSlot][channel-1] print("Calibrating channel "+str(channel)+" on FMC slot "+str(fmcSlot)+" to "+str(triggerPhase)+" ns") if triggerPhase > -1: pg.SetTriggerPhase(channel, triggerPhase) else: print(" (Skipping this calibration, no calibration data (-1) provided.)") def TestSinglePulse(pg, channel): pg.ResetBadState(channel) pg.CreateSinglePulse(channel, start = 0, width = 10, polarity = 1) pg.EnableChannel(channel) pg.StartChannel(channel) def TestBunchPulses(pg, channel): pg.ResetBadState(channel) pg.CreateBunchPulses(channel, pulseDelay = 10, pulseWidth = 10, bunches = (0,1,10,15), polarity = 1) pg.EnableChannel(channel) pg.StartChannel(channel) def StopAndDisable(pg, channel): pg.StopChannel(channel) pg.DisableChannel(channel) def PrintFrequency(pg): frequency = pg.GetFrequency() if frequency is not None: print("RF clock frequency: "+str(frequency/1.0e6) + " MHz") else: print("RF clock frequency: (unstable)") # create FFPG driver for FMC slot pg = Ffpg(fmcSlot) # activate low-level debug output # pg.wb.SetDebug(True) # activate SystemVerilog trace debug # pg.wb.SetDebugSv("wb_trace.svh") # initialize the driver Init(pg) # create single pulse TestSinglePulse(pg, channel) # create bunched pulses # TestBunchPulses(pg, channel) # stop and disable channel # StopAndDisable(pg, channel) # print some info pg.PrintVersion() # print("Actual temperature: "+str(pg.temp.ReadTemperature()) + " °C") PrintFrequency(pg) pg.PrintControl() pg.PrintStatus() pg.PrintDebug() ''' pg.Ad9512ActivateWbAccess() pg.ad9512.debug = True pg.ad9512.Config(ad9512Config) pg.ad9512.Check(ad9512Config) pg.Ad9512DisableWbAccess() '''