tdc  2.0.0.0
Main Page

TDC click

<PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU>

[click Product page](<CLICK_PRODUCT_PAGE_LINK>)


Click library

  • Author : Nenad Filipovic
  • Date : Jul 2021.
  • Type : SPI type

Software Support

We provide a library for the Tdc Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for Tdc Click driver.

Standard key functions :

Example key functions :

  • tdc_gen_pulse TDC pulse generation function.
    void tdc_gen_pulse ( tdc_t *ctx, uint32_t u_sec, uint8_t n_stops );
  • tdc_setup_measurement DC setup measurement function.
    TDC_RETVAL tdc_setup_measurement ( tdc_t *ctx, uint8_t cal_periods, uint8_t avg_cycles, uint8_t num_stops, uint8_t mode );
  • tdc_get_measurement TDC get measurement function.
    err_t tdc_get_measurement ( tdc_t *ctx, uint8_t clock_mode, uint8_t measure_num_stop, uint32_t *time, uint32_t *clock_countn, uint32_t *tof );

Example Description

This library contains an API for the TDC Click driver. This demo application shows the use of a TDC Click boardâ„¢.

The demo application is composed of two sections :

Application Init

Initialization of SPI module and log UART. After driver initialization, the app set default settings and the configures the measurement ( set the pulse to 100 us ).

void application_init ( void )
{
log_cfg_t log_cfg;
tdc_cfg_t tdc_cfg;
tdc_cfg_t tdc_cfg1;
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 115200;
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
tdc_cfg_setup( &tdc_cfg );
TDC_MAP_MIKROBUS( tdc_cfg, MIKROBUS_1 );
tdc_cfg_setup( &tdc_cfg1 );
TDC_MAP_MIKROBUS( tdc_cfg1, MIKROBUS_2 );
err_t init_flag = tdc_init( &tdc, &tdc_cfg );
init_flag |= tdc_init( &tdc_puls, &tdc_cfg1 );
if ( SPI_MASTER_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
tdc_default_cfg ( &tdc );
log_info( &logger, " Application Task " );
Delay_ms( 100 );
cal_periods = 10;
avg_cycles = 1;
num_stops = 3;
sel_mode = 1;
pulse_us = 100;
count_stop = 1;
tdc_setup_measurement( &tdc, cal_periods, avg_cycles, num_stops, sel_mode );
log_printf( &logger, "---------------------------\r\n" );
Delay_ms( 100 );
}

Application Task

This is an example that shows the use of a TDC Click boardâ„¢. In this example, after the START signal, the app sends 3 STOP signals per 100 microseconds. The application reads and displays the value of Time, Clock count and Time-of-Flight values of three performed measurements. Results are being sent to the Usart Terminal where you can track their changes.

void application_task ( void )
{
while ( tdc_get_trg( &tdc ) == 0 );
tdc_gen_pulse( &tdc_puls, pulse_us, num_stops );
while ( tdc_get_interrupt( &tdc ) == 1 );
tdc_get_measurement( &tdc, TDC_MCU_CLOCK_MODE_168_MHZ, count_stop, p_time, p_clock_count, p_tof );
log_printf( &logger, " Time[ 0 ] = %lu\r\n", p_time[ 0 ] );
log_printf( &logger, " Time[ 1 ] = %lu\r\n", p_time[ 1 ] );
log_printf( &logger, " Time[ 2 ] = %lu\r\n", p_time[ 2 ] );
log_printf( &logger, "- - - - - - - - - - - - - -\r\n" );
log_printf( &logger, " Clock count[ 0 ] = %lu\r\n", p_clock_count[ 0 ] );
log_printf( &logger, " Clock count[ 1 ] = %lu\r\n", p_clock_count[ 1 ] );
log_printf( &logger, " Clock count[ 2 ] = %lu\r\n", p_clock_count[ 2 ] );
log_printf( &logger, "- - - - - - - - - - - - - -\r\n" );
log_printf( &logger, " TOF[ 0 ] = %u us\r\n", p_tof[ 0 ] );
log_printf( &logger, " TOF[ 1 ] = %u us\r\n", p_tof[ 1 ] );
log_printf( &logger, " TOF[ 2 ] = %u us\r\n", p_tof[ 2 ] );
log_printf( &logger, "---------------------------\r\n" );
Delay_ms( 1000 );
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Tdc

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all MikroElektronika compilers, or any other terminal application of your choice, can be used to read the message.


TDC_MCU_CLOCK_MODE_168_MHZ
#define TDC_MCU_CLOCK_MODE_168_MHZ
Definition: tdc.h:153
tdc_get_interrupt
uint8_t tdc_get_interrupt(tdc_t *ctx)
TDC get interrupt function.
TDC_MAP_MIKROBUS
#define TDC_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: tdc.h:173
application_task
void application_task(void)
Definition: main.c:88
tdc_setup_measurement
err_t tdc_setup_measurement(tdc_t *ctx, uint8_t cal_periods, uint8_t avg_cycles, uint8_t num_stops, uint8_t mode)
TDC setup measurement function.
tdc_get_trg
uint8_t tdc_get_trg(tdc_t *ctx)
TDC get trigger signal function.
tdc_cfg_t
TDC Click configuration object.
Definition: tdc.h:216
application_init
void application_init(void)
Definition: main.c:44
tdc_cfg_setup
void tdc_cfg_setup(tdc_cfg_t *cfg)
TDC configuration object setup function.
tdc_t
TDC Click context object.
Definition: tdc.h:193
tdc_init
err_t tdc_init(tdc_t *ctx, tdc_cfg_t *cfg)
TDC initialization function.
tdc_get_measurement
err_t tdc_get_measurement(tdc_t *ctx, uint8_t clock_mode, uint8_t measure_num_stop, uint32_t *time, uint32_t *clock_countn, uint32_t *tof)
TDC get measurement function.
tdc_default_cfg
err_t tdc_default_cfg(tdc_t *ctx)
TDC default configuration function.
tdc_start_measurement
void tdc_start_measurement(tdc_t *ctx)
TDC start measurement function.
tdc_gen_pulse
void tdc_gen_pulse(tdc_t *ctx, uint32_t u_sec, uint8_t n_stops)
TDC pulse generation function.