Intermediate
30 min

Transform inductance measurements into digital data using LDC1312-Q1 and TM4C123GH6PZ

Your inductance-to-digital transformer!

LDC Click with UNI Clicker

Published Sep 04, 2023

Click board™

LDC Click

Dev. board

UNI Clicker

Compiler

NECTO Studio

MCU

TM4C123GH6PZ

Unlock infinite possibilities with our inductance-to-digital marvel, which effortlessly converts inductance values into digital data, making it a vital component for real-time monitoring, quality control, and system automation

A

A

Hardware Overview

How does it work?

LDC Click is based on the LDC1312-Q1, two-channel, 12-bit inductance to digital converters (LDCs) for inductive sensing solutions from Texas Instruments. This Click board™ is easy to use, requiring only the sensor frequency within 1kHz and 10MHz to begin sensing. It measures the oscillation frequency of an LC resonator and outputs a digital value proportional to frequency. Inductive sensing offers better performance, reliability, and flexibility than competitive technologies at lower cost and power. This board is ideal for exact short-range measurements of conductive targets' position, motion, or composition. Conductive objects in contact with an AC electromagnetic (EM) field will induce field changes that can be detected using a sensor such

as an inductor. Conveniently, an inductor and a capacitor are used to construct an LC resonator, also known as an LC tank, to produce an EM field. In the case of an LC tank, the effect of the field disturbance is an apparent shift in the inductance of the sensor, which can be observed as a shift in the resonant frequency - using this principle, the LDC1312-Q1 works. LDC Click communicates with MCU using the standard I2C 2-Wire interface with a maximum clock frequency of 400kHz. In addition to I2C communication, two GPIO pins connected to the mikroBUS™ socket pins are also used. The SD pin routed to the RST pin of the mikroBUS™ socket, is used to place the LDC1312-Q1 in Shutdown mode, saving current, while the INT pin may be configured as an interrupt

to notify the host MCU of changes in system status. Besides, it also allows the choice of the least significant bit of its I2C slave address by positioning the SMD jumper labeled ADDR SEL to an appropriate position marked as 1 and 0. It also can connect additional external LC sensors, allowing you to replace the provided onboard sensor and solder your own at places marked with COIL1 and COIL2. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

LDC Click top side image
LDC Click bottom side image

Features overview

Development board

UNI Clicker is a compact development board designed as a complete solution that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It supports a wide range of microcontrollers, such as different ARM, PIC32, dsPIC, PIC, and AVR from various vendors like Microchip, ST, NXP, and TI (regardless of their number of pins), four mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a debugger/programmer connector, and two 26-pin headers for interfacing with external electronics. Thanks to innovative manufacturing technology, it allows you to build

gadgets with unique functionalities and features quickly. Each part of the UNI Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the UNI Clicker programming method, using a third-party programmer or CODEGRIP/mikroProg connected to onboard JTAG/SWD header, the UNI Clicker board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Type-C (USB-C) connector, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or using a Li-Po/Li

Ion battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board (plus USB HOST/DEVICE), including the well-established mikroBUS™ socket, a standardized socket for the MCU card (SiBRAIN standard), and several user-configurable buttons and LED indicators. UNI Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

UNI clicker double image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

ARM Cortex-M4

MCU Memory (KB)

256

Silicon Vendor

Texas Instruments

Pin count

100

RAM (Bytes)

32768

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Shutdown
PH0
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PH4
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PA6
SCL
I2C Data
PA7
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

LDC Click Schematic schematic

Step by step

Project assembly

UNI Clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI Clicker as your development board.

UNI Clicker front image hardware assembly
Thermo 28 Click front image hardware assembly
SiBRAIN for STM32F745VG front image hardware assembly
Prog-cut hardware assembly
UNI Clicker MB 1 - upright/with-background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Necto image step 7 hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for LDC Click driver.

Key functions:

  • ldc_get_interrupt - Get interrupt pin status

  • ldc_get_frequency - Get frequency value calculated for specific channel

  • ldc_calculate_inductance - Calculate inductance relative to frequency

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief LDC Click example
 *
 * # Description
 * This example showcases the ability of the device to detect 
 * metal objects. It configures a device for reading data from 
 * channel 0, checks if ID's are OK and reads data when interrupting 
 * is asserted and logs result.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of communication modules (I2C, UART) and 
 * additional pins. Then configures the device for reading data from 
 * channel 0, and checks if device ID's are correctly read, and
 * read the currently set divider.
 *
 * ## Application Task
 * Checks if interrupt pin is asserted, if so reads data from channel 0.
 * Calculates and returns the frequency of the sensor. If the frequency 
 * is greater than 0, then it calculates the inductance of the sensor. 
 * It will log error and error values if it occurred.
 * 
 * @author Luka Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "ldc.h"
#include "math.h"

static ldc_t ldc;
static log_t logger;

uint16_t divider;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    ldc_cfg_t ldc_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    ldc_cfg_setup( &ldc_cfg );
    LDC_MAP_MIKROBUS( ldc_cfg, MIKROBUS_1 );
    err_t init_flag = ldc_init( &ldc, &ldc_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );
        for ( ; ; );
    }

    if ( ldc_default_cfg ( &ldc ) < 0 )
    {
        log_error( &logger, " Default configuration. " );
        for ( ; ; );
    }
    
    uint16_t temp_data = 0;
    ldc_generic_read( &ldc, LDC_REG_MANUFACTURER_ID, &temp_data );
    log_printf( &logger, "> Manufacturer ID: 0x%.4X\r\n", temp_data );
    if ( LDC_MANUFACTURER_ID != temp_data )
    {
        log_error( &logger, " Manufacturer ID. " );
        for ( ; ; );
    }
    
    ldc_generic_read( &ldc, LDC_REG_DEVICE_ID, &temp_data );
    log_printf( &logger, "> Device ID 0x%.4X\r\n", temp_data );
    if ( LDC_DEVICE_ID != temp_data )
    {
        log_error( &logger, " Device ID. " );
        for ( ; ; );
    }
    
    ldc_generic_read( &ldc, LDC_REG_CLOCK_DIVIDERS_CH0, &temp_data );
    divider = temp_data & 0x3FF;
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    if ( !ldc_get_interrupt( &ldc ) )
    {
        float frequency = 0.0;
        float inductance = 0.0;
        uint16_t status = 0;
        ldc_generic_read( &ldc, LDC_REG_STATUS, &status );
        if ( status & LDC_STATUS_DRDY )
        {
            err_t ret_val = ldc_get_frequency( &ldc, LDC_REG_DATA_CH0, divider, &frequency );
            if ( !ret_val )
            {
                log_printf( &logger, "> Freq[MHz]: %.3f\r\n", frequency );
                if ( frequency > 0 )
                {
                    inductance = ldc_calculate_inductance( frequency );
                }
                log_printf( &logger, "> L[uH]: %.3f\r\n", inductance );
                log_printf( &logger, "> ************************\r\n" );
                
                Delay_ms ( 500 );
            }
            else
            {
                log_error( &logger, " Reading data: %ld", ret_val );
            }
        }
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.