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.


Solving the problem of Flash memory density

How improved die-stacking technology reduces pin count, board footprint and system complexity The direction and force of consumer demand is relentless: buyers of mobile and computing devices are co...

Common and differential mode noise AC filtering

Almost every design engineer today get challenged by the demand for miniaturization to reduce space, weight and overall size. Within external and internal power supplies working with 230VAC noise filt...

The Next Generation Touch Technology Experience

Projected Capacitive Touchscreen Technology (“PCT” or “PCAP”) is the most advanced touch solution available today. However, such high-grade technology comes at a significant co...


ZES Zimmer on testing advanced power electronics

In this video Bernd Neuner from ZES Zimmer talks to Alix Paultre for Electronic News TV at the 2017 Power Electronics Conference in Nuremberg. The discussion deals with the issues involving test and m...

Weidmüller discusses the need for a better signal and power interface

In this video Rene Arntzen from Weidmüller talks to Alix Paultre of Electronic News TV about the importance of a good signal and power interface for industrial equipment. There is currently no good ...

Mouser talks about the state of engineering development today

In this video Mark Burr-Lonnon and Graham Maggs of Mouser Electronics, a major international electronics distributor, talk to Alix Paultre about the state of engineering development today. With massiv...

Infineon launches a new family of configurable industrial drive boards

In this video Infineon explains their new family of configurable industrial drive boards at SPS-IPC Drives 2017. Intended to enable easy setup and deployment, the XMC-based automation boards can handl...

STMicro explains their STSPIN family of single-chip motor drivers

In this video STMicroelectronics explains their STSPIN single-chip motor drivers at SPS-IPC Drives 2017. The STSPIN family embeds can drive motors efficiently and with high accuracy, with an advanced ...