Skip to content

This code example demonstrates Infineon's static distance measurement using the XENSIV™ 60 GHz radar sensors with a PSOC™ 6 MCU for various use cases, such as liquid level sensing, parking occupancy monitoring.

License

Notifications You must be signed in to change notification settings

Infineon/mtb-example-ce241721-xensiv-60ghz-static-distance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSOC™ 6 MCU: XENSIV™ 60 GHz radar static distance measurement

This code example provides a ModusToolbox™ application for static distance measurement using the XENSIV™ BGT60TR13C and BGT60UTR11AIP 60 GHz FMCW radar sensors.

The code example processes radar raw data to calculate the distance to a static target, leveraging zero-padding, range FFT, and coherent integration for high accuracy. The algorithm returns static distance to the strongest reflected target, i.e., the target with the highest radar cross-section (RCS) within the set range and field of view (FoV). The code is modular, with radar processing logic separated into radar_processing.c and radar_processing.h, and hardware interfacing and API calls in the main.c file.

Static distance measurements can be used in various use cases, such as liquid level sensing, parking occupancy monitoring, drone altitude detection, and in any application where measuring distance to a static or stationary target is necessary. Unlike presence detection algorithms, the static distance algorithm enables the detection of non-moving or static targets.

Features are as follows:

  • Measures distance to a static target with configurable minimum and maximum range
  • Supports zero-padding for enhanced range measurement accuracy, enabling measurements with a radome lens for high accuracy
  • Utilizes the Infineon sensor DSP library for efficient radar signal processing
  • Allows for event-driven radar data acquisition via interrupt
  • Compatible with ModusToolbox™ HAL for PSOC™ 6 MCU platforms
  • Can be easily integrated into any custom application and is compatible with FreeRTOS

View this README on GitHub.

Provide feedback on this code example.

Requirements

  • ModusToolbox™ v3.5 or later (tested with v3.5)
  • Board support package (BSP) minimum required version: 4.0.0
  • Programming language: C
  • Associated parts: All PSOC™ 6 MCU parts

Supported toolchains (make variable 'TOOLCHAIN')

  • GNU Arm® Embedded Compiler v11.3.1 (GCC_ARM) – Default value of TOOLCHAIN
  • Arm® Compiler v6.22 (ARM)
  • IAR C/C++ Compiler v9.50.2 (IAR)

Supported kits (make variable 'TARGET')

Hardware setup

XENSIV™ BGT60UTR11AIP Connected Sensor Kit

The XENSIV™ KIT_CSK_BGT60UTR11AIP is a comprehensive development kit consisting of:

  • Rapid IoT Connect Developer Kit CYSBSYSKIT-DEV-01

  • XENSIV™ BGT60UTR11AIP Radar Wing EVAL_60UTR11_WING

    Figure 1. XENSIV™ BGT60UTR11AIP CSK


Set up the kit:

  1. Ensure that the EVAL_60UTR11_WING is securely mounted on top of the CYSBSYSKIT-DEV-01 kit using the pin headers

  2. Connect the CYSBSYSKIT-DEV-01 to your PC using the provided Micro-USB cable through the KitProg3 USB connector

  3. In the *resource_map.h file, define the radar sensor being currently used, i.e., BGT60UTR11AIP. By default, the BGT60UTR11AIP is selected as the connected radar sensor

  4. For optimal performance of the static distance application, place the KIT_CSK_BGT60UTR11AIP kit at a fixed location, such as the corner of a room

XENSIV™ BGT60TR13C Connected Sensor Kit

The XENSIV™ KIT_CSK_BGT60TR13C is a comprehensive development kit consisting of:

  • Rapid IoT Connect Developer Kit CYSBSYSKIT-DEV-01

  • XENSIV™ BGT60TR13C Radar Wing EVAL_BGT60TR13C_WING

    Figure 2. XENSIV™ BGT60TR13C CSK


Set up the kit:

  1. Ensure that EVAL_BGT60TR13C_WING is mounted on the top of the CYSBSYSKIT-DEV-01 kit through the pin headers

  2. Connect the CYSBSYSKIT-DEV-01 to your PC using the provided Micro-USB cable through the KitProg3 USB connector

  3. In the resource_map.h file, define the radar sensor being currently used, i.e., BGT60TR13C. By default, the BGT60UTR11AIP is selected as the connected radar sensor

  4. For optimal performance of the application, place the KIT_CSK_BGT60TR13C kit at a fixed location, such as the corner of a room

