Skip to content

Infineon/mtb-example-psoc4-msclp-lls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSOC™ 4: MSCLP CAPSENSE™ liquid level sensing

This code example demonstrates an implementation of capacitive sensors to measure the depth of water-based liquids in nonconductive containers. Mounted on or near the container exterior, these sensors provide accurate, real-time monitoring of liquid fill levels, while also rejecting foam interference and eliminating the need for physical contact with the liquid.

Note: When using the liquid level sensing flex PCB provided with the kit, this code example delivers efficient performance for liquid level detection. However, it provides less efficient and less accurate results for foam rejection due to the thin flex PCB used. For applications that require reliable foam rejection, it is highly recommended to use FR4 PCBs. If flex PCBs must be used, thicker flex PCBs are advised to reduce parasitic capacitance between the active sensors and the shield..

View this README on GitHub.

Provide feedback on this code example.

Requirements

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

This example uses the board's default configuration. See the kit user guide to configure the required operating voltage on the kit and to setup the VDDA supply voltage, see the Set up the VDDA supply voltage and debug mode in Device Configurator section.

This application is tuned to perform optimally at the default voltage. However, you can observe the basic functionality at other supported voltages.

Note: Some PSOC™ 4 kits ship with KitProg2 installed. ModusToolbox™ requires KitProg3. Before using this code example, make sure that the board is upgraded to KitProg3. The tool and instructions are available in the Firmware Loader GitHub repository. If you do not upgrade, you will see an error like "unable to find CMSIS-DAP device" or "KitProg firmware is out of date".

Software setup

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

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 "MSCLP CAPSENSE LLS" application with the desired name "MyLLS" configured for the CY8CPROTO-040T-MS BSP into the specified working directory, C:/mtb_projects:

project-creator-cli --board-id CY8CPROTO-040T-MS --app-id mtb-example-psoc4-msclp-lls --user-app-name MyLLS --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. Ensure the board is connected with the liquid level sensing flex PCB

    Note: If a custom container is used other than the bottle provided with the kit, the system may need a liquid level factory calibration as mentioned in the Perform liquid level calibration section

  2. Connect the board to your PC using the provided USB cable through the KitProg3 USB connector

  3. Program the board using one of the following:

    Note: It is essential to completely empty the tank before programming to ensure accurate one-time calibration. See the One-time factory auto-calibration section for further details

    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
    
  4. After programming, the application starts automatically

    Note: After programming, you may see the following error message if debug mode is disabled, see Table 7 of the Debugging section for the default debug configuration in the supported kits. Ignore the error or enable debug mode to solve it

    "Error: Error connecting Dp: Cannot read IDR"
  5. To test the application, observe the LED behavior as shown in Table 1

Table 1. LED indications and status

Scenario CY8CPROTO-040T-MS CY8CPROTO-041TP LED Status
Tank detected LED2 LED2 ON
Liquid Presence detected (60 mm) LED2 & LED3 LED2 & LED3 ON

