Simplify life with logic

This article explains how a confi gurable logic cell can simplify the implementation of complex functions on a PIC microcontroller.

By Manu Venkategowda, Microchip                Download PDF version of this article

Sometimes, something simple can have great benefits. Most embedded engineers need a variety of signals or logic to address the end application needs. They resort to designing complex board logics to address these needs. But what if there was a simple way to do something more complex? Some microcontrollers have flexible peripherals to perform the functions needed for complex applications. That is where the Configurable Logic Cell (CLC) comes in. The CLC peripheral has been added to the set of peripherals for Microchip PIC microcontrollers (MCUs) and allows users to design a simple function that can interface with the MCU. This CLC peripheral lets the user specify combinations of signals as inputs to a logic function, and to use the logic output to control other peripherals and IO pins, providing users the flexibility to design the function of their choice.

To keep things simple, the CLC is supported in Microchip MPLAB Code Configurator (MCC). This enables the designer to easily drag and drop logic gates to connect the inputs and outputs in a GUI format, and generate C code with the click of a button, greatly simplifying implementation of the CLC modules. Core Independent Peripherals (CIPs) handle their tasks with no additional code or supervision from the CPU to maintain their operation. The CLC is one such CIP that simplifies the implementation of complex control systems and gives developers ample design flexibility at the same time, off-loading the CPU to boost the microcontroller performance. Keep reading to learn how the CLC can be used to implement signal phase detection, complementary waveform generation or multiple parameter monitoring in an application. With a wide variety of inputs, triggers and outputs, the possibilities with the CLC are endless.

The CLC is a user-configurable peripheral, similar to a programmable logic device (PLD), but integrated into a microcontroller. Internal and external inputs can be chosen as inputs to the CLC. The CLC receives inputs from other peripherals or from an input pin. It then performs the intended logic operation and provides an output that can be used to control other peripherals or another IO pin. The CLC can receive signals, such as internal clock signal, an output of another peripheral and peripheral events such as a timer input. The selected input signals can be directed to the desired logic function through the signal gating stage.

The CLC supports various logic functions such as AND, OR, NOT, XOR, NAND, NOR and XNOR. In the CLC, the outputs of the data gating stage are inputs to the logic function selection stage. The output polarity stage is the last stage in the CLC and the desired polarity can be selected. The CLC can be used as a stand-alone peripheral in implementing sequential and combinational logic functions, thus facilitating quick event triggers and responses. It can also be used with other peripherals to help extend their capabilities, by facilitating custom implementation of complex functionalities in hardware.

Figure 1. Phase detector


Being a core independent peripheral, the CLC effectively reduces the CPU bandwidth requirement for an application, by offloading many simple and logic event responses from the CPU to the peripheral. It also reduces Flash and RAM requirements since software algorithms are not required. Logic functions implemented in hardware have faster event response compared to logic functions implemented in software. Additionally, the CLC supports a higher level of integration without any external components, reducing the overall PCB size.

The versatile features and simplicity of the CLC extend the design capabilities of a PIC MCU. One good example that demonstrates the capabilities of a CLC is in a phase detector. A phase detector can be used for many applications including distance measurement. It works on the principle that when a continuous RF wave is transmitted towards a target, the distance to the target is proportional to the phase shift between the transmitted and received waves. The CLC can be used to measure the phase difference between two signals of the same frequency. The transmitted and received waves are used as inputs to the CLC and the phase difference between the two signals at the CLC output can be used for calculating the distance between the source and target.

In the phase detector implementation using CLC, the AND-OR logic function in the CLC can be used to implement an XOR function to measure the magnitude of phase difference and the D-Flip Flop (D-FF) logic function helps in obtaining lead and lag information of the signals. Besides square waves, it is possible to measure the phase between other types of analog signals such as sinusoidal waves. Figure 1 depicts the configuration of a phase detector using CLC.

Figure 2. Complementary waveform generator in edge-aligned mode using CLC