Software setup

See the ModusToolbox™ tools package installation guide for information about installing and configuring the tools package.

Install a terminal emulator if you do not have one. Instructions in this document use Tera Term.

This example requires no additional software or tools.

Using the code example

Create the project

The ModusToolbox™ tools package provides the Project Creator as both a GUI tool and a command line tool.

Use Project Creator GUI
  1. Open the Project Creator GUI tool

    There are several ways to do this, including launching it from the dashboard or from inside the Eclipse IDE. For more details, see the Project Creator user guide (locally available at {ModusToolbox™ install directory}/tools_{version}/project-creator/docs/project-creator.pdf)

  2. On the Choose Board Support Package (BSP) page, select a kit supported by this code example. See Supported kits

    Note: To use this code example for a kit not listed here, you may need to update the source files. If the kit does not have the required resources, the application may not work

  3. On the Select Application page:

    a. Select the Applications(s) Root Path and the Target IDE

    Note: Depending on how you open the Project Creator tool, these fields may be pre-selected for you

    b. Select this code example from the list by enabling its check box

    Note: You can narrow the list of displayed examples by typing in the filter box

    c. (Optional) Change the suggested New Application Name and New BSP Name

    d. Click Create to complete the application creation process

Use Project Creator CLI

The 'project-creator-cli' tool can be used to create applications from a CLI terminal or from within batch files or shell scripts. This tool is available in the {ModusToolbox™ install directory}/tools_{version}/project-creator/ directory.

Use a CLI terminal to invoke the 'project-creator-cli' tool. On Windows, use the command-line 'modus-shell' program provided in the ModusToolbox™ installation instead of a standard Windows command-line application. This shell provides access to all ModusToolbox™ tools. You can access it by typing "modus-shell" in the search box in the Windows menu. In Linux and macOS, you can use any terminal application.

The following example clones the "XENSIV™ 60 GHz radar static distance measurement" application with the desired name "XENSIV 60GHz Radar Static Distance Measurement" configured for the CYSBSYSKIT-DEV-01 BSP into the specified working directory, C:/mtb_projects:

project-creator-cli --board-id CYSBSYSKIT-DEV-01 --app-id mtb-example-ce241721-xensiv-60ghz-static-distance --user-app-name XENSIV 60GHz Radar Static Distance Measurement --target-dir "C:/mtb_projects"

The 'project-creator-cli' tool has the following arguments:

Argument Description Required/optional
--board-id Defined in the field of the BSP manifest Required
--app-id Defined in the field of the CE manifest Required
--target-dir Specify the directory in which the application is to be created if you prefer not to use the default current working directory Optional
--user-app-name Specify the name of the application if you prefer to have a name other than the example's default name Optional

Note: The project-creator-cli tool uses the git clone and make getlibs commands to fetch the repository and import the required libraries. For details, see the "Project creator tools" section of the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).

Open the project

After the project has been created, you can open it in your preferred development environment.

Eclipse IDE

If you opened the Project Creator tool from the included Eclipse IDE, the project will open in Eclipse automatically.

For more details, see the Eclipse IDE for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_ide_user_guide.pdf).

Visual Studio (VS) Code

Launch VS Code manually, and then open the generated {project-name}.code-workspace file located in the project directory.

For more details, see the Visual Studio Code for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_vscode_user_guide.pdf).

Arm® Keil® µVision®

Double-click the generated {project-name}.cprj file to launch the Keil® µVision® IDE.

For more details, see the Arm® Keil® µVision® for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_uvision_user_guide.pdf).

IAR Embedded Workbench

Open IAR Embedded Workbench manually, and create a new project. Then select the generated {project-name}.ipcf file located in the project directory.

For more details, see the IAR Embedded Workbench for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_iar_user_guide.pdf).

Command line

If you prefer to use the CLI, open the appropriate terminal, and navigate to the project directory. On Windows, use the command-line 'modus-shell' program; on Linux and macOS, you can use any terminal application. From there, you can run various make commands.

For more details, see the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).

