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:

Highest increase in global cyberattacks in two years
Information Security News & Events
Check Point Global Research released new data on Q2 2024 cyber-attack trends, noting a 30% global increase in Q2 2024, with Africa experiencing the highest average weekly per organisation.

Read more...
From QR code to compromise
Information Security News & Events
A new attack vector involves threat actors using fraudulent QR codes emailed in PDF attachments to bypass companies' phishing security measures by requiring users to scan the code with their mobile phones.

Read more...
Here’s to a SMART 2025
SMART Security Solutions Editor's Choice News & Events
This is the final news brief from SMART Security Solutions for 2024, and the teams would like to take this opportunity to thank our readers, advertisers and partners and wish everyone a safe and secure festive season.

Read more...
Organisations fear AI-driven cyberattacks, but lack key defences
Kaspersky Information Security News & Events Training & Education
A recent Kaspersky study reveals that businesses are increasingly worried about the growing use of artificial intelligence in cyberattacks, with 56% of surveyed companies in South Africa reporting a rise in cyber incidents over the past year.

Read more...
Ryzen-based computer on module
Altron Arrow AI & ML
SolidRun announced the launch of its new Ryzen V3000 CX7 Com module, configurable with the eight-core/16-thread Ryzen Embedded V3C48 processor.

Read more...
QuecPython live demonstration
Quectel Wireless Solutions DSP, Micros & Memory
QuecPython allows designers to adapt Quectel’s modules quickly, with a low-code approach to suit their precise requirements in less time and at reduced cost, while maintaining high security standards.

Read more...
Robust and customisable SBC
Altron Arrow DSP, Micros & Memory
Pairing the powerful i.MX8M Plus System on Module (SoM) from SolidRun, which features the i.MX 8M Plus SoC from NXP, this high-performance SBC is set to transform industrial environments.

Read more...
New family supports future cryptography
Altron Arrow DSP, Micros & Memory
NXP has introduced its new i.MX 94 family, which contains an i.MX MPU with an integrated time-sensitive networking (TSN) switch, enabling configurable, secure communications with rich protocol support in industrial and automotive environments.

Read more...
Fast and reliable 4G connectivity worldwide
TRX Electronics DSP, Micros & Memory
Powered by a powerful Quectel LTE Cat 4 modem, the Arduino Pro 4G module’s fast data throughput and high bandwidths ensure reliable and quick data download and upload, even in remote locations.

Read more...
NXP’s all-purpose microcontroller series
Altron Arrow DSP, Micros & Memory
NXP has released its MCX A14x and A15x series of all-purpose microcontrollers which are part of the larger MCX portfolio that shares a common Arm Cortex-M33 core platform.

Read more...