Skip to content

This example, developed on PIC32CM-PL10 CNano, highlights use of MVIO feature in the PIC32CM-PL10 family and 5V operation of MCUs for industrial applications that involve analog sensors operating at a different voltage than 4-20mA current loop transmitter

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/pic32cm-pl10-mvio-interfacing-industrial-sensor-4-20ma-tx-vscode

Repository files navigation

Microchip Technologies Inc.

Interfacing Industrial Sensors With 4–20 mA Current Loop Transmitter Using MVIO in the Arm® Cortex®-M0+ Based PIC32CM PL10 Microcontroller Family

Introduction

Microcontrollers operating with 5V power supply offer enhanced immunity to interference and improved signal transmission stability, while maintaining low-power consumption. These features make them highly suitable for industrial control and automation applications, particularly for use with analog sensors, operating at 5V, in high-interference environments. Additionally, to transmit the processed sensor data over a long distance and without interference, the 4–20 mA current loop is by far the dominant standard in the industrial segment. To minimize power consumption, the ICs used in current loop transmitter circuitry are usually powered by 3.3V. Therefore, to interface sensors and microcontrollers operating at 5V with a 4–20 mA current loop transmitter, a voltage level shifter is typically needed. The PIC32CM PL10 microcontroller (MCU) family is well-suited for these applications, as the on-chip Multi-Voltage I/O (MVIO) interface capability eliminates the need for external level shifter when interfacing the microcontroller with external IC operating at a different voltage. It allows a subset of the I/O pins to be powered by a different I/O voltage domain, namely VDDIO2. Thus, the serial interface pins of the microcontroller used for interfacing with a 4–20 mA current loop transmitter can be powered by 3.3V through the VDDIO2 pin.

The PIC32CM PL10 family — based on the Arm® Cortex®-M0+ processor — is designed for developers moving up from 8-bit MCUs while retaining the simplicity and peripheral structure they expect from Microchip. This product family operates with up to 5V supply and features MVIO interface with multiple I/O pins powered by an alternative VDD pin. This capability allows direct interfacing with external ICs that operate at different voltage levels, without the need for external level shifters. As a result, hardware design is simplified and overall system costs are reduced.

This code example demonstrates the 5V operating voltage and Multi-Voltage I/O (MVIO) features of the PIC32CM PL10 microcontroller family, which enable interfacing a temperature sensor with a 4–20 mA current loop transmitter operating at different voltage levels. The processed temperature sensor data is transmitted to a receiver through a 4–20 mA current loop. This code example was developed using both MPLAB® X IDE and MPLAB tools for Visual Studio Code® (VS Code®).

Related Documentation

Description


Figure 1. Block Diagram

This section outlines the implementation details for the code example, covering both the transmitter and receiver parts.

4–20 mA Transmitter

The PIC32CM6408PL10048 device operates at 5V and serves as the main microcontroller. The SHT AN Click, featuring the SHT31 sensor, is used for temperature measurement and connects directly to an Analog-to-Digital (ADC) input pin of the microcontroller. The Curiosity Nano Base for Click boards™ offers expansion options for connecting both the microcontroller and the SHT-AN Click board™.

Additionally, the EV34C35A DAC-Based 4–20 mA Current Loop evaluation board is integrated for reliable transmission of processed sensor data over longer distances. The 12-bit Digital-to-Analog (DAC) module on the EV34C35A board receives the processed sensor data from the microcontroller through the Serial Peripheral Interface (SPI) interface, which is then converted to an accurate 4–20 mA signal by the circuitry on the EV34C35A board. For more details about the operation of the EV34C35A board, refer to its user guide. Since the 12-bit DAC module operates at 3.3V while the PIC32CM6408PL10048 device operates at 5V, the configured SPI peripheral pins, supported by the MVIO interface, are powered externally with 3.3V through the VDDIO2 pin of the PIC32CM6408PL10048 device. With this configuration, the SPI peripheral pins on the PIC32CM6408PL10048 device operate at 3.3V and can interface directly with the 12-bit DAC module for the transmission of processed sensor data.

