2 #include "FPGADigitalDemultiplexer.h"
3 #include "parameters/IO.h"
4 #include "helpers/DaqChunk.h"
9 :
FPGAIO6587(NiFpga_DigitalDemultiplexerV3_IndicatorBool_Onboard_Clock_Ready
10 , NiFpga_DigitalDemultiplexerV3_ControlU16_Onboard_Clock_Write_Data
11 , NiFpga_DigitalDemultiplexerV3_ControlBool_Onboard_Clock_Write
12 , NiFpga_DigitalDemultiplexerV3_IndicatorBool_Xpoint_Switch_Ready
13 , NiFpga_DigitalDemultiplexerV3_ControlU8_ClockSource
14 , NiFpga_DigitalDemultiplexerV3_ControlBool_Xpoint_Switch_Write
15 , NiFpga_DigitalDemultiplexerV3_ControlBool_Commit
16 , NiFpga_DigitalDemultiplexerV3_ControlBool_Acq_Reset)
18 assert(SCOPE_NAREAS <= 2);
19 status = NiFpga_Initialize();
21 char*
const Bitfile =
"devices\\fpga\\" NiFpga_DigitalDemultiplexerV3_Bitfile;
24 status = NiFpga_Open(Bitfile, NiFpga_DigitalDemultiplexerV3_Signature,
"RIO0", 0, &
session);
25 DBOUT(L
"FPGADemultiplexer: FPGA Session opened\n");
33 std::this_thread::sleep_for(std::chrono::milliseconds(500));
39 fifos[0] = NiFpga_DigitalDemultiplexerV3_TargetToHostFifoU16_ToHostArea1Ch1FIFO;
40 fifos[1] = NiFpga_DigitalDemultiplexerV3_TargetToHostFifoU16_ToHostArea1Ch2FIFO;
41 fifos[2] = NiFpga_DigitalDemultiplexerV3_TargetToHostFifoU16_ToHostArea2Ch1FIFO;
42 fifos[3] = NiFpga_DigitalDemultiplexerV3_TargetToHostFifoU16_ToHostArea2Ch2FIFO;
43 reqpixels[0] = NiFpga_DigitalDemultiplexerV3_ControlU32_RequestedpixelsA1;
44 reqpixels[1] = NiFpga_DigitalDemultiplexerV3_ControlU32_RequestedpixelsA2;
45 smplsperpixel[0] = NiFpga_DigitalDemultiplexerV3_ControlU16_SamplesperpixelA1;
46 smplsperpixel[1] = NiFpga_DigitalDemultiplexerV3_ControlU16_SamplesperpixelA2;
47 smplsperpixelacq[0] = NiFpga_DigitalDemultiplexerV3_ControlU16_SamplesperpixelAcqA1;
48 smplsperpixelacq[1] = NiFpga_DigitalDemultiplexerV3_ControlU16_SamplesperpixelAcqA2;
53 status = NiFpga_Finalize();
54 DBOUT(L
"FPGADemultiplexer::~FPGADemultiplexer session closed");
69 std::this_thread::sleep_for(std::chrono::milliseconds(500));
83 uint16_t clockcycles = round2ui16(_pixeltime * 1E-6 *
samplingrate);
84 DBOUT(L
"FPGADemultiplexer::SetPixeltime Clockcycles per pixel" << clockcycles);
86 if ( clockcycles%60 != 0 ) {
87 clockcycles -= (clockcycles%60);
88 DBOUT(L
"FPGADemultiplexer::SetPixeltime Coerced clockcycles per pixel" << clockcycles);
102 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Waitfortrigger, _waitfortrigger);
106 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Acquirecontinuously, _cont);
114 NiFpga_Bool alreadyrunning =
false;
115 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Acquire, &alreadyrunning);
116 if ( !alreadyrunning ) {
118 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Acquire,
true);
123 DBOUT(L
"FPGADigitalDemultiplexer::StopAcquisition");
124 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Acquire,
false);
128 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Acq_Reset,
false);
129 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Acq_Reset,
true);
130 std::this_thread::sleep_for(std::chrono::milliseconds(200));
131 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Acq_Reset,
false);
135 size_t remaining = 0;
138 assert( (_chunk.NChannels() == 2) && (_chunk.Area() <= 1) );
141 assert(_chunk.
data.size() >= _chunk.PerChannel() * _chunk.NChannels());
143 NiFpga_Status stat = NiFpga_Status_Success;
145 for ( uint32_t c = 0 ; c < _chunk.NChannels() ; c++ ) {
146 stat = NiFpga_ReadFifoU16(
session
147 ,
fifos[_chunk.Area() * 2+c]
148 , &_chunk.
data[c*_chunk.PerChannel()]
149 , _chunk.PerChannel()
150 ,
static_cast<uint32_t
>(_timeout * 1000)
152 _timedout = (stat == NiFpga_Status_FifoTimeout);
161 return _chunk.PerChannel();
168 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_IndicatorBool_ToHostFIFOOverflowA1Ch1, &b);
170 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_IndicatorBool_ToHostFIFOOverflowA1Ch2, &b);
172 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_IndicatorBool_ToHostFIFOOverflowA2Ch1, &b);
174 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_IndicatorBool_ToHostFIFOOverflowA2Ch2, &b);
176 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_IndicatorBool_InterloopFIFOoverflow, &b);
178 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_IndicatorBool_InterloopFIFOtimeout, &b);
180 status = NiFpga_ReadU16(
session, NiFpga_DigitalDemultiplexerV3_IndicatorU16_LaserpulsesperpixelA1, &ui);
181 DBOUT(L
"Laserpulsecount " << ui);
183 status = NiFpga_ReadBool(
session, NiFpga_DigitalDemultiplexerV3_IndicatorBool_Acquiring, &b);
188 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_ClearInterloopFIFO, 1);
189 std::this_thread::sleep_for(std::chrono::milliseconds(50));
190 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_ClearInterloopFIFO, 0);
193 for (
auto f :
fifos )
195 std::this_thread::sleep_for(std::chrono::milliseconds(50));
198 for (
auto f : fifos )
200 std::this_thread::sleep_for(std::chrono::milliseconds(50));
204 status = NiFpga_WriteBool(
session, NiFpga_DigitalDemultiplexerV3_ControlBool_Countmode, _mode);
void StartAcquisition() override
Starts the acquisition on the FPGA.
void WriteOnboardClockFrequency(NiFpga_Session _session, const double &_clock_freq)
Writes the program for the Si570 clock chip to the device.
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...
parameters::InputsFPGADigitalDemultiplexer * parameters
the parameter set
std::array< double, 2 > pixeltimes
Pixel dwell time in microseconds.
FPGADigitalDemultiplexer()
Load the FPGA bitfile, set the IO module's onboard clock, initialize the acquisition.
std::array< NiFpga_DigitalDemultiplexerV3_ControlU32, 2 > reqpixels
requested pixels for both areas
Handels the NI FlexRIO adapter module IO-6587.
std::array< NiFpga_DigitalDemultiplexerV3_ControlU16, 2 > smplsperpixel
samples per pixel for both areas
double SetPixeltime(const uint32_t &_area, const double &_pixeltime) override
Sets the time per pixel/dwell time (in seconds)
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.
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) ...
void ResetAcquisition()
Resets the acquisition.
void CheckFPGADiagnosis()
Checks the status of the FIFOs on the FPGA.
~FPGADigitalDemultiplexer()
Close FPGA session.
void Initialize(parameters::InputsFPGA *_parameters) override
Set initial parameters.
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...
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 SetContinuousAcquisition(const bool &_cont) override
Sets if the FPGA should acquire data continuously or acquire the number of pixels per channel set wit...
FPGAStatusSafe status
current FPGA status.
std::array< NiFpga_DigitalDemultiplexerV3_TargetToHostFifoU16, 4 > fifos
all FIFOs for both areas both channels
void SetCountMode(const bool &_mode)
Set the counting mode on the FPGA.
#define DBOUT(s)
A debug output to the debug console.
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.
void SetClockSource(NiFpga_Session _session, const uint8_t &_clock_source=3)
Possible clock sources (see SetClockSource.vi from NI examples) .
virtual void Initialize(parameters::InputsFPGA *_parameters)
Set initial parameters.
std::array< NiFpga_DigitalDemultiplexerV3_ControlU16, 2 > smplsperpixelacq
samples per pixel for both areas, for the acquisition loop
void ClearFIFOs()
Clears the interloop and ToHost FIFOs.
NiFpga_Session session
NI FPGA session handle.
void SetTriggering(const bool &_waitfortrigger) override
Sets if the FPGA should wait for a trigger before starting acquisition.
double samplingrate
programmed sampling rate (usually 1-1.4GHz), this is double the IO modules clock rate ...