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:

Analysis of switch-mode power supply: inductor violations
Altron Arrow Editor's Choice Power Electronics / Power Management
Common switch-mode power supply (SMPS) design errors are discussed, and their appropriate rectification is specified, with details on complications that arise with the power stage design of DC-DC switching regulators.

Read more...
Microsoft Windows IoT on ARM
Altron Arrow Computer/Embedded Technology
This expansion means that the Windows IoT ecosystem can now harness the power of ARM processors, known for their energy efficiency and versatility.

Read more...
The 8-bit survival syndrome – Part 2
DSP, Micros & Memory
Just like the 4-bit pre-microcontroller, the 8-bit MCU has been finding ways to stick around. Their features and speeds have been improving, offering competitive reasons to work with them.

Read more...
Accelerating the commercialisation of the 5G IoT markets
Altron Arrow Editor's Choice Telecoms, Datacoms, Wireless, IoT
Fibocom unveils Non-Terrestrial Networks (NTN) module MA510-GL, enabling satellite and cellular connectivity to IoT applications.

Read more...
Microchip introduces ECC608 TrustMANAGER
Altron Arrow Circuit & System Protection
To increase security on IoT products and facilitate easier setup and management, Microchip Technology has added the ECC608 TrustMANAGER with Kudelski IoT keySTREAM, Software as a Service (SaaS) to its Trust Platform portfolio of devices, services and tools.

Read more...
Enhanced code protection for USB µC portfolio
Future Electronics DSP, Micros & Memory
To help easily incorporate USB power and communication functionality into embedded systems, Microchip Technology has launched the AVR DU family of microcontrollers.

Read more...
General-purpose MCU with RISC-V architecture
EBV Electrolink DSP, Micros & Memory
Renesas has released a general-purpose MCU to enhance its existing RISC-V portfolio, and this is its first MCU using a RISC-V core developed internally at the company.

Read more...
8-bit MCU with I3C support
Avnet Silica DSP, Micros & Memory
The PIC18-Q20 8-bit microcontrollers from Microchip easily interface with devices operating in multiple voltage domains, and the built-in I3C interface supports higher-speed and lower-power data transfers than I2C.

Read more...
xG26 sets new standard in multiprotocol wireless device performance
Altron Arrow AI & ML
Silicon Labs has announced its new xG26 family of Wireless SoCs and MCUs, which consists of the multiprotocol MG26 SoC, the Bluetooth LE BG26 SoC, and the PG26 MCU.

Read more...
SolidRun unveils new SoM
Altron Arrow AI & ML
SolidRun and Hailo has unveiled a game-changer for engineers and AI product developers with the launch of their market-ready SoM, which packs the cutting-edge capabilities of the Hailo-15H SoC.

Read more...