Operation

  1. Open a terminal program and select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud

  2. Program the board using one of the following:

    Using Eclipse IDE
    1. Select the application project in the Project Explorer

    2. In the Quick Panel, scroll down, and click <Application Name> Program (KitProg3_MiniProg4)

    In other IDEs

    Follow the instructions in your preferred IDE.

    Using CLI

    From the terminal, execute the make program command to build and program the application using the default toolchain to the default target. The default toolchain is specified in the application's Makefile but you can override this value manually:

    make program TOOLCHAIN=<toolchain>
    

    Example:

    make program TOOLCHAIN=GCC_ARM
    
  3. Observe the output on the terminal:

    • The terminal initially displays initialization messages that include range accuracy, minimum range, and maximum range in centimeters, and then continuously displays measured distances in centimeters:
      -----Static Distance Measurement using Infineon XENSIV™ 60GHz Radar-----
      Range Accuracy = 2.34 cm | Minimum Range: 15.0 cm | Maximum Range: 200.0 cm
      Distance: 85.23 CMS
      Distance: 85.23 CMS
      Distance: 85.23 CMS
      
    • If errors occur (e.g., “Range FFT Failed!”), check hardware connections, zero padding factor, and register settings
    • The magnitude of the peak can be accessed in max_magnitude variable

Setting the algorithm configurations

This section explains how to configure the radar distance measurement algorithm by adjusting key parameters. The parameters control the zero padding factor and the measurable minimum and maximum distances.

Configuration parameters

Table 1 lists the parameters that can be modified to configure the radar algorithm.

Table 1. Configuration for radar algorithm

Parameter Type Description Valid values Default value
max_range_m float32_t Maximum measurable distance by the radar in meters Up to 5.0 meters 3.0
min_range_m float32_t Minimum measurable distance by the radar in meters 0.15 meters without lens, 0.05 meters with lens 0.15
zeroPadding_factor int16_t Zero padding factor for signal processing. Higher values improve resolution but increase computation. 1, 2, 4, or 8 1

Configuration

  1. Zero padding factor (zeroPadding_factor):

    • Zero padding: Zero padding is a signal processing technique where extra zeros are added to the end of a signal (in this case, radar data) before performing a Fast Fourier Transform (FFT). Zero padding adds extra zeros to the radar data before processing, improving range resolution by creating finer frequency bins without altering the radar's sampling rate. However, it does not add new information to the signal and increases computational complexity, but this helps in delivering a better range resolution

    • Set to '1', '2', '4', or '8' based on your requirements. For moderate resolution, set zeroPadding_factor to 2, to achieve a range resolution of 1.34 cm. This parameter also affects the minimum measurable range and measurement stability

    • A higher value (e.g., '4','8') provides better resolution but requires more processing power and affects the signal-to-noise ratio (SNR). This means that the reflected signal from the target must be stronger in order to be detected and might require a radome lens in most cases to reliably measure distance.

    • For the BGT60UTR11AIP radar at full bandwidth (sweeping frequency), the range resolution varies with the zero padding factor as follows:

      Table 2. Zero padding factors

      Zero padding factor Range resolution
      1 2.68 cm
      2 1.34 cm
      4 0.67 cm
      8 0.33 cm

  2. Maximum range (max_range_m):

    • Defines the maximum distance that the radar can measure (up to 5 meters)
    • Set a value in meters, e.g., max_range_m = 4.5f for a 4.5-meter range
    • Ensure that max_range_m is greater than min_range_m
    • The performance and reliability of the algorithm beyond 5.0 meters are not guaranteed
  3. Minimum range (min_range_m):

    • Defines the minimum distance that the radar can measure (down to 5 centimeters or 0.05 meters)
    • Set a value in meters, e.g., min_range_m = 0.15f for a 15-centimeter minimum
    • Ensure that min_range_m is less than max_range_m
    • Ensure that min_range_m is enough to overcome the peak at 0 Hz, otherwise algorithm will return to the minimum distance as the measured distance

Example configuration

To configure the radar to measure distances between 10 cm and 4 meters with a moderate resolution, use:

int16_t zeroPadding_factor = 4;       // Moderate resolution (0.67 cm)
float32_t max_range_m = 4.0f;         // Maximum distance of 4 m
float32_t min_range_m = 0.1f;         // Minimum distance of 10 cm

