15.12 Timestamping

The CAN FD Protocol Module contains a Time Base Counter (TBC). The TBC is a 32-bit free-running counter that increments on multiples of Fcy and rolls over to zero when:

  • TBCPRE[9:0] bits (CxTSCON[9:0]) are used to configure the prescaler for the TBC.
  • Setting TBCEN (CxTSCON[16]) enables the TBC.
  • Clearing TBCEN disables, stops and resets the TBC.
  • The TBC has to be disabled before writing to CxTBC by clearing TBCEN.
  • TEFTSEN (CxTEFCON[5]) has to be set to time-stamp messages in the TEF.
  • RXTSEN (CxFIFOCONx[5]) has to be set to time-stamp messages in the individual RX FIFO.
  • The application can read CxTBC at any time. Similar to any multibyte counter, the application has to consider that the counter increments and might roll over while reading different bytes of the counter.

All timestamps are 32 bits, allowing timestamps to be used for system time synchronization with high resolution.

A rollover of the TBC will generate an interrupt if TBCIE is set.

Messages can be time-stamped either at the beginning of a frame or at the end, depending on the TSEOF bit (CxTSCON[17]). When TSEOF = 0, TSRES (CxTSCON[18]) specifies if FD frames are time-stamped at SOF or the reserved bit. Table 15-14 specifies the reference points when the timestamping occurs. At the reference point, the value of the TBC (CxTBC) is captured and stored into the message object:

Table 15-14. Reference Point
FrameCAN 2.0CAN FD
Start of TXSample point of SOFSample point of SOF or the bit after FDF
Start of RXSample point of SOFSample point of SOF or the bit after FDF
Valid TXNo error till end of EOFNo error till end of EOF
Valid RXNo error till the last, but one bit of EOFNo error till the last, but one bit of EOF