Monitor data using CAPSENSE™ Tuner

  1. Open CAPSENSE™ Tuner from the IDE Quick Panel of the Eclipse IDE for ModusToolbox™

    Or

    Run the CAPSENSE™ Tuner application in standalone mode from {ModusToolbox™ install directory}/ModusToolbox/tools_{version}/capsense-configurator/capsense-tuner. In this case, after opening the application, select File > Open and open the design.cycapsense file of the respective application, which is present in the {Application root directory}/bsps/TARGET_APP_<BSP-NAME>/config folder

    See the ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf) for options to start CAPSENSE™ Tuner using the CLI

  2. Ensure the status LED is on and not blinking, which indicates that the onboard KitProg3 is in CMSIS-DAP bulk mode. See Firmware-loader to learn how to update the firmware and switch modes in KitProg3

  3. In the Tuner application, select Tools > Tuner Communication setupor click on the Tuner Communication Setup icon

    In the window that appears, select I2C under KitProg3 and configure it as follows:

    • I2C address: 8
    • Sub-address: 2 Bytes
    • Speed (kHz): 400

    These are the same values set in the EZI2C resource

    Figure 1. Tuner communication setup parameters

  4. Select Communication > Connect or click the Connect icon to establish a connection

    Figure 2. Establish connection

  5. Select Communication > Start or Click the Start icon to start streaming data from the device

    Figure 3. Start tuner communication

    The Widget/Sensor Parameters tab is updated with the parameters configured in the CAPSENSE™ Configurator window. The tuner displays the data from the sensor in the Widget View and Graph View tabs

  6. Set the Read mode as Synchronized. Navigate to the Widget View tab and observe the needle in the Liquid_Level_Sensor_FR widget changing as you pour or remove water in the container

    Figure 4. Widget view of the CAPSENSE™ Tuner

  7. Add a layer of foam on top of the liquid, facilitated by a surfactant, and observe how the liquid level remains unaffected by the foam, as reported by the Liquid_Level_Sensor_FR widget. This demonstrates the system's ability to reject foam and maintain accurate liquid level sensing

    Figure 5. Widget view of CAPSENSE™ Tuner

    Note: The level in the Liquid_Level_Sensor changes due to the foam as it is a normal liquid level sensor and does not incorporate the foam rejection capability

  8. View the raw counts of the liquid level sensors through the Graph View tab. The normal liquid level and foam-rejected liquid level can be observed in the position window

    Figure 6. Liquid level sensor position

  9. Switch to the SNR Measurement tab and verify that the SNR is above 20:1 by performing the following steps:

    1. Select the Liquid_Level_0_Sns0 sensor under the Liquid_Level_0 widget and click Acquire Noise, as shown in Figure 7. Repeat the same (Acquire Noise) for all sensors under the Liquid_Level_0 widget

      Figure 7. CAPSENSE™ Tuner - SNR measurement: Acquire noise

    2. Fill the tank to the maximum level, Select the Liquid_Level_0_Sns0 sensor under the Liquid_Level_0 widget, and click Acquire Signal, as shown in Figure 8 and wait for the SNR measurement to complete. Repeat the same (Acquire Signal) for all the sensors under the Liquid_Level_0 widget

      Figure 8. CAPSENSE™ Tuner - SNR measurement: Acquire Signal

      Ensure the SNR is above 20:1

Tuning procedure

Create a custom BSP for your board
  1. Create a custom BSP for your board for any device by following the steps given in ModusToolbox™ BSP Assistant user guide. This code example is created for the CY8C4046LQI-T452 device

  2. Open the design.modus file from the {Application root directory}/bsps/TARGET_APP_<BSP-NAME>/config/ folder obtained in the previous step and enable CAPSENSE™ to get the design.cycapsense file. CAPSENSE™ configuration can then be started from scratch, as explained below


Note: See the "Selecting CAPSENSE™ hardware parameters" section in AN85951 – PSOC™ 4 and PSOC™ 6 MCU CAPSENSE™ design guide to learn the considerations for selecting each parameter value.

The tuning flow of the Liquid level sensing widget is shown in Figure 9.

Figure 9. Tuning flow of liquid level sensor


Perform the following steps to tune the liquid level sensing widget:

