2 #include "FPGAPhotonCounter.h"
3 #include "parameters/IO.h"
4 #include "helpers/DaqChunk.h"
9 :
FPGAIO6587(NiFpga_PhotonCounterV2_IndicatorBool_Onboard_Clock_Ready, NiFpga_PhotonCounterV2_ControlU16_Onboard_Clock_Write_Data
10 , NiFpga_PhotonCounterV2_ControlBool_Onboard_Clock_Write , NiFpga_PhotonCounterV2_IndicatorBool_Xpoint_Switch_Ready
11 , NiFpga_PhotonCounterV2_ControlU8_ClockSource, NiFpga_PhotonCounterV2_ControlBool_Xpoint_Switch_Write, NiFpga_PhotonCounterV2_ControlBool_Commit
12 , NiFpga_PhotonCounterV2_ControlBool_Acq_Reset) {
13 status = NiFpga_Initialize();
14 char*
const Bitfile =
"devices\\fpga\\" NiFpga_PhotonCounterV2_Bitfile;
17 status = NiFpga_Open(Bitfile, NiFpga_PhotonCounterV2_Signature,
"RIO0", NiFpga_OpenAttribute_NoRun, &
session);
18 DBOUT(L
"FPGAPhotonCounter: FPGA Session opened");
26 std::this_thread::sleep_for(std::chrono::milliseconds(500));
33 fifos[0] = NiFpga_PhotonCounterV2_TargetToHostFifoU16_ToHostCh1FIFO;
34 fifos[1] = NiFpga_PhotonCounterV2_TargetToHostFifoU16_ToHostCh2FIFO;
39 status = NiFpga_Finalize();
40 DBOUT(L
"FPGAPhotonCounter::~FPGAPhotonCounter session closed");
54 std::this_thread::sleep_for(std::chrono::milliseconds(500));
67 uint16_t samplesperpixel = round2ui16(_pixeltime * 1E-6 *
samplingrate);
68 status = NiFpga_WriteU16(
session, NiFpga_PhotonCounterV2_ControlU16_Samplesperpixel, samplesperpixel);
69 status = NiFpga_WriteU16(
session, NiFpga_PhotonCounterV2_ControlU16_SamplesperpixelAcq, samplesperpixel);
70 return static_cast<double>(samplesperpixel)*1E6/
samplingrate;
75 uint16_t samplesperline = round2ui32(_linetime * 1E-6 *
samplingrate);
76 status = NiFpga_WriteU16(
session, NiFpga_PhotonCounterV2_ControlU32_Samplesperline, samplesperline);
77 return static_cast<double>(samplesperline*1E6/
samplingrate);
81 status = NiFpga_WriteBool(
session, NiFpga_PhotonCounterV2_ControlBool_Waitfortrigger, _waitfortrigger);
85 status = NiFpga_WriteBool(
session, NiFpga_PhotonCounterV2_ControlBool_Acquirecontinuously, _cont);
89 status = NiFpga_WriteU32(
session, NiFpga_PhotonCounterV2_ControlU32_Requestedpixels, _reqpixels);
94 throw ScopeException(
"Initialize FPGAPhotonCounter before StartAcquisition!");
96 status = NiFpga_WriteBool(
session, NiFpga_PhotonCounterV2_ControlBool_Acquire,
true);
100 size_t remaining = 0;
102 assert(_chunk.NChannels() <= 2 );
104 NiFpga_Status stat = NiFpga_Status_Success;
106 for ( uint32_t c = 0 ; c < _chunk.NChannels() ; c++ ) {
107 stat = NiFpga_ReadFifoU16(
session
109 , &_chunk.
data[c * _chunk.PerChannel()]
110 , _chunk.PerChannel()
111 ,
static_cast<uint32_t
>(_timeout * 1000)
114 _timedout = (stat == NiFpga_Status_FifoTimeout);
121 return _chunk.PerChannel();
127 status = NiFpga_WriteBool(
session, NiFpga_PhotonCounterV2_ControlBool_Acquire,
false);
132 status = NiFpga_ReadBool(
session, NiFpga_PhotonCounterV2_IndicatorBool_ToHostFIFOOverflowCh1, &b);
134 status = NiFpga_ReadBool(
session, NiFpga_PhotonCounterV2_IndicatorBool_ToHostFIFOOverflowCh2, &b);
136 status = NiFpga_ReadBool(
session, NiFpga_PhotonCounterV2_IndicatorBool_InterloopFIFOoverflow, &b);
138 status = NiFpga_ReadBool(
session, NiFpga_PhotonCounterV2_IndicatorBool_InterloopFIFOtimeout, &b);
140 status = NiFpga_ReadBool(
session, NiFpga_PhotonCounterV2_IndicatorBool_Acquiring, &b);
145 status = NiFpga_WriteBool(
session, NiFpga_PhotonCounterV2_ControlBool_ClearInterloopFIFOs, 1);
146 std::this_thread::sleep_for(std::chrono::milliseconds(50));
147 status = NiFpga_WriteBool(
session, NiFpga_PhotonCounterV2_ControlBool_ClearInterloopFIFOs, 0);
149 for (
auto f :
fifos )
151 std::this_thread::sleep_for(std::chrono::milliseconds(50));
153 for (
auto f : fifos )
155 std::this_thread::sleep_for(std::chrono::milliseconds(50));
159 status = NiFpga_WriteBool(
session, NiFpga_PhotonCounterV2_ControlBool_Countingmode, _mode);
void SetCountMode(const bool &_mode)
Set the counting mode on the FPGA.
void WriteOnboardClockFrequency(NiFpga_Session _session, const double &_clock_freq)
Writes the program for the Si570 clock chip to the device.
Simple exception class for Scope.
void SetTriggering(const bool &_waitfortrigger) override
Sets if the FPGA should wait for a trigger before starting acquisition.
~FPGAPhotonCounter()
Close FPGA session.
Handels the NI FlexRIO adapter module IO-6587.
bool CheckIOModule(NiFpga_Session _session)
Necessary calls at the moment not supported by NI FPGA API 12.0, see CheckIOModule.vi for what to do.
std::vector< uint16_t > data
The data vector.
void InitializeAcquisition(NiFpga_Session _session)
Commits the clock frequency and clock source writings and resets the IO module acquisition circuit...
double SetLinetime(const uint32_t &_area, const double &_linetime) override
Sets the time per line (in seconds) for the generation of the line clock (if implemented) ...
A DaqChunk contains data from all channels sequentially.
This is the include file for standard system include files, or project specific include files that ar...
bool initialized
true if already initialized
void Initialize(parameters::InputsFPGA *_parameters) override
Set initial parameters.
double SetPixeltime(const uint32_t &_area, const double &_pixeltime) override
Sets the time per pixel/dwell time (in seconds)
FPGAPhotonCounter()
Load the FPGA bitfile, reset, set the IO module's onboard clock, initialize the acquisition.
FPGAStatusSafe status
current FPGA status.
#define DBOUT(s)
A debug output to the debug console.
void ClearFIFOs()
Clears the interloop and ToHost FIFOs.
void SetContinuousAcquisition(const bool &_cont) override
Sets if the FPGA should acquire data continuously or acquire the number of pixels per channel set wit...
parameters::InputsFPGAPhotonCounter * parameters
the parameter set
std::array< NiFpga_PhotonCounterV2_TargetToHostFifoU16, 2 > fifos
both fifos for both channels
void SetClockSource(NiFpga_Session _session, const uint8_t &_clock_source=3)
Possible clock sources (see SetClockSource.vi from NI examples) .
double samplingrate
programmed sampling rate (usually 1-1.4GHz), this is double the IO modules clock rate ...
void StopAcquisition() override
Stops the acquisition on the FPGA.
int32_t ReadPixels(DaqChunk &_chunk, const double &_timeout, bool &_timedout) override
Read only pixels from the FPGA FIFO.
virtual void Initialize(parameters::InputsFPGA *_parameters)
Set initial parameters.
void StartAcquisition() override
Starts the acquisition on the FPGA.
NiFpga_Session session
NI FPGA session handle.
void SetRequestedPixels(const uint32_t &_area, const uint32_t &_reqpixels) override
Sets the number of pixels per channel the FPGA should acquire, set to -1 for live scanning...
void CheckFPGADiagnosis()
Checks the status of the FIFOs on the FPGA.