4–20 mA Receiver

In this code example, the PIC16F17146 Curiosity Nano board functions as the receiver. For more details on the receiver part, refer to the 4–20 mA Current Loop Receiver code example.

Hardware Used

EV34C35A Board


Figure 2. EV34C35A Board

The EV34C35A is a DAC-based 4–20 mA Current Loop evaluation board is designed to demonstrate the performance of a 4–20 mA current loop using the MCP48CMD21 DAC. The board accepts a DAC voltage input and converts it to a current, ensuring a linear relationship between the input process variable and the output loop current. The sensor output, calculated by the host microcontroller, is provided to the current loop transmitter through the MCP48CMD21 12-bit DAC. For further information, refer to the EV34C35A DAC-Based 4–20 mA Current Loop Evaluation Board User’s Guide.

Software Used

Hardware Setup


Figure 3. Hardware Setup

Connections Between the PIC32CM6408PL10048 Transmitter and the EV34C35A Board

The following table explains the connections between PIC32CM6408PL10048 Curiosity Nano mounted on the Curiosity Nano Base board for Click boards and on the EV34C35A board. The PIC16F17146 Curiosity Nano board is utilized as the receiver.

PIC32CM6408PL10048 Cnano Board Header J2 on EV34C35A Board
PA10 (MOSI) Pin 8 (SDI)
PA11 (SCK) Pin 7 (SCK)
PA09 (MISO) Pin 6 (SDO)
PA08 (GPIO) Pin 5 (CS1)
GND Pin 2 (GND)
VDDIO2 Pin 1 (3.3V)

Since the ICs on the EV34C35A board are powered by 3.3V, the SPI pins of the PIC32CM6408PL10048 device, used for interfacing the 12-bit DAC module on the EV34C35A board, are powered by 3.3V through the VDDIO2 pin. The voltage regulator on the EV34C35A board generates 3.3V and is used to power the VDDIO2 pin of the PIC32CM6408PL10048 device.

Note: Before powering the SPI pins through the VDDIO2 pin, ensure that resistor R110 is removed from the Curiosity Nano board. Failure to remove this resistor may result in permanent damage to the board.


Figure 4. PIC32M6408PL10048 Curiosity Nano Board

Connections Between the PIC16F17146 Receiver and the EV34C35A Board

In the receiver application, the receiver performs two key functions. First, it senses the current flowing through the loop using the Proto Click module installed in slot 2. Second, it supplies power to the loop via the Boost Click module installed in slot 1.

The VOUT pin of the Boost Click module is connected to the positive terminal of the EV34C35A board. The ground connection is routed through the Proto Click module before reaching the ground terminal of the EV34C35A board.

Note 1: It is recommended to use separate isolated power supplies, such as two independent USB power adapters or power banks, for each board. This approach helps prevent the formation of a common ground between the transmitter and receiver.

Note 2: As the EV34C35A Board (4 to 20 mA) is powered by the receiver, make sure to power on the Receiver board before powering up the transmitter. This step needs to be performed after all hardware connections have been completed, as outlined in the Hardware Setup section.

Firmware Implementation

The transmitter application firmware is developed on the PIC32CM6408PL10048 microcontroller and generated using MCC Harmony and MPLAB tools for VS Code. Additionally, the firmware is generated using MPLAB X IDE.

The microcontroller peripherals ADC, RTC, SERCOM1-USART, SERCOM0-SPI, MVIO, Event System, and sleep modes are used to implement the transmitter firmware for the application.

The Real Time Clock (RTC) peripheral is configured to generate an interrupt every 10s, which is used as a trigger for the ADC to start the measurement. Using the Event System module, the RTC peripheral interrupt is configured as an event generator for the ADC peripheral to start sensor data measurement. The ADC peripheral is configured in Single-Ended mode with a sampling frequency of 250 kHz. The analog output from the temperature sensor is measured by the ADC and converted into a corresponding digital value.

