Zibb

Design Idea

Perform timing for microcontrollers without using timers

Use the I/O "interrupt-on-change" feature to implement a medium-precision, long-period timer with low additional cost.

Ganeshkumar Krishnamoorthy, NTERA Ltd, Dublin, Ireland; Edited by Martin Rowe and Fran Granville -- EDN, 1/22/2009

Microcontrollers now find use in every walk of life. Their peripherals vary from the general-purpose I/Os to the USB interface, making them versatile for a range of products. Timing is one key part of a typical microcontroller application. Low-cost microcontrollers have one or two built-in timers and often also have a watchdog timer. Sometimes, the design requires more timers without a significant cost increase. Software timers are not suitable for time-critical application because the controller is fully occupied. The circuit in this Design Idea uses the I/O “interrupt-on-change” feature that is common in most microcontrollers to implement a medium-precision, long-period timer with low additional cost.

The circuit in Figure 1 uses I/O1, a typical I/O pin, to drive an RC filter. The circuit feeds the output of the RC filter to a Schmitt-trigger inverter whose output goes back to I/O2, which has the interrupt-on-change feature. After power-up, I/O1 is low and the output of the Schmitt-trigger inverter is high. After initialization, I/O1 goes high. Capacitor C1 charges up with the time constant R1C1. Once it reaches logic-high voltage, the output of the Schmitt-trigger inverter goes low and triggers an interrupt on I/O2. In the ISR (interrupt-service routine), a counter increments, driving I/O1 low. Now, C1 discharges through R1. The voltage reaches logic low, again triggering an interrupt. As the cycle repeats, the value in the counter indicates time=counter×R1C1. The Schmitt-trigger inverter serves as a debouncer.

See all of EDN's
Design Ideas

Listing 1 includes the software routine for the ATMEGA64 microcontroller from Atmel. In the listing, Port D, Pin 5 plays the role of I/O1 and Pin 3, whose alternate function is INT3, plays the role of I/O2 in Figure 1. The trigger-edge interrupt in this case changes from falling-rising-falling edge in a cycle. Most microcontrollers don’t require this feature because any logic change will trigger an interrupt. Figure 2 shows the timing waveform of the circuit with the ATMEGA64 and the 74HC14.

The circuit’s advantages are its low cost, a microcontroller-clock-independent time period, and the ability to achieve time periods of minutes to hours by tuning resistance and capacitance. For example, with a resistance of 10 MΩ, a capacitance of 10 µF, and a 16-bit register as a counter, you can achieve a maximum count of 75.85 days.

Acknowledgment

This work is part of a system design in a project funded by the European Union under the Marie Curie Project.



Reed Business Information Resource Center

Featured Company


Related Resources

ADVERTISEMENT

ADVERTISEMENT

Related Content

 

By This Author

There are no additional articles written by this author.


ADVERTISEMENT

Knowledge Center


Events

Microchip Worldwide Embedded Designer’s Forum
Dates: 10/6/2009 - 2/15/2010
Location: 120 Locations Worldwide

Microprocessor Test and Verification (MTV'09)
Dates: 12/7/2009 - 12/8/2009
Location: Austin, TX

Oxford University Digital Signal Processing Short Course
Dates: 1/25/2010 - 1/27/2010
Location: Oxford, United Kingdom

Oxford University Digital Signal Processing Implementation Short Course
Dates: 1/28/2010 - 1/28/2010
Location: Oxford, United Kingdom

Oxford University High-Speed Digital Design Short Course
Dates: 6/22/2010 - 6/23/2010
Location: Oxford, United Kingdom

Submit an EventSubmit an Event




Technology Quick Links

EDN Marketplace


©1997-2009 Reed Business Information, a division of Reed Elsevier Inc. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other Reed Business sites