Stage 1: Set the initial hardware parameters

  1. Connect the board to your PC using the provided USB cable through the KitProg3 USB connector

  2. Launch the Device Configurator tool

    Launch it in the Eclipse IDE for ModusToolbox™ from the Quick Panel

    Or

    Launch it in standalone mode from {ModusToolbox™ install directory}/ModusToolbox/tools_{version}/device-configurator/device-configurator. In this case, after opening the application, select File > Open and open the design.modus file of the respective application located in the {Application root directory}/bsps/TARGET_APP_<BSP-NAME>/config folder

  3. Enable the CAPSENSE™ channel in the Device Configurator tool, as shown in Figure 10:

    Figure 10. Enable CAPSENSE™ in Device Configurator

    Save the changes and close the window

  4. Launch the CAPSENSE™ Configurator tool

    Launch it in Eclipse IDE for ModusToolbox™ through the "CAPSENSE™" peripheral setting in the Device Configurator or directly from the IDE Quick Panel

    Or

    Launch it in standalone mode through {ModusToolbox™ install directory}/ModusToolbox/tools_{version}/capsense-configurator/capsense-configurator. In this case, after opening the application, select File > Open and open the design.cycapsense file of the respective application present in the {Application root directory}/bsps/TARGET_APP_<BSP-NAME>/config folder

    See the ModusToolbox™ CAPSENSE™ Configurator user guide for step-by-step instructions on how to configure and launch CAPSENSE™ in ModusToolbox™

  5. In the Basic tab, configure a Liquid Level Sensing widget as a CSD RM (self-capacitance). The Liquid Level sensing widget comprises a number of sensing elements called segments. The widget uses the data from each segment to calculate the liquid level

    Figure 11. CAPSENSE™ Configurator - Basic tab

  6. Set the following in the Advanced > General tab:

    Table 2. Widget details

    Parameter Setting Description
    CAPSENSE™ IMO clock frequency (MHz) 46 IMO clock frequency
    Modulator clock divider 1 Set to obtain the optimum modulator clock frequency
    Number of init sub-conversions 3 Set to ensure proper initialization of CAPSENSE™
    Enable CIC2 hardware filter TRUE Enabling CIC2 filter helps in higher SNR

    Figure 12. CAPSENSE™ Configurator - General settings

  7. Go to the CSD Settings tab and make the following changes:

    Table 3. Scan settings

    Parameter CY8CPROTO-040T-MS Description
    Inactive sensor connection Shield Connects the inactive sensors (configured sensors that have not been scanned in a given scan slot) to the driven shield
    Shield mode Active The driven shield is a signal that replicates the sensor-switching signal. It helps reduce the sensor parasitic capacitance
    Total shield count 2 Selects the number of shield electrodes used in the design. Most designs work with one dedicated shield electrode, but some designs require multiple dedicated shield electrodes to ease the PCB layout routing or minimize the PCB area used for the shield layer
    Raw count calibration level (%) 40 If the sensor raw count saturates (equals maximum raw count) on water covering the sensor, reduce the raw count calibration level (%). This prevents raw count saturation

    Figure 13. CAPSENSE™ Configurator - Advanced CSD settings

  8. Go to the Widget Details tab

    Select the LiquidLevel0 from the left pane and set the following:

    Table 4. Initial widget parameter setting LiquidLevel0

    Parameter Setting Description
    Enable foam rejection true This is to enable the Foam Rejection Widget for the Foam Rejection functionality
    Enable tank removal detection true This is to identify if the physical tank connected to the device has been removed or is not present
    Maximum level 120 Set this value to a multiple of the total depth of the tank. For example, this project uses a 12 cm tank. Therefore, the value may be 120, 240, or 1200; however, this project has used 120, for every 1 count, 1 mm is measured
    Sense clock divider Default Value is set in Stage 2: Set sense clock frequency
    Clock source Direct Direct clock is a constant frequency sense clock source. When you choose this option, the sensor pin switches with a constant frequency
    Number of sub-conversions 60 Good starting point to ensure a fast scan time and sufficient signal. This value has to be adjusted as required in Stage 3: Fine-tune for required SNR
    Reference CDAC mode Auto Set it to Auto for initial auto-calibration
    Reference CDAC boost Disable Not required
    Fine CDAC mode Auto Set it to Auto for initial auto-calibration
    Compensation CDAC mode Auto Set it to Auto for initial auto-calibration
    Compensation CDAC divider mode Auto Set it to Auto for initial auto-calibration
    CDAC dither mode Disable Not required
    IIR filter False Not required
    Median filter True Essential to remove sudden spikes in the level measurement due to calculation errors
    Average filter True Removes periodic noises like noise from AC mains
    Jitter filter True Removes toggling of the position data

    Figure 14. CAPSENSE™ Configurator - Liquid Level Sensor widget details

    Select the LiquidLevel0_FR from the left pane and set the following:

    Table 5. Initial widget parameter setting LiquidLevel0_FR

    Parameter Setting Description
    Foam correction coefficient 64 To compensate for the foam correction level. To accurately calculate this value, follow the steps mentioned in the "Foam rejection coefficient calculation" section of AN239805 – Liquid-level sensing with PSOC™ 4 CAPSENSE™
    Maximum level Same as LiquidLevel0 widget
    Sense clock divider Same as LiquidLevel0 widget
    Clock source Same as LiquidLevel0 widget
    Number of sub-conversions 2X of LiquidLevel0 General guidance is to set the number of sub-conversions to twice the number of sub-conversions for the base widget
    Reference CDAC mode Auto Set it to Auto for initial auto-calibration
    Reference CDAC boost Disable Not required
    Fine CDAC mode Auto Set it to Auto for initial auto-calibration
    Compensation CDAC mode Auto Set it to Auto for initial auto-calibration
    Compensation CDAC divider mode Auto Set it to Auto for initial auto-calibration
    CDAC dither mode Disable Not required
    IIR filter False Not required
    Median filter True Essential to remove sudden spikes in the level measurement due to calculation errors
    Average filter True Removes periodic noise like noise from AC mains
    Jitter filter True Removes toggling of the position data

    Figure 15. CAPSENSE™ Configurator - Liquid Level Foam Rejection widget details

  9. Go to the Scan Configuration tab to select the pins and scan slots. Configure the pins for electrodes using the drop down menu

    Ensure that the bottom-most sensor is considered as Sensor 0 (Sns0) and the top-most sensor is considered as Sensor N (SnsN)

  10. The electrodes for the liquid level foam rejection widget LiquidLevel0_FR are the same as that of the liquid level widget LiquidLevel0, so the sensor electrodes of LiquidLevel0 are simply ganged to LiquidLevel0_FR widget's sensor electrodes

    Figure 16. CAPSENSE™ Configurator – Scan Configuration tab