SERCOM0 is configured as an SPI host with a frequency of 1 MHz and is used to transmit the processed sensor data to the 12-bit DAC module on the EV34C35A board. SERCOM1 is configured as a Universal Synchronous Asynchronous Receiver Transmitter (USART) module with a baud rate of 115200 and is used to print the measured temperature sensor data on the terminal window of the Data Visualizer.

Using the MVIO interface, the SPI I/O pins are powered by 3.3V through the VDDIO2 pin. Standby sleep mode is enabled in the application to place the device into a low-power state whenever the microcontroller is idle and not measuring temperature sensor data. The device wakes from sleep in response to an RTC interrupt.

The on-board LED of the PIC32CM6408PL10048 Curiosity Nano board is used to indicate the operating status of the transmitter device. When the LED is ON, the transmitter is in active mode. When the LED is OFF, the transmitter is in sleep mode.

Sensor Parameter to Current Conversion

The conversion from temperature reading to DAC value is carried out using the following formula:

DAC_COUNT = (TEMP_READING-LOWEST_TEMP) * (DAC_COUNT_20mA- DAC_COUNT_4mA)/(HIGHEST_TEMP- LOWEST_TEMP) + DAC_COUNT_4mA

For this example, LOWEST_TEMP is set as 0 °C. HIGHEST_TEMP is set as 100 °C.

Note: If any other sensor is used at the transmitter side, remember to change macros in the 'main.c' file according to the sensor and its range. This should match with the receiver firmware for correct operation.

DAC_COUNT20mA and DAC_COUNT4mA are the DAC values required to set 20 mA and 4 mA of current, respectively. The Transmitter Calibration section explains the procedure to find out these DAC values.

Transmitter Calibration

To perform the calibration of the 4–20 mA transmitter click, determine the 4–20 mA EV34C35A board’s DAC register values corresponding to 4 mA and 20 mA current through the loop.

Ensure that the EV34C35A board is powered on first, as its loop side receives power from the receiver and then power-on the transmitter. Confirm that the loop provides sufficient voltage for the EV34C35A board’s operation. The loop can be powered either by a DC source or by the Boost Click module of the current loop receiver.

To calibrate the transmitter, try updating DAC values over the range of 0 to 4095. Use a multimeter to measure the current and record the DAC values for 4 mA and 20 mA of current. The respective DAC values are then used in the transmitter firmware. For the setup of this example, a DAC value of 135 for 4 mA and a DAC value of 4000 for 20 mA have been recorded. These values can vary depending on the cable type and length used.

Peripheral Configuration Summary

All peripheral and clock configurations for this example are generated using MPLAB® Code Configurator (MCC) inside Visual Studio Code for the PIC32CM6408PL10 microcontroller. The peripheral configuration is as per the table below.

Sr. No. Peripheral Configuration Usage
1 Clock Control Clock Source - HFINTOSC
Frequency - 24 MHz
Divider - 1
Clock Tuning - Enabled
GCLK0 Channel 8 – Enabled (SERCOM1 - USART)
GCLK0 Channel 6 - Enabled (SERCOM0 - SPI)
GCLK0 Channel 1 - Enabled (EVSYS)
System Clock
2 EVSYS User List - ADC0_START
Enable Channel 0
Event Source - RTC_CMP_0
Path Selection - Asynchronous
Event Edge Detection - Rising Edge
Run In Standby Sleep Mode - Enabled
Event USER Settings - Channel 0 - ADC0_START Channel Selection
Used for waking up the device from Sleep.RTC_Cmp trigger is Event Generator and ADC_Start is Event User
3 ADC0 Disable Voltage Pump
Select Timebase Time - 6
Select Operation Mode - Burst mode with accumulation
Select Prescaler - APB clock divided by 5
Sample Length - 5
Select Reference - Internal Reference 2.5V
Conversion Trigger - HW Event Trigger
Start Event Input - Enabled on Rising Edge
Conversion Start Type - Start Conversion when event is received by the ADC
Channel Configuration - Positive Input - ADC AIN26 PIN
Result Resolution - 12-bit ADC Result
Enable Result Ready Interrupt
Result Scaling - Accumulated ADC result is averaged and right adjusted
Accumulated Samples - 64 samples
ADC measures the temperature sensor data and converts it into a digital value
4 RTC RTC Count Sync Enabled
Operation Mode - 32-bit Counter mode
RTC Prescaler - DIV1
Compare Value - 0x2710 (10s)
Clear on Compare Match Enabled
Compare 0 Event Output Enable
RTC is configured to generata a compare interrupt for every 10s
5 SERCOM0 Operation Mode - SPI Master
Enable Operation in Standby mode
SPI Data Out Pad - PAD0=D0,PAD1=SCK,PAD2=SS
SPI Data In Pad - SERCOM PAD3 is used as Data Input
SPI Speed = 1 MHz
SPI is used to transmit 24-bit data
6 SERCOM1 Operation Mode - USART with internal clock
Baud Rate - 115200
Character Size - 8-bits
USART is used to display the data on terminal window