The source signals, whose phase difference is to be measured, are fed as inputs to two comparators, which are configured as zero-cross detectors (ZCDs). The ZCDs convert the input analog signals to square waves of the same frequency. If source signals are square waves, then ZCDs are not required. The square waves are internally routed as inputs to multiple CLC modules. CLC1 and the input capture (IC) peripheral are used for determining the magnitude of phase difference. CLC1 is configured in AND-OR logic function from which XOR functionality is derived. The XORed output of CLC1 is externally connected as the source signal to the IC. The pulse width of the XORed output gives the magnitude of phase difference between the two waves and is measured by the IC. If the CLC1 output produces no signal, then the source signals are in phase.

In order to determine the phase lead and lag information of two input waveforms, the CLC is configured in a D-FF mode with one square wave used as a D input and the other used as a clock. The output of CLC2 being high or low will determine if D input leads or lags in phase with respect to the clock input. Measuring the phase angle between two signals of the same frequency is useful in many applications, including metering, digital power systems, communications and medical instruments.

Another way to use the CLC is in a complementary waveform generator (CWG). The CWG produces a complementary waveform with a dead-band control from its input source. A dead-band time is inserted between two signals to prevent shoot-through current in various power supply applications. This application illustrates the use of the CLC peripheral’s edge detection and interrupt capabilities in generating a complementary waveform with a single capture/compare/PWM (SCCP) module as its input source.

Figure 3. Multiple parameters monitoring using CLC


Often, applications, such as motor control, require several complementary waveform generators to control their functioning. The multiple capture/compare/PWM (MCCP) module can produce complementary waveforms with non-overlapping signals by controlling the dead band at its output. However, if the application requires more instances of MCCP than those available in the device, then the SCCP, in combination with the CLC, can be used. The CLC peripherals with the SCCP can be used to generate a complementary waveform with the required dead band, as the SCCP on its own cannot generate non-overlapping signals. A dead band can be added for both edge-aligned and centre-aligned SCCP outputs. Figure 2 shows the configuration of CLC1, CLC2 and CLC3 to control the dead band of the SCCP output in an edge-aligned mode.

For example, a full-bridge motor driver circuit can be driven by using an MCCP peripheral with its output producing a complementary waveform. However, if several such full-bridge motor driver circuits are to be driven, and the number of MCCP peripherals available on the device is insufficient, then an SCCP, in combination with the CLC, can be used.

Often, applications require the monitoring of different parameters, such as temperature, pressure and humidity, at the same time. If these parameters should start crossing the upper or lower thresholds, the necessary action can be taken to avert catastrophic results. Multiple comparators are available as source inputs to the CLC. In a microcontroller, a comparator can be used to monitor only one parameter. The output of multiple comparators can be combined using the CLC, to monitor multiple parameters. Necessary action can be taken when any or all of the monitored parameters exceed a certain limit. Figure 3 shows the configuration of the CLC to monitor two different parameters.

In practice, this application finds its use in monitoring temperature and pressure in an industrial plant, so that the plant can be shut down if either of the parameters exceeds a pre-set threshold. It can also be used for monitoring voltage levels in an offline uninterruptible power supply.


Slimming program for medical operating devices

Operating devices in the medical sector are not only subject to strict controls and requirements. Nowadays design demands are becoming more and more important for developers of medical HMI devices. De...

Establishing a root of trust to secure the IoT

Security is not something that any developer can ignore. It is no longer safe, for the OEM or their customers, to assume that their product or service is immune to cyber attacks. The sheer size of the...

Securing the smart and connected home

With the Internet of Things and Smart Home technologies, more and more devices are becoming connected and therefore can potentially become entry points for attackers to break into the system to steal,...


Arrow and Analog Devices strategic partnership and collaborative approach to provide solutions for our customers.

