Scope
InputsFPGA.cpp
1 #include "stdafx.h"
2 #include "InputsFPGA.h"
3 #include "fpga\FPGAPhotonCounter.h"
4 #include "fpga\FPGADigitalDemultiplexer.h"
5 #include "fpga\FPGAResonanceScanner_NI5771.h"
6 #include "fpga\FPGAAnalogIntegrator.h"
7 #include "fpga\FPGAResonanceScanner.h"
8 #include "fpga\FPGAAnalogDemultiplexer.h"
9 #include "fpga\FPGANoiseOutput.h"
10 #include "ScopeDefines.h"
11 #include "helpers\helpers.h"
12 #include "ScopeDatatypes.h"
13 #include "parameters\IO.h"
14 #include "parameters\Scope.h"
15 #include "helpers\DaqChunk.h"
16 #include "helpers\ScopeException.h"
17 
18 namespace scope {
19 
20 SCOPE_FPGA_T& theFPGA() {
21  static SCOPE_FPGA_T staticFPGA;
22  return staticFPGA;
23 }
24 
25 InputsFPGA::InputsFPGA(const uint32_t& _area, parameters::InputsFPGA* _inputparams, const parameters::Scope& _params)
26  : Inputs(_area)
27  , laserpulsesperpixel(1000.0) {
28  try {
29  double pt = 0.0;
30  theFPGA().Initialize(_inputparams);
31 
32  uint32_t samplesperchan = 0;
33  // two more lines/preframelines are required, because in resonance scanner mode some pixels are thrown away at the beginning until the first line is triggered with the sync signal
34  samplesperchan = _params.areas[area]->Currentframe().TotalPixels() + _inputparams->preframelines() * _params.areas[area]->Currentframe().XTotalPixels();
35  if ( _params.requested_mode() == DaqModeHelper::nframes) {
36  samplesperchan *= _params.areas[area]->daq.requested_frames() * _params.areas[ThisAreaOrMasterArea(area)]->daq.averages();
37  }
38 
39  DBOUT(L"Requested pixeltime area " << area << L": " << _params.areas[area]->daq.pixeltime());
40  pt = theFPGA().SetPixeltime(area, _params.areas[area]->daq.pixeltime());
41  DBOUT(L"Real pixeltime area " << area << L": " << pt);
42  laserpulsesperpixel = pt * 1E-6 * 80E6;
43  DBOUT(L"Laser pulses per pixel " << laserpulsesperpixel);
44 
45  _params.areas[area]->daq.pixeltime = pt;
46  DBOUT(L"Requested pixels " << samplesperchan);
47  theFPGA().SetRequestedPixels(area, samplesperchan);
48  requested_samples = samplesperchan;
49 
50  if ( _params.requested_mode() == DaqModeHelper::continuous )
51  theFPGA().SetContinuousAcquisition(true); // overrides requested pixels on FPGA VI
52  else
53  theFPGA().SetContinuousAcquisition(false);
54 
55  // If T-Series is triggered the FPGA waits for external trigger (and all other tasks waiting for it)
56  theFPGA().SetTriggering((_params.requested_mode() == DaqModeHelper::nframes) && _params.timeseries.triggered());
57 
58  // For diagnosis: Connect the FPGA generated sample clock to a DAQmx output terminal
59  // if ( _area == 1 ) {
60  // DAQmxDisconnectTerms("/PXI-6259_0/PXI_Trig1", "/PXI-6259_0/PFI0");
61  // }
62 
63  theFPGA().SetScannerdelay(_params.areas[area]->daq.ScannerDelaySamples(false));
64 
65  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
66 }
67 
68 
69 InputsFPGA::~InputsFPGA(void) {
70  Stop();
71 }
72 
73 void InputsFPGA::Start(void) {
74  try {
75  theFPGA().StartAcquisition();
76  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
77 }
78 
79 void InputsFPGA::Stop(void) {
80  try {
81  theFPGA().StopAcquisition();
82  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
83 }
84 
85 int32_t InputsFPGA::Read(DaqChunk &_chunk, bool& _timedout, const double& _timeout) {
86  int32_t read = 0;
87  try {
88  read = theFPGA().ReadPixels(_chunk, _timeout, _timedout);
89  if ( _timedout ) {
90  DBOUT(L"InputsFPGA::Read area " << area << L" timed out");
91  }
92  DBOUT(L"InputsFPGA::Read area " << area << L" read " << read);
93  theFPGA().CheckFPGADiagnosis();
94  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
95  return read;
96 }
97 
98 }
99 
ScopeNumber< uint32_t > preframelines
number of lines to acquire before each frame, e.g.
Definition: IO.h:40
Wraps hardware connection for signal input from PMTs.
Definition: Inputs.h:13
const uint32_t area
the area
Definition: Inputs.h:17
The master parameters class.
Definition: Scope.h:204
InputsFPGA(const InputsFPGA &i)
disable copy
std::array< std::unique_ptr< Area >, SCOPE_NAREAS > areas
holds AreaParameters for all areas.
Definition: Scope.h:231
uint32_t requested_samples
the total number of samples that should be read (in case of nframes mode) otherwise the buffer size (...
Definition: Inputs.h:20
Timeseries timeseries
the TimeseriesParameters
Definition: Scope.h:240
int32_t Read(DaqChunk &_chunk, bool &_timedout, const double &_timeout) override
Reads one chunk of samples for one area.
Definition: InputsFPGA.cpp:85
A DaqChunk contains data from all channels sequentially.
Definition: DaqChunk.h:9
This is the include file for standard system include files, or project specific include files that ar...
ScopeValue< DaqMode > requested_mode
requested acquisition mode (see DaqModeHelper)
Definition: Scope.h:279
ScopeNumber< bool > triggered
the current/first repeat is triggered on triggerchannel
Definition: Runstates.h:81
In here all declarations for all kinds of datatypes Scope needs.
#define DBOUT(s)
A debug output to the debug console.
Definition: helpers.h:153
void Start() override
Start task.
Definition: InputsFPGA.cpp:73
void ScopeExceptionHandler(const std::string &_origin, const bool &_log, const bool &_showmessagebox, const bool &_trace, const bool &_rethrow)
Handles all exceptions and does nice logging.
double laserpulsesperpixel
how many laser pulses arrive per pixel, photon counts are normalized to the number of laser pulses ...
Definition: InputsFPGA.h:32
Various helper functions and classes for Scope.
Parameters for pixel acquisition with NI-FPGA.
Definition: IO.h:117
void Stop() override
Stops task.
Definition: InputsFPGA.cpp:79