Do You Need an Analog Comparator in Your MCU?
This industrial computer can benefit from an MCU with an integrated analog comparator.
I remember when I built my first op-amp analog comparator in my college electronics classes using an LM358 op-amp. Such simple circuits don’t always seem to have practical use until you start designing them into real systems for your customers. An analog comparator is easy to build with positive feedback in an op-amp circuit, but you’ll always take up some space on the board with the op-amp IC and additional components in the feedback loop.
What about working with an analog comparator and your MCU? Your MCU provides plenty of integrated functions and I/Os, and one option to accept a comparator output with your MCU is to use one of the GPIOs. A better option is to find an MCU with an integrated comparator circuit, which will eliminate the need for an external op-amp circuit or comparator IC. Here’s how these circuits work in your design and some popular MCUs that include this functionality.
What is an Analog Comparator?
An analog comparator is basically a 1-bit analog-to-digital converter. Once the voltage input into the comparator exceeds some threshold, the device will shift states between its low and high voltage values. An analog comparator can be an inverting or non-inverting device. On a non-inverting device, the rising edge of the input signal will trigger the comparator output to switch from its low to high voltage output states, and vice versa on the falling edge. The behavior is reversed for an inverting comparator.
In an op-amp analog comparator circuit, positive feedback is normally used to ensure the output saturates once the input voltage switches above the external reference voltage. In other words, the op-amp will swing rail-to-rail on the rising or falling edges of the input signal. This is a simple way to create a 2-state output that saturates at two voltage levels while also provided some immunity to low-level noise.
Analog comparator output voltage with and without hysteresis.
In order to provide low-level noise immunity, analog comparator circuits can have some hysteresis, and the noise margin will depend on the size of the hysteresis window. The effect of hysteresis on switching due to an input triangle wave is shown above. If the input signal had some variation or noise, any variation within the hysteresis window will not cause switching. In an ADC with multiple bits of resolution, this would not be the case; the smaller voltage difference between quantization levels keeps
In the op-amp circuit, the size of the hysteresis window is determined by the ratio of the total resistance in the feedback loop to the resistance between the reference voltage and the non-inverting input. By setting these two values, the comparator’s hysteresis window can be adjusted to a particular application and noise margin. This is where an MCU with an integrated analog comparator really shines as it does not require these external resistors to set the size of the hysteresis window or threshold voltages.
Advantages of an Analog Comparator in Your MCU
An analog comparator integrated directly into your MCU provides a number of advantages over other methods for integrating a comparator for an analog interface with your MCU.
- Simplified switching. If you just need to detect the difference between 2 voltage states, an integrated analog comparator is a better option than using an external op-amp circuit and an ADC channel. You won’t need to program some numerical threshold and conversion into your firmware to estimate when the input voltage is truly saturated.
- Programmable hysteresis. The size of the hysteresis window can be programmed in the MCU’s firmware, or it can be set dynamically during operation. If you like, you can set the hysteresis window to be wider than the noise margin of a GPIO input, giving you a very robust circuit for detecting switching events.
- More external noise immunity. The feedline between the op-amp output and the MCU input creates another point where noise can be injected into the input, which could then create an inaccurate reading in the MCU’s ADC/GPIO. By integrating the analog comparator into the MCU, you’ve eliminated this additional point where noise can enter the system.
- Fewer components with comparable inputs. You can reduce your BOM cost without using an excessive number of inputs in your MCU when you use an MCU with an integrated analog comparator.
- Programmable propagation delay. The propagation delay in an analog comparator is defined as the time between the moment the input signal crosses the switching threshold and the moment the output state begins changes. Some MCUs with an integrated comparator allow this quantity to be programmed. By increasing the propagation delay, the MCU will consume less power during switching.
Popular MCUs with Integrated Analog Comparator
These days, you’ll find plenty of MCUs on the market from top manufacturers. Here are some popular MCUs that include integrated analog comparator features as well as a range of other interfaces:
NXP Semiconductors, S08PB
ON Semiconductor’s S08PB MCU is a smaller 8-bit device for simple embedded computing applications. This particular device includes two analog comparators with fewer peripherals, and it comes in a smaller package than many other popular MCUs by eliminating unneeded peripherals for simpler analog systems. Some useful features for analog systems include an integrated op-amp, high precision RTC counter, two flex timer modulators, and 12-channel ADC (12-bit resolution).
Block diagram for the MC9S08PB8MTG MCU from NXP Semiconductors. From the MC9S08PB8MTG datasheet.
STMicroelectronics, STM32 Series
The STM32 Series from STMicroelectronics is one of the most popular lines of MCUs used in embedded products requiring moderate processing power and high bus width. These devices operate up to 72 MHz (Arm Cortex-M4 core) with 32-bit bus width. They also feature high resolution ADC (12-bit) and a range of digital interfaces (CAN, I2C, I2S, IrDA, LIN, SPI, UART, USART, USB) with high I/O count.
Texas Instruments, MSP430
The MSP430 family of MCUs from Texas Instruments is a range of 16-bit MCUs that come in a variety of packages and include an analog comparator. These MCUs run up to 25 MHz and include features like integrated SRAM/FRAM, Flash memory, ADC, SPI/UART, and other interfaces and features.
Functional block diagram for the MSP430FR5727 MCU from Texas Instruments. From the MSP430FR5727 datasheet.
Other Components to Support Your Mixed Signal Designs
Your MCU should be the starting point for a mixed signal design as it will need to interface with all other digital and analog components in your system. Some other components your system will need include:
- Passives for supporting circuitry
- Display modules for HMI
- DC-DC converters for power regulation
- Wireless and networking components
When you need to select an MCU or other processor with an integrated analog comparator, you can find all the parts you need with the advanced search and filtration features in Octopart. When you use Octopart’s electronics search engine, you’ll have access to a complete set of distributor data and parts specifications, and it’s all freely accessible in a user-friendly interface. Take a look at our embedded processor and controllers page to find the components you need.