Pin Connection Table

Microcontroller Pin Signal Description
PA06 SHT AN SEL
PA29 SHT_AN_RST
PA08 SPI_CS (MVIO Pin)
PA09 SPI_MISO (MVIO Pin)
PA10 SPI_MOSI (MVIO Pin)
PA11 SPI_SCK (MVIO Pin)

Application Flow Diagram


Figure 5. Application Flow Diagram

MPLAB® Data Visualizer

Connect the hardware as outlined in the Hardware Setup section. For this demonstration, the MPLAB Data Visualizer software tool is required. Please follow the steps below to open the terminal window in the MPLAB Data Visualizer:

  1. Launch the stand-alone MPLAB Data Visualizer application.

  2. Click the Connections tab located at the top left of the Data Visualizer interface.

  3. Select the appropriate PIC32CM6408PL10 Cnano Board where the firmware is loaded, and open the COM port settings window. Please ensure that the baud rate is set to 115200.

  4. Click the right-aligned symbol on the COM tab. In the pop-up window, select the Send to Terminal option, then close the pop-up window.

  5. Test messages will begin to appear in the terminal window once the firmware is loaded onto the microcontroller.

Demo Operation

As described in the previous section, the MPLAB Data Visualizer tool is required to display data in the terminal window.

By default, the MCU operates in a sleep mode, and its status is displayed in the terminal window.


Figure 6. MCU in Sleep Mode

Every 10 seconds, the device wakes up to measure the temperature. Based on the measured temperature, the current flowing through the loop is adjusted by setting the appropriate DAC value.

Additionally, the on-board LED of the PIC32CM6408PL10048 Curiosity Nano board blinks every 10 seconds.

Upon waking, a message is displayed in the terminal window, showing the temperature reading and the corresponding DAC value.


Figure 7. Temperature and DAC Values Displayed on Terminal Window

The data transmitted from the transmitter is also displayed on the receiver. For further information on viewing the data on the receiver, refer to the Demo Operation section of the 4–20 mA Current Loop Receiver code example.

Conclusion

This code example demonstrates the usage of the MVIO feature of the PIC32CM PL10 microcontroller family by configuring the presented pins as serial communication pins for communication with an external IC module, powered at a different voltage (VDDIO2) than the operating voltage supplied to the PIC32CM6408PL10048 microcontroller, without the need for an external level shifter. The 5V operation and integrated MVIO interface of the PIC32CM PL10 microcontroller family are highly beneficial in industrial sensor applications, as they offer enhanced immunity to interference, improved signal transmission stability, and reduced BOM cost for end products by eliminating the need for an on-board level shifter IC.

About

This example, developed on PIC32CM-PL10 CNano, highlights use of MVIO feature in the PIC32CM-PL10 family and 5V operation of MCUs for industrial applications that involve analog sensors operating at a different voltage than 4-20mA current loop transmitter

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages