Timestamps
Reading out the timestamps
(c) Spectrum GmbH
113
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 56 bit long and internally mapped to 64 bit (8 bytes). The 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 56 bit to a 64 bit value the leading 8 bits are filled up with zeros (as a sign extension for
positive values), to have the stamps ready for calculations as a unsigned 64 bit wide integer value.
Extended BaseXIO-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 byte of every 64 bit timestamp value is not (as in
standard data mode) filled up with leading zeros, but with the values of the BaseXIO digital inputs. The following table shows the resulting
64 bit timestamps.
char* pcData = new char[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 pur 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
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
56 bit wide Timestamp
Refclock mode
0h
24 bit wide Refclock edge counter (seconds counter)
32bit wide sample counter
Timestamp Mode
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
XIO7…XIO0
56 bit wide Timestamp
Refclock mode
XIO7…XIO0
24 bit wide Refclock edge counter (seconds counter)
32bit wide sample counter