
Timestamps
Reading out the timestamps
(c) Spectrum Instrumentation GmbH
163
Buffer handling example for polling timestamp transfer (ABA transfer is similar, just using other registers)
Comparison of DMA and polling commands
This chapter shows you how small the difference in programming is between the DMA and the polling mode:
Data format
Each timestamp is 128 bit long and internally mapped to two consecutive 64 bit (8 bytes) values. The lower 64 bit (counter value) contains
the number of clocks that have been recorded with the currently used sampling rate since the last counter-reset has been done. The matching
time can easily be calculated as described in the general information section at the beginning of this chapter.
The values the counter is counting and that are stored in the timestamp FIFO represent the moments the trigger event occurs internally. Com
-
pared to the real external trigger event, these values are delayed. This delay is fix and therefore can be ignored, as it will be identical for all
recordings with the same setup.
Standard data format
When internally mapping the timestamp from 128 bit to two 64 bit values, the unused upper 64 bits are filled up with zeros.
Extended timestamp data format
Sometimes it is useful to store the level of additional external static signals together with a recording, such as e.g. control inputs of an external
input multiplexer or settings of an external. When programming a special flag the upper 64 bit of every 128 bit timestamp value is not (as
in standard data mode) filled up with leading zeros, but with the values of the digital inputs ( X3, X2, X1) and optionally also (X19 ..X4). The
following table shows the resulting 128 bit timestamps.
int8* pcData = (int8*) pvAllocMemPageAligned (lBufSizeInBytes);
// we now define the transfer buffer with the minimum notify size of one page = 4 kByte
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_TIMESTAMP, SPCM_DIR_CARDTOPC, 4096, (void*) pcData, 0, lBufSizeInBytes);
// we start the polling mode
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_EXTRA_POLL);
// this is pure polling loop
do
{
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_LEN, &lAvailBytes);
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_POS, &lBytePos);
if (lAvailBytes > 0)
{
printf (“We now have %d new bytes available\n”, lAvailBytes);
printf (“The available data starts at position %d\n”, lBytesPos);
// we take care not to go across the end of the buffer
if ((lB lAvailBytes) >= lBufSizeInBytes)
lAvailBytes = lBufSizeInBytes - lBytePos;
// our do function get’s a pointer to the start of the available data section and the length
vProcessTimestamps (&pcData[lBytesPos], lAvailBytes);
// the buffer section is now immediately set available for the card
spcm_dwSetParam_i32 (hDrv, SPC_TS_AVAIL_CARD_LEN, lAvailBytes);
}
}
while (!dwError); // we loop forever if no error occurs
DMA mode
Polling mode
Define the buffer
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_TIMESTAMP, SPCM_DIR...);
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_TIMESTAMP, SPCM_DIR...);
Start the transfer
spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_EXTRA_STARTDMA)
spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_EXTRA_POLL)
Wait for data
spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_EXTRA_WAITDMA)
not in polling mode
Available bytes?
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_LEN, &lBytes);
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_LEN, &lBytes);
Min available bytes programmed notify size
4 bytes
Current position?
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_LEN, &lBytes);
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_LEN, &lBytes);
Free buffer for card
spcm_dwSetParam_i32 (hDrv, SPC_TS_AVAIL_CARD_LEN, lBytes);
spcm_dwSetParam_i32 (hDrv, SPC_TS_AVAIL_CARD_LEN, lBytes);
Timestamp Mode
16
th
byte
...
11
th
byte
10
th
byte
9
th
byte
8
th
byte
7
th
byte
6
th
byte
5
th
byte
4
th
byte
3
rd
byte
2
nd
byte
1
st
byte
Standard/StartReset
0h
64 bit wide Timestamp
Refclock mode
0h
24 bit wide Refclock edge counter (seconds counter)
40 bit wide Timestamp
Timestamp Mode
16
th
byte
...
15
h
byte
14
th
byte
...
9
th
byte
8
th
byte
7
th
byte
6
th
byte
5
th
byte
4
th
byte
3
rd
byte
2
nd
byte
1
st
byte
Standard/StartReset
0h
Extra Data Word
64 bit wide Timestamp
Refclock mode
0h
Extra Data Word
24 bit wide Refclock edge counter (seconds counter)
40 bit wide Timestamp
Summary of Contents for M2p.59 Series
Page 190: ......