5.5 ndigo6g12_adc_quad.cpp
¶
1#include "ndigo6g12_app.h"
2#include <stdio.h>
3#include <cmath>
4#include <array>
5
6
7// an application that measures the delay between a start signal (A)
8// stop signals on channels B-D
9double Ndigo6GAppQuad::ProcessADCPacket(crono_packet *pkt) {
10
11 double falling_edge_ts = ComputeFallingEdge(pkt);
12
13 // gather data
14 if (falling_edge_ts > 0) {
15 delayMeasure.InsertTimestamp(pkt->channel, falling_edge_ts);
16 }
17
18 Delays *delays = delayMeasure.MeasureDelays();
19
20 delayMeasure.PrintDelays(delays);
21
22 return falling_edge_ts;
23}
24
25void Ndigo6GAppQuad::ProcessTDCTimestamp(int tdcChannel, double timestamp) {
26 // insert TDC as channel 4-7
27 delayMeasure.InsertTimestamp(4 + tdcChannel, timestamp);
28
29 Delays *delays = delayMeasure.MeasureDelays();
30
31 delayMeasure.PrintDelays(delays);
32}
33
34void Ndigo6GAppQuad::ConfigureADC(ndigo6g12_configuration *config,
35 int adcThreshold) {
36 this->adcThreshold = adcThreshold;
37 // quad channel mode with 1.6 Gsps
38 config->adc_mode = NDIGO6G12_ADC_MODE_ABCD;
39
40 // ADC sample value range -32768 .. 32767
41 config->output_mode = NDIGO6G12_OUTPUT_MODE_SIGNED16;
42 // trigger on falling edge of ADC data
43 for (int index : {NDIGO6G12_TRIGGER_A0, NDIGO6G12_TRIGGER_B0,
44 NDIGO6G12_TRIGGER_C0, NDIGO6G12_TRIGGER_D0}) {
45 config->trigger[index].edge = true;
46 config->trigger[index].rising = false;
47 config->trigger[index].threshold = adcThreshold;
48 }
49
50 // the sources of each channel (they should trigger on the input data
51 // of the channel)
52 std::array<int, 4> sources = {
53 NDIGO6G12_TRIGGER_SOURCE_A0, NDIGO6G12_TRIGGER_SOURCE_B0,
54 NDIGO6G12_TRIGGER_SOURCE_C0, NDIGO6G12_TRIGGER_SOURCE_D0};
55
56 // enable ADC channels A-D and trigger on the falling edge of ADC data
57 // shift baseline of analog inputs to +350 mV
58 for (int c = 0; c < 4; c++) {
59 config->analog_offsets[c] = NDIGO6G12_DC_OFFSET_N_NIM * -1;
60
61 // enable channel
62 config->trigger_block[c].enabled = true;
63
64 // in multiples of 8 ADC samples (5 ns recording time) after trigger
65 config->trigger_block[c].length = 1;
66
67 // in multiples of 8 ADC samples, gets added to packet length
68 config->trigger_block[c].precursor = PRECURSOR;
69
70 // select ADC data as trigger source of the channel
71 config->trigger_block[c].sources = sources[c];
72 }
73}