Subscribe to EDN
RSS
Reprints/License
Print
Email

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, January 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.

RSS
Reprints/License
Print
Email
Canon Resource Center

Featured Company


Most Recent Resources

Advertisement
Related Content

No related content found.

  • 0 rated items found.
Advertisement

KNOWLEDGE CENTER

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
Featured Job On
Scroll for More Jobs
Advertisement
About EDN   |   Site Map   |   Contact Us   |   Subscription   |   RSS
© 2012 UBM Electronics. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other UBM Canon sites

UBM Canon | Design News | Test & Measurement World | Packaging Digest | EDN | Qmed | Pharmalive | Appliance Magazine | Plastics Today | Powder Bulk Solids | Canon Trade Shows