DSP, Micros & Memory


Microcontroller comparators: method of faster code for detecting change

20 October 2004 DSP, Micros & Memory News & Events

In this 'Tips 'n Tricks' article from Microchip Technologies, the company describes a method of structuring faster code for detecting change.

When using a comparator to monitor a sensor, it is often just as important to know when a change occurs as it is to know what the change is. To detect a change in the output of a comparator, the traditional method has been to store a copy of the output and periodically compare the held value to the actual output to determine the change. An example of this type of routine is shown in Figure 1.

Figure 1. Routine 1
Figure 1. Routine 1

This routine requires five instructions for each test; nine instructions if a change occurs and one RAM location for storage of the old output state. A faster method for microcontrollers with a single comparator is to use the comparator interrupt-flag to determine when a change has occurred.

Routine 2 (Figure 2) requires two instructions for each test; three instructions if a change occurs and no RAM storage. If the interrupt flag cannot be used or if two comparators share an interrupt flag, an alternate method that uses the comparator output polarity bit can be used.

Figure 2. Routine 2
Figure 2. Routine 2

Routine 3 (Figure 3) requires two instructions for each test; five instructions if a change occurs and no GPR storage.

Figure 3. Routine 3
Figure 3. Routine 3



Credit(s)



Share this article:
Share via emailShare via LinkedInPrint this page

Further reading:

EMC limits and levels
Altron Arrow Editor's Choice Circuit & System Protection
As soon as electronics and electrical systems started interfering with each other, the world had to come to some consensus. Considering physics is universal and does not care about what country electrical/electronic products are used in, it should be the same everywhere, right? It is nearly there, but not quite.

Read more...
Introducing STM32CubeMX2
Altron Arrow Design Automation
STMicroelectronics has launched STM32CubeMX2, a new evolution of its popular configuration and code generation tool for STM32 microcontrollers.

Read more...
Next-gen SPE
Altron Arrow Telecoms, Datacoms, Wireless, IoT
Next-generation 100/1000BASE-T1 Single Pair Ethernet PHYs integrate MACsec security, time sensitive networking, and functional safety.

Read more...
Industrial vibration sensing simplified
Altron Arrow Analogue, Mixed Signal, LSI
The IIS3DWBG1 from STMicroelectronics is a high performance, three-axis digital vibration sensor engineered for demanding industrial applications where accurate motion monitoring is essential.

Read more...
ESP32-S31 for advanced IoT
iCorp Technologies DSP, Micros & Memory
At the heart of the device is a dual-core 32-bit RISC-V MCU operating at up to 320 MHz, delivering 6,86 CoreMark/MHz performance with MMU support for efficient memory management.

Read more...
Cortex-M33 performance for cost-sensitive designs
Future Electronics DSP, Micros & Memory
The STM32C5 series from STMicroelectronics introduces a new generation of entry-level microcontrollers engineered to deliver enhanced processing capability, modern security, and cost-effective scalability for connected embedded applications.

Read more...
Global security in 2026
Editor's Choice News & Events Security Services & Risk Management Industrial (Industry) Mining (Industry)
The World Security Report 2026 states: “In a world of increasing volatility, physical security has evolved. It is no longer just a defensive measure; it is a critical driver of corporate value.”

Read more...
Memory shortage 2026: Engineering implications for South Africa
DSP, Micros & Memory
[Sponsored] Addressing this challenge requires system-level thinking and adoption with McKinsey Electronics providing the engineering and sourcing framework required to maintain system resilience despite ongoing global constraints.

Read more...
IQSight SmartSuite integration with XProtect
Surveillance News & Events AI & Data Analytics
Milestone Systems and IQSight have strengthened their collaboration with the release of SmartSuite, a consolidated plug-in suite for Milestone XProtect video management software, to cut installation time for system integrators by 70%.

Read more...
Cost-effective microcontroller series
Altron Arrow DSP, Micros & Memory
The STM32C5 series from STMicroelectronics delivers an excellent balance of performance, efficiency, and affordability for embedded designs that require more capability without increasing bill of materials cost.

Read more...









While every effort has been made to ensure the accuracy of the information contained herein, the publisher and its agents cannot be held responsible for any errors contained, or any loss incurred as a result. Articles published do not necessarily reflect the views of the publishers. The editor reserves the right to alter or cut copy. Articles submitted are deemed to have been cleared for publication. Advertisements and company contact details are published as provided by the advertiser. Technews Publishing (Pty) Ltd cannot be held responsible for the accuracy or veracity of supplied material.




© Technews Publishing (Pty) Ltd | All Rights Reserved