Notes

  • Ensure that min_range_m is always smaller than max_range_m to avoid invalid configurations
  • Higher zeroPadding_factor values increase computational load and decreases SNR, so balance resolution with performance based on your hardware capabilities
  • If min_range_m is too small (e.g., <0.10 m), the algorithm might return to a distance always equal to min_range_m. This occurs due to Rx-Tx signal coupling, also sometimes referred to as a peak at the zero frequency bin

Debugging

You can debug the example to step through the code.

In Eclipse IDE

Use the <Application Name> Debug (KitProg3_MiniProg4) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ user guide.

In other IDEs

Follow the instructions in your preferred IDE.

Design and implementation

This section provides APIs and their implementation.

API dependencies

The API depends on the following software components:

Table 3. Software components

Software component Description
Infineon sensor DSP library
(sensor-dsp)
Functions: ifx_range_resolution, ifx_window_hamming_f32, ifx_range_fft_f32
Provides radar-specific signal processing utilities
CMSIS-DSP library Functions: ifx_range_resolution, ifx_window_hamming_f32, ifx_range_fft_f32
Structures: arm_rfft_fast_instance_f32
Functions: arm_rfft_fast_init_f32
Enables efficient FFT computations
ModusToolbox™ HAL and PDL
(mtb-hal-cat1, mtb-pdl-cat1)
Hardware abstraction layer for PSOC™ 6 MCU (SPI, GPIO, UART)
Infineon BGT60TRxx sensor library
(sensor-xensiv-bgt60trxx)
Functions: xensiv_bgt60trxx_mtb_init, xensiv_bgt60trxx_start_frame, xensiv_bgt60trxx_get_fifo_data
Manages radar sensor communication
Retarget-IO library
(retarget-io)
Redirects STDIO to UART for debug output
Standard C libraries <stdint.h>: Fixed-width integer types (int32_t, uint16_t)
<stdlib.h>: Dynamic memory allocation (malloc, free)
Radar configuration BGT60UTR11AIP_RegisterListNew.h: Generated via bgt60-configurator-cli (Radar Development Kit, software package)
Defines radar parameters (e.g., XENSIV_BGT60TRXX_CONF_NUM_CHIRPS_PER_FRAME)

Note: Include these libraries in the ModusToolbox™ project via the Library Manager. The Radar Development Kit’s documentation and tools are available through the Infineon Developer Center.

Data structures

static_distance_context_t

It is a structure that encapsulates the state for static distance measurement, including configuration parameters, dynamically allocated buffers, and a CMSIS-DSP FFT instance. It is used by init_static_distance and get_static_distance to manage radar data processing.

Definition of static_distance_context_t is as follows:

typedef struct
{
    int32_t num_samples_zeroPadded;     
    int32_t fft_size;                  
    float32_t bin_len;               
    uint16_t skip;                     
    uint16_t max_range_bin;             
    float32_t frame XENSIV_BGT60TRXX_CONF_NUM_CHIRPS_PER_FRAME,XENSIV_BGT60TRXX_CONF_NUM_SAMPLES_PER_CHIRP;
    float32_t *zero_padded_samples;    
    cfloat32_t *fft_buffer;             
    float32_t *fft_buffer_real;         
    float32_t *fft_win;                 
    float32_t *integrated_chirp;        
    arm_rfft_fast_instance_f32 rfft;
} static_distance_context_t;

Table 4. Fields and their description

