Skip to content

This repository contains an MPLAB® X project that uses the MTCH9010 and AVR64DD32 microcontroller to detect the absence of liquid in a container and alternately control two pumps to transfer water between containers.

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/avr64dd32-mtch9010-lack-of-liquid-alarm

Repository files navigation

Microchip Technologies Inc.

Lack of Liquid Alarm Using the AVR64DD32 Microcontroller and MTCH9010 Liquid Detector

This MPLAB® X project shows how the MTCH9010, together with an AVR64DD32 microcontroller as the host device, can be used to detect the lack of liquid in a container. The application controls two water pumps to alternately transfer water between two containers. Each container uses a MTCH9010 and a sensor to automatically stop the corresponding water pump when the liquid is no longer detected.

Related Documentation

Software Used

Hardware Used

Operation

To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board section.

Concept

Setup Description

The schematic diagram of the application is shown in the image below. Each container has a water sensor connected to a MTCH9010 Evaluation Kit and a water pump. The sensors used are the ones that are found in the Evaluation Kit, one container using a conductive sensor (Container 1) and the other a capacitive sensor (Container 2). The water pumps are powered by an external power supply that generates 6V and are controlled using a two channel relay connected on MikroBUS™ 1 socket. The two MTCH9010 boards are powered externally (from the 3V3 output of the Curiosity Nano Base board) through header J100 (Externel Control Interface) using the VDD and GND pins.

The two MTCH9010 are previously configured using the Enhanced Configuration mode before making the setup. The configuration procedure of the devices can be found in the MTCH9010 Configuration chapter. For normal operation, the ECFG slide switch will be set to OFF and the LOCK slide switch will be set to ON for using the configuration parameters that were saved in memory. The interface between the MTCH9010 and the host device for detecting the water presence is realized using the DETECT output pin (from the MTCH9010) and a GPIO (from the host device).

Note: In this situation, when powering the board externally through header J100, the jumper cap on header J201 must be removed to prevent potential damage to the board.

The diagram below shows how a sensor is placed inside the container. This application uses submersible DC pumps that are designed to operate while fully submerged in water. When using this type of pumps, it is important to ensure that the water level in the container is always higher than the intake (the part of the pump that collects water). If the water level drops below the intake, the pump will start to draw in air instead of water, condition called "running dry", potentially damaging the motor. For this reason, a liquid detection sensor is placed inside the container above the intake level. When the water level drops below the sensor, MTCH9010 will detect the lack of liquid in the container and will make the DETECT output pin low to notify the host device that the pump must be stopped.

Note: A plastic container is used in this application. The sensor is introduced through a hole inside the container and is fixed using hot glue. The sensor header's pins are placed outside the container to avoid contact with water.

MTCH9010 Configuration

Both MTCH9010 devices are configured using the Enhanced Configuration mode that allows storing the parameters in Nonvolatile memory (NVM) and reading them when the device is powered.

The parameter that influences the sensibility level for water detection is the liquid detection threshold. The higher the value of the threshold, the more water is needed for detection. For this type of application, most of the time the sensor will detect the liquid presence because it will be completely submerged in water. Because of that, it is important for the device to be sensible when the water no longer completely covers the sensor, being a sign that the water level will drop below the sensor level soon.

To determine the right threshold for each type of sensor, the first step is to determine the reference value for the sensor used (in a completely dry state) and the value measured by MTCH9010 when the sensor is completely submerged in water. After that, the delta measurement (that is compared with the threshold value to determine if the liquid is detected or not) can be obtained by subtracting the reference value from the standard measurement. In this case, the threshold will have a value that is smaller, but relatively close to the value obtained for this delta measurement.

MTCH9010 device could be configured in different ways through the Enhanced Configuration mode:

  • Using a terminal for transmitting the commands
  • Using the MPLAB MTCH9010 Plugin - This is an MPLAB Data Visualizer plugin used to configure the device and visualize device parameters in real-time graphs
  • Using the MTCH9010 Configuration Scripts - There are two PowerShell®-compatible scripts available, one for simple transmission of a predefined configuration and another that allows the user to interactively enter the desired parameters

For this example, the basic configuration script is used. To use the script, the coresponding serial port for the MTCH9010 must be configured in the script file. The script can be executed in a PowerShell terminal by first opening the terminal in the directory where the script is located, then running the command powershell .\send_param_basic.ps1. More information about the script usage can be found on the GitHub page.

The MTCH9010 configuration for this case implies two steps. The first one is to determine the right threshold based on the reference value and the second one is to use this threshold for a new configuration of the device. To enter the Enhanced Configuration mode, the LOCK slide must be configured to OFF, the ECFG slide must be configured to ON and a reset operation must be done. The board will be powered using a USB-C® cable. The external VDD pin must not be connected for this step. The USB BRIDGE slide must be configured to ON to display the output data on a serial terminal. To determine the right threshold value, the Extended Output mode must be enabled to visualize the measurements. The Extended Output Format could be set to Both standard and delta measurements for better understanding of the device behaviour in different scenarious. The sleep time will be set to one second to decrease the response time.

Conductive Sensor Configuration

For a basic configuration used to determine the reference value of the conductive sensor and the standard measurement when the sensor is completely submerged in water, the following configuration could be done. The threshold value is not important for the moment.

The reference value measured for the sensor used is 64 and the standard value when the sensor is completely submerged in water is about 62779. The calculated value for the delta measurement is 62715. After more experiments were realized, the best results were obtained with a threshold value of 62500.