Stage 2: Set sense clock frequency

The sense clock is derived from the modulator clock using a sense clock divider and is used to scan the sensor by driving the CAPSENSE™ switched capacitor circuits. Both the clock source and clock divider are configurable. The sense clock divider should be configured so that the pulse width of the sense clock is long enough to let the sensor capacitance charge and discharge completely. This is verified by observing the charging and discharging waveforms of the sensor using an oscilloscope and an active probe. The sensors should be probed close to the electrode and not at the sense pins or the series resistor.

See Figure 17 and Figure 18 for waveforms observed on the sensors. Figure 17 shows the proper charging when the sense clock frequency is correctly tuned. Adjust the sense clock divider so the voltage reaches at least 99.3% of VDDD in Phase 1, or VDDD/2 in Phase 0, as Figure 18 shows.

Figure 17. Proper charge cycle of a sensor


Figure 18. Improper charge cycle of a sensor

To set the proper sense clock frequency:

  1. Program the board and launch CAPSENSE™ Tuner

  2. Observe the charging waveform of the sensor and shield as described earlier

  3. If the charging is incomplete, increase the sense clock divider. Do this in CAPSENSE™ Tuner by selecting the widget and editing the sense clock divider parameter in the Widget/Sensor Parameters panel

    Note: > - The sense clock divider should be divisible by 4. This ensures that all four scan phases have equal durations > - After editing the value, click the Apply to Device button and observe the waveform again. Repeat this until you observe complete settling > - Using a passive probe will add an additional parasitic capacitance of around 15 pF; therefore, it should be considered while tuning

  4. Click Apply to Project to save the configuration to your project

    Figure 19. Sense clock divider setting

  5. Repeat this process for all the sensors and the shield. Each sensor may require a different sense clock divider value to charge or discharge completely. But all the sensors under the same widget need to have the same sense clock source, sense clock divider, and number of sub-conversions. Therefore, consider the largest sense clock divider required by the sensor for that widget

    Note: Typically, shields require a high sense clock divider. Because this project utilizes a shield, obtain the required sense clock divider for the shield. If it is higher than the liquid level sensor widget, set the same sense clock divider for the liquid level sensor widget as well

    Table 6. Sense clock divider settings obtained for supported kits

    Parameter CY8CPROTO-040T-MS CY8CPROTO-041TP
    Sense clock divider 128 128

Stage 3: Fine tune for required SNR

