#------------------------------------------------------------------------ # ThisCommandFile = 'DAQ96_Initialize_&_FindDAC.cmd' # # Called by the GUI button "Initialize DAQ96" # to Intialize all ADF-2 Cards, and run Find_DAC # # Created 19-Jan-2007 # # Updated 26-Feb-2007 : calculate and dd to pop-up the average noise # by groups of 16 channels # #------------------------------------------------------------------------ from tkMessageBox import showinfo from Site_Dependent import Boot_Auxi from Site_Dependent import AdfCardTot from Site_Dependent import AdfChannelTot from Site_Dependent import AdfSlotVsCardNum from Site_Dependent import AdfSlotMaestro from Site_Dependent import SamplesPerChannel from Site_Dependent import Zeresp #------------------------------------------------------------------------ # Register Address and data for controlling the NIM Trigger (i.e. Crate_0_Signal_0) RegAddr_MaestroToSCLD = 1 # Control Data to tell the SCLD to enable/disable the NIM Trigger Data_Enable_NIM_Trigger = 0xff50 Data_Disable_NIM_Trigger = 0xff40 # Base address of the Per Channel Input COntrol Regsiter RegAddr_InputControl_Base = 0x0302 # Register Address for Raw ADC Address Generator Control Register RegAddr_RawAdcAddrGen_Ctrl = 512 # Register Address for Raw ADC Address Generator Rollover Address RegAddr_RawAdcAddrGen_Roll = 513 # The threshold at which a noisy channel will be flagged in the pop-up summary StdDev_OkMax = 1.5 #------------------------------------------------------------------------ #------------------------------------------------------------------------ # Execute Boot_Auxi command file # (which needs to specify that Find_DAC can use random samples) Tcs_Exec_McfFile ( Boot_Auxi ) # Initialize all ADF-2 cards i.e. call the standard intialization for AdfNum in range(AdfCardTot) : Comment = "DAQ96 ADF #%d" % AdfNum Adf_InitCard ( SlotNum = AdfSlotVsCardNum[AdfNum], Comment = Comment ) #------------------------------------------------------------------------ # Setup the Input Control Registers for all channels # of all ADF-2 cards in the DAQ 96 System so that: # # Stop Comparator is set to ADC full scale counts = 1023 # i.e. set Bits 7:0 = $FF # # Set zero ADC data delay, i.e. set bits 11:8 all Low # # Select ADC data to go to the Filter, i.e. set bit #12 Low # # Channel's Raw ADC Mem Block Write Enable to follow the # Address Generator Global Write Enable, i.e. set Bit #14 Low InputControl_Data = 0x00ff for AdfNum in range(AdfCardTot) : for FpgaNum in range (2) : # two FPGAs per ADF for D0_FpgaChannelNum in range (8) : # 8 channel pairs per FPGA for D0_TtType in range (2) : # two TT types: EM=0, HD=1 InputControl_RegAddr = RegAddr_InputControl_Base \ + D0_FpgaChannelNum * 0x2000 \ + D0_TtType Rio_Write ( SlotNum = AdfSlotVsCardNum[AdfNum], ChipNum = FpgaNum, RegAddr = InputControl_RegAddr, DataOut = InputControl_Data ) #------------------------------------------------------------------------ # Disable the External NIM Trigger on the SCLD card. # The External NIM Trigger is DISABLED by telling the Maestro ADF-2 # card, i.e. ADF-2 Card Number #0, to send a NOT asserted # ADF_Crate_to_SCLD_Signal_0 signal to the SCLD card. Do this # by writing to the Board Control PAL Register Address 1. Rio_Write ( SlotNum = AdfSlotMaestro, ChipNum = 0, # i.e. Board Control PAL RegAddr = RegAddr_MaestroToSCLD, DataOut = Data_Disable_NIM_Trigger ) # Set up the channel control and the Address Generators # on **ALL** ADF-2 card so that Raw ADC data is being written # into the Raw ADC Monitor Data Block circular buffers. # Control Data for the Raw ADC address generator control register to : # - enable multi turn running # - enable the Global Write Enable signal to be asserted # - enable the Save Monitor Data signal to stop the Address Generators Data_ModeCaptureMonitorData = 0x000e for AdfNum in range(AdfCardTot) : for FpgaNum in range(2) : # set end address Rio_Write ( SlotNum = AdfSlotVsCardNum[AdfNum], ChipNum = FpgaNum, RegAddr = RegAddr_RawAdcAddrGen_Roll, DataOut = SamplesPerChannel - 2 ) # set mode for capturing data on NIM signal Rio_Write ( SlotNum = AdfSlotVsCardNum[AdfNum], ChipNum = FpgaNum, RegAddr = RegAddr_RawAdcAddrGen_Ctrl, DataOut = Data_ModeCaptureMonitorData ) #------------------------------------------------------------------------ # All ADF-2 card channels will have their pedestal set to 400 ADC counts # cf. Zeresp variable in site_dependent module. for AdfNum in range(AdfCardTot) : Summary = "" NoiseSumBy16 = 0.0 for D96_RelChannelNum in range(AdfChannelTot) : D96_SysChanNum = AdfChannelTot*AdfNum + D96_RelChannelNum D0_TtType = D96_RelChannelNum % 2 D0_ChanNum = ( 4 * ( D96_RelChannelNum/2 ) + D96_RelChannelNum/8 ) % 16 D0_RelEta = D0_ChanNum / 4 D0_RelPhi = D0_ChanNum % 4 Comment = "DAQ96 ADF #%d Chan #%d" % ( AdfNum, D96_SysChanNum ) DacValue, Average, StdDev, HistoFileName, Status = \ Find_Dac( SlotNum = AdfSlotVsCardNum[AdfNum], TtType = D0_TtType, RelEta = D0_RelEta, RelPhi = D0_RelPhi, AdcValue = Zeresp, Comment = Comment ) # convert strings to values try : DacValue = int( DacValue ) except : DacValue = 0 try : StdDev = float ( StdDev ) except : StdDev = 0.0 # keep a running sum to calculate average NoiseSumBy16 = NoiseSumBy16 + StdDev # Build up the multi-line summary string Summary = Summary \ + "\n Ch#%#02d Find_DAC = %3d StdDev = %2.2f " % ( D96_SysChanNum, DacValue, StdDev ) if ( Status != eOk ) : Summary = Summary \ + " **Error** " if ( StdDev >= StdDev_OkMax ) : Summary = Summary + ( " ** noise >= %2.2f " % StdDev_OkMax ) # Display the average of each group of 16 channels if ( D96_RelChannelNum % 16 == 15 ) : # use 15 to display AFTER each group of 16 channels Summary = Summary \ + ( "\n Ave Noise of Ch#%#02d-%#02d = %2.2f\n" % ( D96_SysChanNum - 15, D96_SysChanNum, NoiseSumBy16 / 16. ) ) # reset running sum for next group of 16 channels NoiseSumBy16 = 0.0 # Record Summary in logfile printLine ( "ADF #%d" % AdfNum, Summary ) # Pop up the summary dialog for this ADF showinfo ( "ADF #%d" % AdfNum , Summary )