The following configuration was used to configure the device for further operation. The Extended Output mode was disabled because the application doesn't use the data send by MTCH9010 through UART but only the DETECT output. After the configuration was done, the LOCK slide was configured to ON and the ECFG slide was configured to OFF to ensure that the device uses the saved parameters, as it is shown in the Setup Description section.

Capacitive Sensor Configuration

The same operations are done for the capacitive sensor. For a basic configuration used to determine the reference value of the capacitive sensor and the standard measurement when the sensor is completely submerged in water, the following configuration could be done. The threshold value is not important for the moment.

The reference value measured for the sensor used is 575 and the standard value when the sensor is completely submerged in water is 902. The calculated value for the delta measurement is 327. After more experiments were realized, the best results were obtained with a threshold value of 275.

The following configuration was used to configure the device for further operation. The Extended Output mode was disabled because the application doesn't use the data send by MTCH9010 through UART but only the DETECT output. After the configuration was done, the LOCK slide was configured to ON and the ECFG slide was configured to OFF to ensure that the device uses the saved parameters, as it is shown in the Setup Description section.

Note: The right configuration parameters could be different, depending on the sensor design and dimensions, the liquid properties or the environmental temperature and humidity.

Note: It is recommanded to use the sensors that are actually placed in the container and the wires that will be used in the final setup when the reference value is determined. The reason is that, especially for the capacitive sensor, the wires used could influence the overall capacitance and, implicitly, the measured reference value.

Host Application Overview

The host application running on the AVR64DD32 microcontroller is used to control the water pumps based on the decision about liquid absence from the MTCH9010 boards. The on-board button of the Curiosity Nano is used to start one of the pumps or to stop/pause the one that is currently running. The state machine implemented in the application is shown in the diagram below. The WAITING state is used to verify if the button was pressed for starting one of the two pumps. One pump can run at a time and it can only be started if the MTCH9010 detects water in the corresponding container. The application verifies the first container and if it doesn't contain water, the second container is verified. The PUMP_1_START/PUMP_2_START state enables the corresponding relay to start the pump and then transitions in the PUMP_1_RUNNING/PUMP_2_RUNNING state in which it is verified if the running pump must be stopped. A pump can be stopped either by the user using the button (PUMP_1_PAUSE/PUMP_2_PAUSE) and then started the same way or it is automatically stopped when water is no longer detected in the container (PUMP_1_STOP/PUMP_2_STOP), returning the app in the initial WAITING state.

The application's normal operation will be to move water from a container to the other in turn, by pressing the button to start and automatically stop when water is no longer detected, then restarted the same way. The option to pause the pump using the button offers more flexibility for the user.

The DETECT outputs of the MTCH9010 Evaluation Kits are connected to two GPIO inputs of the AVR64DD32 microcontroller, MTCH9010_DETECT_1 and MTCH9010_DETECT_2. The host verifies the presence of water in a container by checking the value of these input pins (logic 0 - water is not detected, logic 1 - water is detected). The stop condition when a pump is running is the transition from 1 to 0 for the coresponding detected input. An Interrupt-on-Change (IOC) is generated on the negative edge of these two inputs. After the interrupt occurs, a debouncing mechanism is implemented using a software delay to avoid false triggers. The state of the input is verified in the main loop after a 20 ms delay to determine if the low state of the input is maintained. The same mechanism using the IOC and software delay is also implemented for the button input.

After the software automatically shuts off the corresponding water pump when water is no longer detected, there may be instances where liquid in the tube flows back into the container, causing the sensor to briefly detect water again until it fully drains from the sensor surface. To address this, an additional condition has been implemented: the software also checks whether the water pump is operating before setting the flag to indicate an empty container.

Setup

The following peripheral and clock configurations are set up using the MPLAB Code Configurator (MCC) Melody for the AVR64DD32:

  1. Clock Control

    • Clock Selection: Internal high-frequency oscillator
    • Internal Oscillator Frequency: 1-32MHz internal oscillator
    • Oscillator Frequency Selection: 24 MHz system clock
  2. Interrupt Manager

    • Global Interrupt Enable: Enabled
  3. Pin Grid View

  4. Pins

Pin Configuration Description Custom name
PC2 Digital input DETECT output of MTCH9010 board 1 MTCH9010_DETECT_1
PC3 Digital input DETECT output of MTCH9010 board 2 MTCH9010_DETECT_2
PF6 Digital input On-board button USER_BUTTON
PA7 Digital output Relay 1 control pin RL1
PD1 Digital output Relay 2 control pin RL2

Demo

The demo shows how the water is transfered from a container to the other when the user presses the button and the pump is automatically stopped when the water is no longer detected in the corresponding container.

Summary

This project shows how the MTCH9010 can be used together with an AVR64DD32 microcontroller to detect when a container is empty and to control two water pumps that alternately transfer water between two containers.

How to Program the Curiosity Nano Board

This chapter demonstrates how to use the MPLAB X IDE to program a PIC® device with an Example_Project.X. This is applicable to other projects, too.

  1. Connect the board to the PC.

  2. Open the Example_Project.X project in MPLAB X IDE.

  3. Set the Example_Project.X project as main project.
    Right click the project in the Projects tab and click Set as Main Project.

  4. Clean and build the Example_Project.X project.
    Right click the Example_Project.X project and select Clean and Build.

  5. Select PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
    Right click the project and click Properties.
    Click the arrow under the Connected Hardware Tool.
    Select PICxxxxx Curiosity Nano (click SN), click Apply and then click OK:

  6. Program the project to the board.
    Right click the project and click Make and Program Device.



Menu

About

This repository contains an MPLAB® X project that uses the MTCH9010 and AVR64DD32 microcontroller to detect the absence of liquid in a container and alternately control two pumps to transfer water between containers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published