The sensor must provide a large signal for the processing function to accurately calculate the liquid level. Liquid level sensing systems perform best with signal-to-noise ratio (SNR) values 10 or higher. The sensitivity can be increased by increasing the number of sub-conversions and noise can be decreased by enabling available filters. This section demonstrates using CAPSENSE™ Tuner and Configurator to measure and adjust the SNR.

Follow these steps for optimizing these parameters:

  1. Measure the SNR as mentioned in Step 9 of the Operation section

  2. If the SNR is less than 20:1, increase the number of sub-conversions. Edit the number of sub-conversions (Nsub) directly in the Widget/Sensor parameters tab of the CAPSENSE™ Tuner and click on Apply to Device

    Note: Number of sub-conversion should be >= 8

  3. Repeat steps 1 and 2 until the Measured SNR is greater than 20:1

  4. If the system is noisy (>40% of signal), enable filters

    Enable the IIR filter for noise reduction

    To enable and configure filters available in the system:

    a. Open CAPSENSE™ Configurator from ModusToolbox™ Quick Panel and select the appropriate filter

    Figure 20. Filter settings in CAPSENSE™ Configurator

    Note: Add the filter based on the type of noise in your measurements. See ModusToolbox™ CAPSENSE™ Configurator user guide for details

    b. Click Save and close CAPSENSE™ Configurator. Program the device to update the filter settings

    Note: Increasing the number of sub-conversions and enabling filters increases the scan time, which in turn reduces sensor responsiveness and increases power consumption. Therefore, the number of sub-conversions and filter configuration must be optimized to achieve a balance between SNR, power, and refresh rate

Stage 4: Perform liquid level calibration

After completing the sensor tuning procedure for the expected SNR as mentioned in Stage 3: Fine-tune for required SNR, perform the liquid level calibration to train the system for level measurement.

This code example is pre-calibrated to be used with the standard liquid level sensing kit, offering a calibration range of 120 mm and a resolution of 1 mm.

For a detailed procedure on the liquid level calibration, see the Liquid-level calibration procedure section of AN239805 – Liquid-level sensing with PSOC™ 4 CAPSENSE™.

Tank removal detection

This feature detects if a physical tank is connected to the device or removed – it is enabled in this code example.

For more details on this feature, see the Tank Removal Detection section of AN239805 – Liquid-level sensing with PSOC™ 4 CAPSENSE™.

Liquid presence detection

The liquid presence detection feature reports the presence of a liquid, based on a pre-configured threshold. This feature can be enabled using either the Liquid Level widget or the Liquid Presence widget;Figure 21 shows the Liquid Presence widget view in CAPSENSE™ Tuner.

Figure 21. Liquid presence widget view of the CAPSENSE™ Tuner

For more details on this feature, including compatible widgets and threshold configuration guidelines see the Liquid Presence detection section of the Liquid-level sensing with PSOC™ 4 CAPSENSE™.

One-time factory auto-calibration

The CAPSENSE™-based liquid-level sensing system uses frozen CDAC values, which can vary across devices and sensing setups. This impacts the level measurement accuracy. To account for these variations, use this one-time factory auto-calibration.

This helps to improve measurement accuracy by handling part-to-part variations and minor mechanical variations on sensor placement.

This code example has this one-time factory auto-calibration feature enabled at the application level. It will get calibrated during the first power on after flashing and values are stored in EEPROM.

Note: It is essential to completely empty the tank attached.

For details on one-time auto-calibration, see the One-time factory auto-calibration section of AN239805 – Liquid-level sensing with PSOC™ 4 CAPSENSE™.

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.

To enable the debug option, see the Setup VDDA and debug mode in Device Configurator section. To achieve lower power consumption, it is recommended to disable it when not debugging.

See Table 7 for the default debug configuration in the supported kits.

Table 7. Debug mode option status

Kit Debug mode
CY8CPROTO-040T-MS Enabled
CY8CPROTO-041TP Enabled

Design and implementation

The project uses CAPSENSE™ middleware; see the ModusToolbox™ user guide for more details on selecting a middleware.

See AN85951 – PSOC™ 4 and PSOC™ 6 MCU CAPSENSE™ design guide for more details on CAPSENSE™ features and usage.

