
166
(c) Spectrum Instrumentation GmbH
Combination of Memory Segmentation Options with Timestamps
Timestamps
Gated Sampling and Timestamps
Gated Sampling and the timestamp mode fit very good together. If timestamp
recording is activated each gate will get timestamped as shown in the draw
-
ing on the right. Both, beginning and end of the gate interval, are times
-
tamped. Each gate segment will therefore produce two timestamps
(Timestamp1 and Timestamp2) showing start of the gate interval and end of
the gate interval. By taking both timestamps into account one can read out the
time position of each gate as well as the length in samples. There is no other
way to examine the length of each gate segment than reading out the times
-
tamps.
Please keep in mind that the gate signals are timestamped, not the beginning
and end of the acquisition. The first sample that is available is at the time po
-
sition of [Timestamp1 - Pretrigger]. The length of the gate segment is [Timestamp2 - Time Ali Pret Posttrigger]. The
last sample of the gate segment is at the position [Time Ali Posttrigger]. When using the standard gate mode the end of
recording is defined by the expiring memsize counter. In standard gate mode there will be an additional timestamp for the last gate segment,
when the maximum memsize is reached!
The programming details of the timestamp mode are explained in an extra chapter.
The following example shows the setup of the Gated Sampling mode together with activated timestamps recording and a short display of the
the acquired timestamps. The example doesn’t care for the acquired data itself and doesn’t check for error:
// setup of the Gated Sampling mode
spcm_dwSetParam_i32 (hDrv, SPC_CARDMODE, SPC_REC_STD_GATE); // Enables Standard Gated Sampling
spcm_dwSetParam_i64 (hDrv, SPC_PRETRIGGER, 32); // 32 samples to acquire before gate start
spcm_dwSetParam_i64 (hDrv, SPC_POSTTRIGGER, 32); // 32 samples to acquire before gate end
spcm_dwSetParam_i64 (hDrv, SPC_MEMSIZE, 4096); // 4 kSamples in total acquired
// setup the Timestamp mode and make a reset of the timestamp counter
spcm_dwSetParam_i32 (hDrv, SPC_TIMESTAMP_CMD, SPC_TSMODE_STANDARD | SPC_TSCNT_INTERNAL);
spcm_dwSetParam_i32 (hDrv, SPC_TIMESTAMP_CMD, SPC_TS_RESET);
// now we define a buffer for timestamp data and start acquistion, each timestamp is 128 bit = 16 bytes
// as we don’t know the number of gate intervals we define the buffer quite large
int64* pllStamps = (int64*) pvAllocMemPageAligned (16 * 1000);
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_TIMESTAMP, SPCM_DIR_CARDTOPC, 0, (void*) pllStamps, 0, 1000 * 16);
spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_CARD_START | M2CMD_CARD_ENABLETRIGGER | M2CMD_EXTRA_STARTDMA);
// we wait for the end of timestamps transfer and read out the number of timestamps that have been acquired
int32 lAvailTimestampBytes;
spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_EXTRA_WAITDMA);
spcm_dwSetParam_i32 (hDrv, SPC_TS_AVAIL_USER_LEN, &lAvailTimestampBytes);
// as we now have the timestamps we just print them and calculate the time in milli seconds
// for simplicity only the lower 64 bit part of the 128 bit stamp is used, hence only every
// second array element of pllStamps is used here.
int64 llSamplerate, llLen, llAlign;
double dTime_ms;
spcm_dwGetParam_i64 (hDrv, SPC_SAMPLERATE, &llSamplerate);
spcm_dwGetParam_i64 (hDrv, SPC_GATE_LEN_ALIGNMENT, &llAlign);
// each even 128 bit timestamp is the start position of a gate segment each odd stamp is the end position
for (int i = 0; (i < (lAvailTimestampBytes / 16)) && (i < 1000); i++)
{
dTime_ms = 1000.0 * pllStamps[4 * i] / llSamplerate;
llLen = pllStamps[4 * i + 2] - pllStamps[4 * i] + 32 + 32; // (stop - start) + pre + post
if ((llLen % llAlign) != 0)
llLen = (llLen + llAlign) - (llLen % llAlign); // correct for alignment
printf ("#%d: Start %I64d samples = %.3f ms", i, pllStamps[4 * i], dTime_ms);
printf ("(Len = %I64d samples)\n", llLen);
}
Image 77: Drawing of Gated Sampling mode and Timestamp positions
Summary of Contents for M2p.59 Series
Page 190: ......