Fields Description
num_samples_zeroPadded (int32_t) Total samples per chirp after zero-padding, calculated as XENSIV_BGT60TRXX_CONF_NUM_SAMPLES_PER_CHIRP zeroPadding_factor
fft_size (int32_t) Size of the FFT output, equal to num_samples_zeroPadded/2
bin_len (float32_t) Range resolution per bin in meters, adjusted for zero-padding
skip (uint16_t) Number of FFT bins to skip, corresponding to min_range_m
max_range_bin (uint16_t) Maximum FFT bin index, corresponding to max_range_m
frame (float32_t[][]) Static 2D array holding raw radar data, sized by XENSIV_BGT60TRXX_CONF_NUM_CHIRPS_PER_FRAME and XENSIV_BGT60TRXX_CONF_NUM_SAMPLES_PER_CHIRP
zero_padded_samples (float32_t*) Dynamically allocated buffer for zero-padded chirp data, sized [NUM_CHIRPS_PER_FRAME][num_samples_zeroPadded]
fft_buffer (cfloat32_t*) Dynamically allocated buffer for complex FFT output, sized [NUM_CHIRPS_PER_FRAME][fft_size]
fft_buffer_real (float32_t*) Dynamically allocated buffer for real FFT magnitudes, sized [NUM_CHIRPS_PER_FRAME][fft_size]
fft_win (float32_t*) Dynamically allocated buffer for Hamming window coefficients, sized [num_samples_zeroPadded]
integrated_chirp (float32_t*) Dynamically allocated buffer for coherently integrated chirp data, sized [fft_size]
rfft (arm_rfft_fast_instance_f32) CMSIS-DSP FFT instance, initialized for num_samples_zeroPadded points

Notes

  • Initialized the structure using init_static_distance before use
  • Buffers are allocated dynamically in init_static_distance and persist for the application’s lifetime
  • Assumes a single receive antenna (XENSIV_BGT60TRXX_CONF_NUM_RX_ANTENNAS = 1), as configured in BGT60UTR11AIP_RegisterListNew.h

Global variables

Context

Global instance of the static_distance_context_t structure, used to maintain radar processing state across API calls.

  • Type: static_distance_context_t
  • Access: Read/write via extern static_distance_context_t context in radar_processing.h
  • Default state: Uninitialized; must be initialized with init_static_distance
  • Notes:
    • Pass &context to init_static_distance and get_static_distance
    • Ensure initialization before processing radar data

ZeroPadding_factor

Factor for zero-padding radar samples, this can be 1, 2, 4, or 8.

  • Type: int16_t

  • Default value: 2

  • Access: Read/write via extern int16_t zeroPadding_factor in radar_processing.h

  • Notes:

    • Set before calling init_static_distance to define num_samples_zeroPadded
    • Higher values increase resolution but require more memory and processing time
  • Set to 1, 2, 4, or 8 based on requirements. For moderate resolution, set zeroPadding_factor = 2 to achieve a range resolution of 1.34 cm. This parameter also affects minimum measurable range and measurement stability

  • A higher value (e.g., 4,8) provides better resolution but requires more processing power and affects the signal-to-noise ratio (SNR), which means that the reflected signal from target must be stronger to detect and might require a radome lens in most cases to reliably measure distance

  • For the BGT60UTR11AIP radar at full bandwidth (sweeping frequency), the range resolution varies with the zero padding factor as follows:

  • Range resolution can be calculated using ifx_range_resolution() API, which internally calculates range resolution as c/2B where c is speed of light and B is bandwidth swept by the radar

  • Note that increasing zero padding will affect SNR, so a radome lens might be needed for higher zero padding factor, such as 4 and 8 to get a stable reading

max_range_m

Maximum measurable distance in meters.

  • Type: float32_t
  • Default value: 3.0f
  • Access: Read/write via extern float32_t max_range_m in radar_processing.h.
  • Notes:
    • Set before init_static_distance to calculate max_range_bin
    • Must be within the sensor’s physical range capabilities (see datasheet)
    • Maximum distance will be equal to first multiple of range resolution lesser than maximum range

min_range_m

Minimum measurable distance in meters.

  • Type: float32_t
  • Default value: 0.15f
  • Access: Read/write via extern float32_t min_range_m in radar_processing.h.
  • Notes:
    • Set before init_static_distance to calculate skip
    • Ensures that measurements ignore near-field artifacts
    • Ensure that this is enough to overcome the peak at 0 Hz, otherwise the algorithm will return to the minimum distance as measured distance
    • Minimum distance will be equal to the first multiple of range resolution greater than the minimum range

Functions

init_static_distance ( )

Initializes the radar processing context by calculating parameters, allocating buffers, initializing the FFT instance, and setting up a Hamming window for range FFT processing.

Prototype

cy_rslt_t init_static_distance(static_distance_context_t *ctx)

Parameters

  • ctx (static_distance_context_t*): Pointer to the context structure to initialize

Return Value

  • CY_RSLT_SUCCESS: Initialization completed successfully
  • CY_RSLT_TYPE_ERROR: Failure due to memory allocation or FFT initialization errors

Info

  • Allocates memory for ctx->zero_padded_samples, ctx->fft_buffer, ctx->fft_buffer_real, ctx->fft_win, and ctx->integrated_chirp
  • Initializes ctx->rfft using arm_rfft_fast_init_f32
  • Sets ctx->num_samples_zeroPadded, ctx->fft_size, ctx->bin_len, ctx->skip, and ctx->max_range_bin based on zeroPadding_factor, max_range_m, min_range_m, and radar configuration macros
  • Checks for valid algorithm configuration parameters
  • Prints range accuracy and limits to the console via printf:
    Range Accuracy=2.34 cm | Minimum Range: 15.0 cm | Maximum Range: 200.0 cm
    

Notes

  • Must be called once before get_static_distance
  • Requires zeroPadding_factor, max_range_m, and min_range_m to be set appropriately
  • Frees allocated memory on failure to prevent leaks
  • Assumes radar configuration macros (e.g., XENSIV_BGT60TRXX_CONF_END_FREQ_HZ) are defined in BGT60UTR11AIP_RegisterListNew.h

Example

#include "radar_processing.h"

int main(void)
{
    cy_rslt_t result = init_static_distance(&context);
    if (result != CY_RSLT_SUCCESS)
    {
        printf("Initialization failed!\r\n");
        // Handle error
    }
    // Proceed with radar processing
}

get_static_distance ( )

Processes a radar frame to calculate the distance to a static target. The function performs zero-padding, de-biasing, range FFT, magnitude calculation, coherent integration, and peak search to determine the distance.

Prototype

float32_t get_static_distance(static_distance_context_t *ctx, const uint16_t *frame_data)

Parameters

  • ctx (static_distance_context_t*): Pointer to an initialized context structure.
  • frame_data (const uint16_t*): Pointer to a 1D array of raw radar samples, sized NUM_SAMPLES_PER_FRAME

Return value

  • float32_t: Distance to the target in meters
  • -1.0f: Error during processing (e.g., FFT failure)

Info

  • Modifies ctx->frame, ctx->zero_padded_samples, ctx->fft_buffer, ctx->fft_buffer_real, and ctx->integrated_chirp during processing
  • Prints the calculated distance to the console via printf:
    Distance: 85.23 CMS
    
  • Prints an error message on FFT failure:
    Range FFT Failed!
    

Notes

  • Requires ctx to be initialized by init_static_distance
  • The frame_data array must contain NUM_SAMPLES_PER_FRAME samples, defined as:
    NUM_SAMPLES_PER_FRAME = XENSIV_BGT60TRXX_CONF_NUM_RX_ANTENNAS * XENSIV_BGT60TRXX_CONF_NUM_CHIRPS_PER_FRAME * XENSIV_BGT60TRXX_CONF_NUM_SAMPLES_PER_CHIRP
  • Assumes a single receive antenna and valid radar configuration
  • The returned distance is valid within the range [min_range_m, max_range_m]

Example

#include "radar_processing.h"

#define NUM_SAMPLES_PER_FRAME (XENSIV_BGT60TRXX_CONF_NUM_RX_ANTENNAS * \
                               XENSIV_BGT60TRXX_CONF_NUM_CHIRPS_PER_FRAME * \
                               XENSIV_BGT60TRXX_CONF_NUM_SAMPLES_PER_CHIRP)

static uint16_t samples[NUM_SAMPLES_PER_FRAME];

void process_radar_data(void)
{
    // Assume samples are filled by radar sensor
    float32_t distance_m = get_static_distance(&context, samples);
    if (distance_m >= 0.0f)
    {
        // Use distance_m
    }
    else
    {
        // Handle error
    }
}

The init_static_distance() API initializes a context for static distance measurement using radar sensor data. It calculates parameters, such as FFT size, range resolution, and allocates dynamic buffers for signal processing. Additionally, it sets up an Arm FFT instance and applies a Hamming window for accurate range detection. The get_static_distance() API processes radar sensor data to calculate the distance to a static object. It normalizes and debias the input frame data, applies zero-padding, and performs a range FFT to transform the signal into the frequency domain. The API then integrates chirp data, searches for the peak magnitude within a specified range, and converts the peak index to a distance measurement in meters. Figure 3 shows signal processing chain used by this code example.

Figure 3. Signal processing chain

Notes

  • Initialization

    • Call init_static_distance once at startup to allocate buffers and configure the FFT
    • Ensure zeroPadding_factor, max_range_m, and min_range_m are set before initialization if non-default values are needed
  • Memory management

    • The API uses dynamic memory allocation (malloc) for buffers in init_static_distance.
    • Buffers persist for the application’s lifetime; no deallocation is provided
    • Verify sufficient heap space in the embedded system (see PSOC™ 6 MCU documentation)
  • Error handling

    • Check init_static_distance for CY_RSLT_SUCCESS to confirm successful initialization
    • Check get_static_distance for non-negative return values to detect processing errors
  • Thread safety

    • The API is not thread-safe. Use synchronization mechanisms (e.g., mutexes) if called from multiple threads
  • Radar configuration

    • The BGT60UTR11AIP_RegisterListNew.h file must contain valid register settings, generated using the bgt60-configurator-cli tool from the Radar Development Kit
    • Ensure XENSIV_BGT60TRXX_CONF_NUM_RX_ANTENNAS = 1 for compatibility with this API
  • Performance

    • The zeroPadding_factor affects processing time and memory usage and also target detection probability. A factor of 2 or 4 provides a balance between resolution and performance
    • The FFT and coherent integration steps are optimized using CMSIS-DSP and sensor DSP libraries
  • Debug output

    • The API uses printf for console output, requiring retarget-io initialization
    • Connect a terminal emulator (e.g., Tera Term) to the KitProg3 COM port (115200 baud, 8N1) to view range accuracy and distance measurements

Related resources

Resources Links
Application notes AN228571 – Getting started with PSOC™ 6 MCU on ModusToolbox™
AN215656 – PSOC™ 6 MCU: Dual-CPU system design
AN080949 – Distance estimation solution using XENSIV™ KIT_CSK_BGT60TR13C 60 GHz radar
Code examples Using ModusToolbox™ on GitHub
Device documentation PSOC™ 6 MCU datasheets
PSOC™ 6 technical reference manuals
XENSIV™ BGT60UTR11AIP datasheet
XENSIV™ BGT60TR13C datasheet
Development kits Select your kits from the Evaluation board finder
Libraries on GitHub sensor-xensiv-bgt60trxx – Driver library to interface with the XENSIV™ BGT60TRxx 60 GHz FMCW radar sensors
sensor-dsp – Sensor-DSP library to provide signal processing functions for sensor applications
mtb-pdl-cat1 – PSOC™ 6 Peripheral Driver Library (PDL)
mtb-hal-cat1 – Hardware Abstraction Layer (HAL) library
retarget-io – Utility library to retarget STDIO messages to a UART port
Middleware on GitHub psoc6-middleware – Links to all PSOC™ 6 MCU middleware
Tools ModusToolbox™ – ModusToolbox™ software is a collection of easy-to-use libraries and tools enabling rapid development with Infineon MCUs for applications ranging from wireless and cloud-connected systems, edge AI/ML, embedded sense and control, to wired USB connectivity using PSOC™ Industrial/IoT MCUs, AIROC™ Wi-Fi and Bluetooth® connectivity devices, XMC™ Industrial MCUs, and EZ-USB™/EZ-PD™ wired connectivity controllers. ModusToolbox™ incorporates a comprehensive set of BSPs, HAL, libraries, configuration tools, and provides support for industry-standard IDEs to fast-track your embedded application development

Other resources

Infineon provides a wealth of data at www.infineon.com to help you select the right device, and quickly and effectively integrate it into your design.

For more information about connected sensor kit, see IoT sensor platform.

Document history

Document title: CE241721PSOC™ 6 MCU: XENSIV™ 60 GHz radar static distance measurement

Version Description of change
1.0.0 New code example

All referenced product or service names and trademarks are the property of their respective owners.

The Bluetooth® word mark and logos are registered trademarks owned by Bluetooth SIG, Inc., and any use of such marks by Infineon is under license.

PSOC™, formerly known as PSoC™, is a trademark of Infineon Technologies. Any references to PSoC™ in this document or others shall be deemed to refer to PSOC™.


© Cypress Semiconductor Corporation, 2025. This document is the property of Cypress Semiconductor Corporation, an Infineon Technologies company, and its affiliates ("Cypress"). This document, including any software or firmware included or referenced in this document ("Software"), is owned by Cypress under the intellectual property laws and treaties of the United States and other countries worldwide. Cypress reserves all rights under such laws and treaties and does not, except as specifically stated in this paragraph, grant any license under its patents, copyrights, trademarks, or other intellectual property rights. If the Software is not accompanied by a license agreement and you do not otherwise have a written agreement with Cypress governing the use of the Software, then Cypress hereby grants you a personal, non-exclusive, nontransferable license (without the right to sublicense) (1) under its copyright rights in the Software (a) for Software provided in source code form, to modify and reproduce the Software solely for use with Cypress hardware products, only internally within your organization, and (b) to distribute the Software in binary code form externally to end users (either directly or indirectly through resellers and distributors), solely for use on Cypress hardware product units, and (2) under those claims of Cypress's patents that are infringed by the Software (as provided by Cypress, unmodified) to make, use, distribute, and import the Software solely for use with Cypress hardware products. Any other use, reproduction, modification, translation, or compilation of the Software is prohibited.
TO THE EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE OR ACCOMPANYING HARDWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. No computing device can be absolutely secure. Therefore, despite security measures implemented in Cypress hardware or software products, Cypress shall have no liability arising out of any security breach, such as unauthorized access to or use of a Cypress product. CYPRESS DOES NOT REPRESENT, WARRANT, OR GUARANTEE THAT CYPRESS PRODUCTS, OR SYSTEMS CREATED USING CYPRESS PRODUCTS, WILL BE FREE FROM CORRUPTION, ATTACK, VIRUSES, INTERFERENCE, HACKING, DATA LOSS OR THEFT, OR OTHER SECURITY INTRUSION (collectively, "Security Breach"). Cypress disclaims any liability relating to any Security Breach, and you shall and hereby do release Cypress from any claim, damage, or other liability arising from any Security Breach. In addition, the products described in these materials may contain design defects or errors known as errata which may cause the product to deviate from published specifications. To the extent permitted by applicable law, Cypress reserves the right to make changes to this document without further notice. Cypress does not assume any liability arising out of the application or use of any product or circuit described in this document. Any information provided in this document, including any sample design information or programming code, is provided only for reference purposes. It is the responsibility of the user of this document to properly design, program, and test the functionality and safety of any application made of this information and any resulting product. "High-Risk Device" means any device or system whose failure could cause personal injury, death, or property damage. Examples of High-Risk Devices are weapons, nuclear installations, surgical implants, and other medical devices. "Critical Component" means any component of a High-Risk Device whose failure to perform can be reasonably expected to cause, directly or indirectly, the failure of the High-Risk Device, or to affect its safety or effectiveness. Cypress is not liable, in whole or in part, and you shall and hereby do release Cypress from any claim, damage, or other liability arising from any use of a Cypress product as a Critical Component in a High-Risk Device. You shall indemnify and hold Cypress, including its affiliates, and its directors, officers, employees, agents, distributors, and assigns harmless from and against all claims, costs, damages, and expenses, arising out of any claim, including claims for product liability, personal injury or death, or property damage arising from any use of a Cypress product as a Critical Component in a High-Risk Device. Cypress products are not intended or authorized for use as a Critical Component in any High-Risk Device except to the limited extent that (i) Cypress's published data sheet for the product explicitly states Cypress has qualified the product for use in a specific High-Risk Device, or (ii) Cypress has given you advance written authorization to use the product as a Critical Component in the specific High-Risk Device and you have signed a separate indemnification agreement.
Cypress, the Cypress logo, and combinations thereof, ModusToolbox, PSoC, CAPSENSE, EZ-USB, F-RAM, and TRAVEO are trademarks or registered trademarks of Cypress or a subsidiary of Cypress in the United States or in other countries. For a more complete list of Cypress trademarks, visit www.infineon.com. Other names and brands may be claimed as property of their respective owners.

About

This code example demonstrates Infineon's static distance measurement using the XENSIV™ 60 GHz radar sensors with a PSOC™ 6 MCU for various use cases, such as liquid level sensing, parking occupancy monitoring.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published