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.


Ultra-Low Voltage 8Mb Serial NOR Flash Memory

Winbond’s ultra-low voltage serial NOR Flash memory can work between 1.14V to 1.60V, which covers most of the single AA battery operation voltage range.  The lower Vcc can reduce the power ...


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

Taking SiC Mainstream: The Story of Littelfuse Power Semiconductors

Since 1964, Littelfuse has brought its legacy of stability and reliability in circuit protection to the power semiconductor space. Now, the company is pioneering a series of in-house technology breakt...

Intel and Wind River Lead Technology Innovation Delivering Resilient and Secure Functional Safety Solutions

Together, industry leaders Wind River and Intel are delivering innovative Industrial IEC 61508 functional safety certification solutions that reduce project risk. A holistic approach is used to combin...

Wind River Titanium Control Advances Industrial IoT

Gareth Noyes, Chief Strategy Officer at Wind River introduces Wind River Titanium Control, a software platform that enables critical infrastructure companies to cost-effectively evolve aging legacy co...

WSI's OLED Professional innovations create more value for You.

WSI are the PMOLED manufacturer and our factory located in Chun-Nan in Taiwan. Our products are the market leader and pioneer in PMOLED module, including the monochrome, area colors and full color one...

SKIPPER UBT21 - a Bluetooth 4.0 USB serial adapter for industrial and medical use

SKIPPER UBT21 is a Bluetooth 4.0 USB serial adapter for industrial and medical use. It incorporates a Bluetooth Dual-Mode Stack, supports ranges of up to 300 meters and transferrates of 720 kbit/s (ne...

Three of a kind - Versatility based on Low Power ARM Cortex-A15

At this year's Embedded World, MEN has presented three low power, ARM Cortex-A15-based solutions on different form factors: a VMEbus SBC, an industrial box PC and a COM Express Mini module. All so...

Enabling Embedded IoT

Eurotech, a long-time leading provider of embedded systems and a global leader in IoT enablement, showed its new modules and Multi-service IoT Gateways at Embedded World 2017. The newly introduced Eu...

PLS’ UDE and new UAD2next allow more powerful trace analysis of embedded multicore systems

The new Universal Debug Engine 4.8 from PLS Development Tools offers a bunch of new and improved features for trace analysis of embedded multicore systems. With the new access device UAD2next PLS cont...

Disruptive technologies

Rahman Jamal, Global Technology & Marketing Director, National Instruments, talks about disruptive technologies in the consumer world, but also in measurement, automation, and the embedded industr...

AdaCore Announces Availability of QGen Debugger at Embedded World 2017

Jose Ruiz, technical lead at AdaCore for the company's QGen automatic code generator toolset for model-based development, discusses that product and explains what differentiates it from other prod...

SECO IoT roadmap: from the proof of concept to the market

During Embedded World 2017 Gianluca Venere, SECO Director of Global Sales, leads us to discover the company's Industrial IoT roadmap showcased at SECO's main booth, along with the latest UDOO ...

Internet of Chocolate

HCC show off an embedded chocolate vending machine using MQTT to connect to a broker in the cloud. There is an important message behind this cool demo – security and reliability of embedded soft...