Intermediate
20 min

Convert capacitance into a digital format with PCAP04 and MK64FN1M0VDC12

Capacitance-to-digital converter (CDC)

CDC Click with Clicker 2 for Kinetis

Published Feb 05, 2024

Click board™

CDC Click

Dev Board

Clicker 2 for Kinetis

Compiler

NECTO Studio

MCU

MK64FN1M0VDC12

Transform capacitance into digital data for enhanced accuracy and control in your projects

A

A

Hardware Overview

How does it work?

CDC Click is based on the PCAP04, a capacitance-to-digital converter from ScioSense. It covers a wide capacitance input range from a few femtofarads to several hundreds of nanofarads. Configuring the PCAP04 for different capacitance measurement tasks, such as single and differential sensors in grounded or floating connections, is easy. The CDC Click is pre-assembled with 10pF capacitors on the PC0 – PC5 header to emulate capacitive sensors. They are connected as single sensors in floating mode. There is a GND connector for connecting the capacitive sensors in grounded mode. The typical value of the capacitive sensors that can be connected is in the range of 30pF to 3.5nF. The PCAP04 has four general

purpose input/output pins (PG prefix) and can be used as pulse-density/pulse-width modulation outputs. The PCAP04 features the RDC (resistance-to-digital converter) as well. The RDC unit is mainly intended for measuring temperature, using an internal sensor and reference, or using external resistors like the PT1000 onboard. You can, however, connect an external sensor over the PT1 and PTO connectors or any other resistance element. The DSP takes information from both the CDC and RDC processes, making it available to the host MCU. You can also add another temperature sensor or temperature reference on RT2. The auxiliary port (PCAUX – PCA on CDC Click) can be used for external compensation

capacitance or external discharge resistor and guarding port. You can make a selection by soldering an R7 jumper. CDC Click can communicate with the host MCU using a standard I2C or 4-wire SPI serial interface. The selection can be made over the COMM SEL jumpers. The I2C is set by default and supports up to 100kHz of the bus frequency clock. The SPI clock frequency is up to 20MHz. 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.

CDC Click hardware overview image

Features overview

Development board

Clicker 2 for Kinetis is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit ARM Cortex-M4F microcontroller, the MK64FN1M0VDC12 from NXP Semiconductors, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a JTAG programmer connector, and two 26-pin headers for interfacing with external electronics. Its compact design with clear and easily recognizable silkscreen markings allows you to build gadgets with unique functionalities and

features quickly. Each part of the Clicker 2 for Kinetis development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 2 for Kinetis programming method, using a USB HID mikroBootloader or an external mikroProg connector for Kinetis programmer, the Clicker 2 board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Micro-B cable, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or

using a Li-Polymer battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several user-configurable buttons and LED indicators. Clicker 2 for Kinetis 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.

Clicker 2 for Kinetis dimensions image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

NXP

Pin count

121

RAM (Bytes)

262144

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
ID SEL
PB11
RST
SPI Select / ID COMM
PC4
CS
SPI Clock
PC5
SCK
SPI Data OUT
PC7
MISO
SPI Data IN
PC6
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PD8
SCL
I2C Data
PD9
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

CDC Click Schematic schematic

Step by step

Project assembly

Clicker 2 for PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 2 for Kinetis as your development board.

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker 2 Access - upright/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
Flip&Click PIC32MZ MCU step 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

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

Software Support

Library Description

This library contains API for CDC Click driver.

Key functions:

  • cdc_write_config - This function writes configuration data starting from the selected config address

  • cdc_send_opcode - This function sends a desired opcode command byte

  • cdc_read_results - This function reads all results and status registers

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 CDC Click example
 *
 * # Description
 * This example demonstrates the use of CDC click board by reading capacitance
 * measurements from C3/C2 and C5/C4 ports calculated from pure capacitance ratio
 * between those ports and port C1/C0 which is used as external C reference.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Starts measurement and reads the results. The results data is displayed on the USB UART.
 *
 * @note
 * For better accuracy and higher measurement range, add 200pF external
 * capacitor between C1/C0 ports and set it below as CDC_EXT_CAP_C1_C0_PF macro
 * before running the application. This way you will be able to measure capacitance
 * in range from 1 to 2000pF.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "cdc.h"

// Settings for reference capacitors
#define CDC_EXT_CAP_C1_C0_PF        0.0f
#define CDC_INT_CAP_PF              10.0f
#define CDC_REF                     ( CDC_EXT_CAP_C1_C0_PF + CDC_INT_CAP_PF )

static cdc_t cdc;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    cdc_cfg_t cdc_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.
    cdc_cfg_setup( &cdc_cfg );
    CDC_MAP_MIKROBUS( cdc_cfg, MIKROBUS_1 );
    err_t init_flag = cdc_init( &cdc, &cdc_cfg );
    if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( CDC_ERROR == cdc_default_cfg ( &cdc ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }

    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    cdc_results_t results;
    cdc_send_opcode ( &cdc, CDC_OPCODE_CDC_START );
    Delay_ms ( 200 );
    if ( CDC_OK == cdc_read_results ( &cdc, &results ) )
    {
        log_printf ( &logger, " C1/C0: %.1f pF\r\n", 
                     results.res_0 * CDC_REF - CDC_INT_CAP_PF );
        log_printf ( &logger, " C3/C2: %.1f pF\r\n", 
                     results.res_1 * CDC_REF - CDC_INT_CAP_PF );
        log_printf ( &logger, " C5/C4: %.1f pF\r\n\n", 
                     results.res_2 * CDC_REF - CDC_INT_CAP_PF );
        Delay_ms ( 1000 );
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ 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.