5.3 ndigo6g12_adc_single.cpp
¶
1#include "ndigo6g12_app.h"
2#include <stdio.h>
3
4// a simple application that measures the distance of two packets and computes
5// the frequency of the signal
6 double Ndigo6GAppSingle::ProcessADCPacket(crono_packet *pkt) {
7
8 double fallingEdgeTs = ComputeFallingEdge(pkt);
9
10 if (fallingEdgeTs > 0) {
11 if (lastFallingEdgeTs > 0) {
12 double packetRate = (1.0 / (fallingEdgeTs - lastFallingEdgeTs));
13 double packetRateKHz = packetRate * 1e9;
14 printf("ADC packet rate: %.3f kHz\n", packetRateKHz);
15 }
16 lastFallingEdgeTs = fallingEdgeTs;
17 }
18 return fallingEdgeTs;
19}
20
21void Ndigo6GAppSingle::ConfigureADC(ndigo6g12_configuration *config,
22 int adcThreshold) {
23 this->adcThreshold = adcThreshold;
24 // single channel mode with 6.4 Gsps
25 config->adc_mode = NDIGO6G12_ADC_MODE_A;
26
27 // ADC sample value range -32768 .. 32767
28 config->output_mode = NDIGO6G12_OUTPUT_MODE_SIGNED16;
29
30 // enable ADC channel A and trigger on the falling edge of ADC data
31 // shift baseline of analog inputs to +350 mV
32 config->analog_offsets[0] = NDIGO6G12_DC_OFFSET_N_NIM * -1;
33
34 // trigger on falling edge of ADC data
35 config->trigger[NDIGO6G12_TRIGGER_A0].edge = true;
36 config->trigger[NDIGO6G12_TRIGGER_A0].rising = false;
37 config->trigger[NDIGO6G12_TRIGGER_A0].threshold = adcThreshold;
38
39 // enable channel A
40 config->trigger_block[0].enabled = true;
41 // multiples of 32 ADC samples (5 ns recording time)
42 config->trigger_block[0].length = 1;
43 // multiples of 32 ADC samples, gets added to packet length
44
45 config->trigger_block[0].precursor = PRECURSOR;
46
47 // select ADC data as trigger source of the channel
48 config->trigger_block[0].sources = NDIGO6G12_TRIGGER_SOURCE_A0;
49
50}