TDC 2 click
PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU
[click Product page](CLICK_PRODUCT_PAGE_LINK)
Click library
- Author : Stefan Ilic
- Date : Jan 2023.
- Type : SPI type
Software Support
We provide a library for the TDC 2 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 2 Click driver.
Standard key functions :
tdc2_cfg_setup
Config Object Initialization function.
void tdc2_cfg_setup(tdc2_cfg_t *cfg)
TDC 2 configuration object setup function.
TDC 2 Click configuration object.
Definition: tdc2.h:286
tdc2_init
Initialization function.
err_t tdc2_init(tdc2_t *ctx, tdc2_cfg_t *cfg)
TDC 2 initialization function.
TDC 2 Click context object.
Definition: tdc2.h:265
tdc2_default_cfg
Click Default Configuration function.
err_t tdc2_default_cfg(tdc2_t *ctx)
TDC 2 default configuration function.
Example key functions :
tdc2_read_results
TDC 2 results data reading function.
err_t tdc2_read_results(tdc2_t *ctx, uint8_t reg, uint32_t *reference_index, uint32_t *stop_result)
TDC 2 results data reading function.
tdc2_start_measuring
TDC 2 start measuring function.
err_t tdc2_start_measuring(tdc2_t *ctx)
TDC 2 start measuring function.
tdc2_set_resolution
TDC 2 set resolution function.
err_t tdc2_set_resolution(tdc2_t *ctx, uint32_t resolution)
TDC 2 set resolution function.
Example Description
This library contains API for TDC 2 Click driver. The library initializes and defines the SPI bus drivers to write and read data from registers, as well as the default configuration for a reading time between two STOP signals.
The demo application is composed of two sections :
Application Init
Initializes the driver after that resets the device and performs default configuration and sets the device in read mode.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( SPI_MASTER_ERROR ==
tdc2_init( &tdc2, &tdc2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define TDC2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: tdc2.h:247
void application_init(void)
Definition: main.c:50
@ TDC2_ERROR
Definition: tdc2.h:313
Application Task
This example demonstrates the use of the TDC 2 Click board by
measuring the time between two STOP signals. This example is set up to generate stop signals until FIFO fil's up which is indicated by interrupt pin going to low state. After that FIFO buffer is completely emptied by reading, and that data is used to calculate the time between STOP signals.
{
uint32_t reference_index [ 18 ] = { 0 };
uint32_t stop_result [ 18 ] = { 0 };
uint8_t cnt = 0;
Delay_ms( 10 );
{
Delay_ms( 100 );
}
{
log_printf( &logger, "CH1: Reference Index[%d]: %lu, Stop Result[%d]: %lu \r\n", ( uint16_t ) cnt,
reference_index[ cnt ], ( uint16_t ) cnt, stop_result[ cnt ] );
Delay_ms( 10 );
if ( cnt )
{
uint32_t time = 0;
stop_result[ cnt ], reference_index[ cnt ], &time );
log_printf( &logger, "Time between STOP %d and STOP %d is %lu ms \r\n",
( uint16_t ) ( cnt - 1 ), ( uint16_t ) cnt, time /
TDC2_uS_TO_mS );
Delay_ms( 10 );
}
cnt++;
}
log_printf( &logger, "---------------------------------------------- \r\n" );
}
#define TDC2_REG_INDEX_CH1_BYTE3
TDC 2 data register.
Definition: tdc2.h:87
#define TDC2_uS_TO_mS
Definition: tdc2.h:218
void tdc2_reset_index(tdc2_t *ctx)
TDC 2 reset reference index function.
err_t tdc2_get_time_between_stops(tdc2_t *ctx, uint32_t stop_result1, uint32_t reference_index1, uint32_t stop_result2, uint32_t reference_index2, uint32_t *time_in_us)
TDC 2 get time between stops function.
uint8_t tdc2_get_int_state(tdc2_t *ctx)
TDC 2 get int state function.
void application_task(void)
Definition: main.c:87
void dev_generate_stop(tdc2_t *ctx)
Dev generate stop signal function.
Definition: main.c:134
Note
In order to test this example, you will need to connect STOP1 with the DIS pin. Disable pin is
disabled by software and it isn't going to affect the working state of the TDC 2 Click Bord.
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.TDC2
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. UART terminal is available in all MikroElektronika compilers.