TDC¶
Description¶
Time to digital converter
The TDC peripheral is a high-precision time-to-digital converter for measuring the time between a configurable start trigger and a configurable stop trigger.
For capacitive touch sensing, the TDC is used together with the ISRC and COMPA peripherals. ISRC will then drive an internal reference voltage for COMPA, nominally 0.8 V, while charging the capacitance that is also connected to the COMPA input. The time from start of charging until the COMPA output goes high is measured using the TDC.
Note that the TI-provided Power driver (used in SimpleLink SDKs for CC13xx and CC26xx devices) uses the TDC for RCOSC calibration, and that the Peripheral Sharing resource must be used to handle this safely.
TDC Behavior¶
The TDC starts counting when the start trigger occurs, and stops counting when the stop trigger has occurred a configurable number of times.
The TDC counts at either 96 MHz (generated by RCOSC) or 48 MHz (generated by RCOSC or XOSC). Note that using XOSC as counter clock source can interfere with fast XOSC startup for the application and radio stack, and can potentially break radio protocol timing.
Timing requirements for start and stop triggers vary between different use cases. See the Use Cases section below for details. For frequency/period measurements on a single signal, the maximum signal frequency is 2.4 MHz. To measure a higher frequency signal, up to 24 MHz, the TDC prescaler must be used. The prescaler detects rising edges on the input signal, and effectively divides the signal frequency by a factor 16 or 64.
The TDC startup can either be synchronous or asynchronous:
- In asynchronous startup, the start trigger must be idle before the start trigger occurs (low before a rising edge start trigger, or high before a falling edge start trigger). This mode can be used when the start signal is controlled from Sensor Controller task code, and can be triggered after the TDC has been armed.
- In synchronous startup, an opposite edge must occur on the start trigger signal before the start trigger can occur. This mode must be used when the start trigger is a continuous signal (for example a clock signal) that is not idle when the TDC is armed.
Use Cases¶
Below are the main supported use cases:
- Measure width of a single pulse
- Select the same signal as start and stop triggers, with opposite polarity
- Select stop trigger ignore count
0
- Use asynchronous start
- Timing requirements:
- Signal must be idle before the start trigger occurs
- Time between start trigger and stop trigger: 292 ns or more
- Signal must be idle after the after stop trigger for: 42 ns or more
- Measure N periods of a continuous signal (for example a clock signal), frequency up to 2.4 MHz
- Select the same signal as start and stop triggers, with same polarity
- Select stop trigger ignore count
N
- Stop trigger ignore count must be
N
rather thanN - 1
because the stop signal is active at startup
- Stop trigger ignore count must be
- Use synchronous start
- Timing requirements:
- Signal must be high for: 210 ns or more
- Signal must be low for: 210 ns or more
- Measure N periods of a continuous signal (for example a clock signal), frequency up to 24 MHz
- Enable the TDC prescaler with division factor 16 or 64
- Select TDC prescaler as start and stop trigger
- Select stop trigger ignore count
N / "prescaler division factor"
- Stop trigger ignore count must be
N
rather thanN - 1
because the stop signal is active at startup
- Stop trigger ignore count must be
- Use synchronous start
- Timing requirements:
- Time between rising edges on the signal: 42 ns or more
- Measure time from a single edge on one signal to the N’th edge on another signal
- Select different signals as start and stop triggers
- Select stop trigger ignore count
N - 1
- Use asynchronous or synchronous start
- Timing requirements:
- For asynchronous start: Start trigger signal must be idle before the start trigger occurs
- For synchronous start: Start trigger signal must be idle before start trigger occurs for: 126 ns or more
- Start trigger signal must be active for: 42 ns or more
- At startup, the stop trigger signal must be idle until: 168 ns or more after start trigger has occurred
- Stop trigger signal must be active for: 42 ns or more
- For
N > 1
, the stop trigger signal must be idle between stop triggers for: 168 ns or more
Examples¶
Pulse Width Measurement¶
// Select 2 x 48 MHz from RCOSC_HF as TDC counter clock source
tdcSetCntSource(TDC_CNTSRC_96M_RCOSC);
// Enable the TDC with:
// - Start trigger on the first rising signal edge
// - Stop trigger on the first subsequent falling signal edge
tdcSetTriggers(TDC_STARTTRIG_AUXIO_HIGH_BASE + AUXIO_I_SIGNAL, TDC_STOPTRIG_AUXIO_LOW_BASE + AUXIO_I_SIGNAL, 0);
tdcEnable();
// Start the measurement (the signal must be low at this point, and we measure the width of one high pulse)
tdcArm(TDC_START_ASYNC);
// The pulse can now occur on AUXIO_I_SIGNAL
// Wait for the TDC stop trigger for 1000 us
tdcWaitUs(1000);
// Get the TDC counter value
U16 tdcValueH;
tdcGetValue(tdcValueH, output.pulseWidth);
// Disable TDC
tdcDisable();
Capacitive Touch Sensing¶
// Enable COMPA, including 2 uA through 400 kOhm = 0.8 V reference voltage for COMPA
compaEnableWithCapTouchRef();
// Enable ISRC (6.5 uA)
U16 current = BV_ISRC_CURR_2P0U | BV_ISRC_CURR_4P5U;
isrcEnable(current);
// Select 2 x 48 MHz from RCOSC_HF as TDC counter clock source
tdcSetCntSource(TDC_CNTSRC_96M_RCOSC);
// Enable the TDC with start trigger on ISRC reset release and stop trigger on COMPA
tdcSetTriggers(TDC_STARTTRIG_ISRC_RELEASE, TDC_STOPTRIG_COMPA_HIGH, 0);
tdcEnable();
// For each pin ...
for (U16 n = 0; n < PIN_COUNT; n++) {
// Select COMPA input/ISRC output
compaSelectGpioInput(cfg.pAuxioAxdCapTouch[n]);
// Prepare the TDC and trigger start of measurement
tdcArm(TDC_START_ASYNC);
isrcRelease(cfg.pAuxioAxdCapTouch[n]);
// Wait for the TDC stop trigger for 80 us
tdcWaitUs(80);
// Re-clamp the pin to ground
isrcClamp(cfg.pAuxioAxdCapTouch[n]);
// Get the TDC counter value
tdcGetValue(output.pTdcValueH[n], output.pTdcValueL[n]);
}
// Disable COMPA, ISRC and TDC
tdcDisable();
isrcDisable();
compaDisable();
Procedures Overview¶
Name | Brief description |
fwClearManualEv() |
Clears the manual event signal, MANUAL_EV. More … |
fwPulseManualEv() |
Pulses the manual event signal, MANUAL_EV (set for two SCE clock cycles, then cleared). More … |
fwSetManualEv() |
Sets the manual event signal, MANUAL_EV. More … |
tdcArm() |
Arms the TDC. More … |
tdcCheckDoneEv() |
Returns whether the TDC done event has occurred for the last started TDC measurement. More … |
tdcDisable() |
Disables the TDC peripheral. More … |
tdcDisablePrescaler() |
Disables the TDC prescaler and disconnects any input source. More … |
tdcEnable() |
Enables the TDC peripheral. More … |
tdcEnablePrescaler() |
Selects input source and enables the TDC prescaler with the specified divider. More … |
tdcGetValue() |
Returns the TDC counter value. More … |
tdcSetCntSource() |
Sets the TDC counter clock source. More … |
tdcSetTriggers() |
Selects TDC start and stop trigger signals, and number of stop triggers to ignore before the wanted stop trigger. More … |
tdcWaitUs() |
Waits for the final TDC stop trigger to occur, or until the specified number of microseconds have elapsed. More … |
Constants¶
Name | Description |
TDC_CNTSRC_48M_RCOSC |
Count at both edges of 24 MHz clock generated by RCOSC_HF |
TDC_CNTSRC_48M_XOSC |
Count at both edges of 24 MHz clock generated by XOSC_HF |
TDC_CNTSRC_96M_RCOSC |
Count at both edges of 48 MHz clock generated by RCOSC_HF |
TDC_PRE_DIV16 |
TDC prescaler divides the rate of the input signal by 16 |
TDC_PRE_DIV64 |
TDC prescaler divides the rate of the input signal by 64 |
TDC_PRE_INPUT_AUXIO_BASE |
Prescaler input source: AUXIO (base + index) |
TDC_PRE_INPUT_COMPA |
Prescaler input source: COMPA output |
TDC_STARTTRIG_AUXIO_HIGH_BASE |
AUXIO (base + index) rising edge triggers start of measurement |
TDC_STARTTRIG_AUXIO_LOW_BASE |
AUXIO (base + index) falling edge triggers start of measurement |
TDC_STARTTRIG_COMPA_HIGH |
COMPA output rising edge triggers start of measurement |
TDC_STARTTRIG_COMPA_LOW |
COMPA output falling edge triggers start of measurement |
TDC_STARTTRIG_ISRC_CLAMP |
Clamping ISRC triggers start of measurement |
TDC_STARTTRIG_ISRC_RELEASE |
Releasing ISRC triggers start of measurement |
TDC_STARTTRIG_MANUAL_EV |
Calling fwPulseManualEv() triggers start of measurement |
TDC_STARTTRIG_TDC_PRE |
TDC prescaler triggers start of measurement |
TDC_STARTTRIG_TIMER0 |
AUX Timer 0 event triggers start of measurement |
TDC_STARTTRIG_TIMER1 |
AUX Timer 1 event triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV0_HIGH |
AUX Timer 2 event 0 rising edge triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV0_LOW |
AUX Timer 2 event 0 falling edge triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV1_HIGH |
AUX Timer 2 event 1 rising edge triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV1_LOW |
AUX Timer 2 event 1 falling edge triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV2_HIGH |
AUX Timer 2 event 2 rising edge triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV2_LOW |
AUX Timer 2 event 2 falling edge triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV3_HIGH |
AUX Timer 2 event 3 rising edge triggers start of measurement |
TDC_STARTTRIG_TIMER2_EV3_LOW |
AUX Timer 2 event 3 falling edge triggers start of measurement |
TDC_START_ASYNC |
Perform asynchronous start |
TDC_START_SYNC |
Perform synchronous start |
TDC_STOPTRIG_ADC_DONE |
ADC measurement done triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_AUXIO_HIGH_BASE |
AUXIO rising edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_AUXIO_LOW_BASE |
AUXIO falling edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_COMPA_HIGH |
COMPA output rising edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_COMPA_LOW |
COMPA output falling edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_MANUAL_EV |
Calling fwPulseManualEv() triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TDC_PRE |
TDC prescaler triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER0 |
AUX Timer 0 event triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER1 |
AUX Timer 1 event triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV0_HIGH |
AUX Timer 2 event 0 rising edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV0_LOW |
AUX Timer 2 event 0 falling edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV1_HIGH |
AUX Timer 2 event 1 rising edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV1_LOW |
AUX Timer 2 event 1 falling edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV2_HIGH |
AUX Timer 2 event 2 rising edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV2_LOW |
AUX Timer 2 event 2 falling edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV3_HIGH |
AUX Timer 2 event 3 rising edge triggers end of measurement (after skipping the specified number of stop triggers) |
TDC_STOPTRIG_TIMER2_EV3_LOW |
AUX Timer 2 event 3 falling edge triggers end of measurement (after skipping the specified number of stop triggers) |
Global Variables¶
None.
Procedures¶
fwClearManualEv¶
Prototype: fwClearManualEv()
Clears the manual event signal, MANUAL_EV.
This event signal allows software to efficiently trigger:
- TDC start/stop
- Timer 2 capture
fwPulseManualEv¶
Prototype: fwPulseManualEv()
Pulses the manual event signal, MANUAL_EV (set for two SCE clock cycles, then cleared).
This event signal allows software to efficiently trigger:
- TDC start/stop
- Timer 2 capture
fwSetManualEv¶
Prototype: fwSetManualEv()
Sets the manual event signal, MANUAL_EV.
This event signal allows software to efficiently trigger:
- TDC start/stop
- Timer 2 capture
tdcArm¶
Prototype: tdcArm(startType)
Arms the TDC. When armed, the TDC will begin counting at the start trigger.
- Use start type TDC_START_ASYNC when the start trigger signal level cannot occur before the TDC has been armed.
- Use start type TDC_START_SYNC when measuring frequency of a clock signal or other continuously toggling signal.
Parameter value(s)¶
- startType : TDC start type (TDC_START_XYZ)
tdcCheckDoneEv¶
Prototype: tdcCheckDoneEv(done)
Returns whether the TDC done event has occurred for the last started TDC measurement.
The event is cleared by calling tdcArm()
or tdcDisable()
.
Return value(s)¶
- done : 1 if the TDC is done, otherwise 0
tdcDisablePrescaler¶
Prototype: tdcDisablePrescaler()
Disables the TDC prescaler and disconnects any input source.
tdcEnablePrescaler¶
Prototype: tdcEnablePrescaler(#div, input)
Selects input source and enables the TDC prescaler with the specified divider.
Parameter value(s)¶
- #div : Divider (TDC_PRE_DIV16 or TDC_PRE_DIV64)
- input : Counter input source (TDC_PRE_INPUT_XYZ)
tdcGetValue¶
Prototype: tdcGetValue(valueH, valueL)
Returns the TDC counter value.
Return value(s)¶
- valueH : TDC value, high part (23:16)
- valueL : TDC value, low part (15:0)
tdcSetCntSource¶
Prototype: tdcSetCntSource(#cntSource)
Sets the TDC counter clock source.
Parameter value(s)¶
- #cntSource : Counter clock source (TDC_CNTSRC_XYZ)
tdcSetTriggers¶
Prototype: tdcSetTriggers(#startTrigger, #stopTrigger, ignoredStopTriggerCount)
Selects TDC start and stop trigger signals, and number of stop triggers to ignore before the wanted stop trigger.
There are timing requirements for the start and stop trigger signals, and these vary between different use-cases. See the TDC resource documentation for details.
When measuring N periods of a single signal, the stop trigger ignore count must be N. This is because the stop trigger signal is active when the start trigger occurs.
For AUXIO triggers, the index of the AUX I/O pin must be added to the base constant.
Parameter value(s)¶
- #startTrigger : Counter start trigger source (TDC_STARTTRIG_XYZ)
- #stopTrigger : Counter stop trigger source (TDC_STOPTRIG_XYZ)
- ignoredStopTriggerCount : Number of stop triggers to ignore before stopping the counter (0-65535)
tdcWaitUs¶
Prototype: tdcWaitUs(timeout)
Waits for the final TDC stop trigger to occur, or until the specified number of microseconds have elapsed.
The TDC value will normally indicate whether timeout has occurred. If the start trigger can be delayed or might not occur at all, tcdCheckDoneEv()
should be used to verify the result.
If timeout occurs, the TDC will remain active until rearmed or disabled.
Parameter value(s)¶
- timeout : Timeout value in microseconds (1-65534)