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

Acoustic MEMS - letting systems listen to the world

Ambient intelligence is fast becoming a mainstream technology. Many homes now have some form of smart speakers that understand spoken commands. Car dashboards and navigation systems use voice control ...

Mass Connectivity in the 5G Era

5G will achieve faster transmission rates, more powerful data exchange networks, and more seamless real-time communication, which will enable tremendous growth for advanced and innovative connectivity...


Arduino CEO Fabio Violante on their migration upwards in engineering

In this video Arduino CEO Fabio Violante talks about their ambitious migration upwards in engineering solutions and products with Alix Paultre in Tegernsee, Germany. Arduino, long known for their deve...

Silicon Lab CEO Tyson Tuttle talks about their wireless IoT portfolio

In this video Silicon Lab's Tyson Tuttle talks to Alix Paultre about their new wireless IoT portfolio. Wireless Xpress provides a configuration-based development environment, with certified Blueto...

Keysight's Joachim Peerlings talks about the new UXR series Oscilloscope

In this video Keysight's Joachim Peerlings talks about the new UXR series Oscilloscope with Alix Paultre at their launch event in Munich. The Infiniium UXR-Series of oscilloscopes has models rangi...

BrainChip explains their new Neuromorphic System-on-Chip

In this video, Bob Beachler of BrainChip talks to Alix Paultre about their latest single-chip neural network technology.  Spiking neural networks (SNNs) are inherently lower power than traditiona...


In this video the Vincotech team walks us through the most important topics displayed on their booth at PCIM Europe 2018. It also explains why Vincotech is First in SiC Modules. Being very flexible in...

Microchip talks about their latest secure microcontroller

Microchip's new SAM L10 and SAM L11 families of 32-bit microcontrollers (MCUs) address the growing need for security in Internet of Things (IoT) endpoints by protecting against the increasing the ...

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 -

October 2018

Content Highlights

Cover Story

Slimming program for medical operating devices

Download now