5.4 ndigo6g12_adc_dual.cpp

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