Mike Britchfield (VP for EMEA Sales) talks about why Analog Devices have a collaborative approach with Arrow Arrow’s design resources are key, from regional FAEs in the field to online des...

WE MAKE IT YOURS! Garz & Fricke to present the latest HMIs and SBCs at Electronica 2018

Sascha Ulrich, Head of Sales at Garz & Fricke, gives you a quick overview about the latest SBC, HMI and Panel-PC Highlights at electronica 2018. Learn more about the SANTOKA 15.6 Outdoor HMI, the ...

Macronix Innovations at electronica 2018

Macronix exhibited at electronica 2018 to showcase its latest innovations: 3D NAND, ArmorFlash secure memory, Ultra Low Vcc memory, and the NVM solutions with supreme quality mainly focusing on Automo...

ams CEO talks about their sensor solutions that define the mega trends of the future

In this video Alexander Everke, ams’ CEO, talks to Alix Paultre of EETimes about their optical, imaging and audio sensor solutions in fast-growing markets – from smartphones, mobile device...

Intel accelerated IoT Solutions by Arrow

Arrow is showing Intel’s Market Ready Solutions in a Retailer shop with complete eco environment. From sensors via gateways into the cloud, combined with data analytics, the full range of Intel ...

CSTAR - Manufacturers of cable assembly from Taiwan

CSTAR was founded in 2010 in Taipei, Taiwan. Through years of experience, we are experts in automotive products, LCD displays, LCD TVs, POS, computers, projectors, laptops, digital cameras, medical ca...

NXP Announces LPC5500 MCU Series

Check this video to discover the new NXP microcontroller LPC5500, the target application and focus area. Links to more information: LPC5500 Series: World’s First Arm® Cortex® -M...

Molex Meets Solutions at Electronica

These are exciting times in the electronics world as Molex migrates from a pure connectors company to an innovate solutions provider. Solutions often start at the component level, such as the connecto...

Alix Paultre investigates Bulgin's new optical fiber rugged connector range at Electronica 2018

Alix Paultre interviews Bulgin's Engineering Team Leader Christian Taylor to find out more about the company's new range of optical fiber connectors for harsh environments. As the smallest rug...

Cypress MCU and Connectivity are the best choice for real-world IoT solutions.

Cypress’ VP of Applications, Alan Hawse, explains why people should use Cypress for their IoT connectivity and MCU needs. Cypress wireless connectivity and MCU solutions work robustly and sea...

Chant Sincere unveils their latest High Speed/High Frequency connection solutions at Electronica 2018

Chant Sincere has been creating various of product families to provide comprehensive connection solutions to customers. USB Series Fakra Series QSFP Series Metric Connector Series Fibro ...

Addressing the energy challenge of IoT to unleash billions of devices

ON Semiconductor introduces various IoT use cases targeted towards smart homes/buildings, smart cities, industrial automation and medical applications on node-to-cloud platforms featuring ultra-low po...

ITECH, world leading manufacturer of power test instruments, shinned on electronica 2018

ITECH, as the leading power electronic instruments manufacturer, attended this show and brought abundant test solutions, such as automotive electronics, battery test, solar array simulator, and electr...

ITECH new series give users a fantastic user experience

ITECH latest series products have a first look at the electronics 2018, such as IT6000B regenerative power system, IT6000C bi-directional programmable DC power supply, IT6000D high power programmable ...

SOTB™ Process Technology - Energy Harvesting in Embedded Systems is Now a Reality

Exclusive SOTB technology from Renesas breaks the previous trade-off between achieving either low active current or low standby current consumption – previously you could only choose one. With S...

E-Mail Newsletters


Our 3 E-Mail Newsletters: EETimes/EDN Europe, Embedded News and Power Electronics News inform about the latest news in technology and products, as well as technical know-how like white papers, webinars, articles, etc.

B & S / ECE Magazine

- latest issue is online now -

November 2018

Content Highlights

Cover Story

Internet-connected displays make the industrial IoT more visible

Download now