See AN239805 – Liquid-level sensing with PSOC™ 4 CAPSENSE™ for complete details on how to create a liquid level sensing system using CAPSENSE™. It also discusses how to design the liquid level sensors.

This code example uses a liquid level sensing widget along with its liquid level sensing foam rejection sub-widget to accurately measure the liquid level in the bottle as provided with the Liquid Level Sensing Kit. The Liquid level sensing foam rejection sub-widget provides accurate liquid level measurements while rejecting foam interference.

Figure 22. Liquid level sensor widget


Figure 23. Liquid level sensor foam rejection sub-widget

The design also has an EZI2C peripheral. The EZI2C slave peripheral is used to monitor the information of a sensor's raw and processed data on a PC using the CAPSENSE™ Tuner available in the Eclipse IDE for ModusToolbox™ via I2C communication.

The firmware scans the liquid level sensing widget and the liquid level sensing foam rejection sub-widget indefinitely. The scan results are then processed and sent to the CAPSENSE™ Tuner via the EZI2C bus. The level then can be seen under the Position window of the CAPSENSE™ Tuner.

Note: In the current project, the liquid level sensing widget and the liquid level sensing foam rejection sub-widget are scanned separately and needs to be scanned separately; they will not work if scanned together by calling Cy_CapSense_ScanAllWidgets due to architectural limitations. This will get resolved in upcoming releases.

Set up the VDDA supply voltage and debug mode in Device Configurator

  1. Open Device Configurator tool from the Quick Panel of the Eclipse for ModusToolbox™

  2. Go to the System tab. Select the Power resource and set the VDDA value under Operating conditions as shown in Figure 24

    Figure 24. Setting the VDDA supply in the System tab of Device Configurator

  3. By default, the debug mode is disabled for this application to reduce power consumption. Enable the debug mode to enable the SWD pins, as shown in Figure 25:

    Figure 25. Enable Debug mode in the System tab of Device Configurator

Resources and settings

Figure 26. EZI2C settings


Table 8. Application resources

Resource Alias/object Purpose
SCB (EZI2C) (PDL) CYBSP_EZI2C EZI2C slave driver to communicate with CAPSENSE™ Tuner
CAPSENSE™ (MSCLP0) CYBSP_MSCLP0 CAPSENSE™ driver to interact with the MSCLP hardware and interface the CAPSENSE™ sensors

Firmware flow

Figure 27. Firmware flowchart

Related resources

Resources Links
Application notes AN79953 – Getting started with PSOC™ 4
AN85951 – PSOC™ 4 and PSOC™ 6 MCU CAPSENSE™ design guide
AN239805 – Liquid-level sensing with PSOC™ 4 CAPSENSE™
AN234231 – PSOC™ 4 CAPSENSE™ ultra-low-power capacitive sensing techniques
AN92239 – Proximity sensing with CAPSENSE™
Code examples Using ModusToolbox™ on GitHub
Device documentation PSOC™ 4 datasheets
PSOC™ 4 technical reference manuals
Development kits Select your kits from the Evaluation board finder.
Libraries on GitHub mtb-pdl-cat2 – PSOC™ 4 Peripheral Driver Library (PDL)
Middleware on GitHub capsense – CAPSENSE™ library and documents
psoc4-middleware – Links to all PSOC™ 4 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.

Document history

Document title: CE240535PSOC™ 4: MSCLP CAPSENSE™ liquid level sensing

Version Description of change
1.0.0 New code example
2.0.0 Major update to support ModusToolbox™ v3.3. This version is not backward compatible with previous versions of ModusToolbox™
2.1.0 Removed foam rejection calibration process
3.0.0 Added support for CY8CPROTO-041TP Prototyping Kit. Major update to support ModusToolbox™ v3.5. This version is not backward compatible with previous versions of ModusToolbox™
4.0.0 Added one-time auto-calibration feature
Major update to support ModusToolbox™ v3.6. This version is not backward compatible with previous versions of ModusToolbox™
5.0.0 Added tank removal detection and liquid level presence feature
Major update to support ModusToolbox™ v3.7. This version is not backward compatible with previous versions of ModusToolbox™
6.0.0 Middleware version updated

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, 2024-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

No description or website provided.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors