Subscribe to EDN
RSS
Reprints/License
Print
Email

Pacer clock saves subroutine calls

Time-delay routine requires no subroutine calls, avoids stack-overflow hazards.

Enver Torlakovic, Willmot, New South Wales, Australia; Edited by Brad Thompson and Fran Granville -- EDN, November 10, 2005

This Design Idea outlines an easy-to-implement time-delay routine that requires no subroutine calls and thus avoids possible stack-overflow problems (Listing 1). This method also saves RAM space by requiring in most cases only two variables: the PACER_CLOCK as a free-running counter and another variable introduced at a particular instance (for example, TIME_VAR). The routine dedicates the microcontroller's Timer 0 to generate an interrupt-on-overflow instruction every 10 msec or at any other desired interval. You assign the Timer 0 interrupt a low priority in the initialization code and then enable the Timer 0 any convenient time. After assignment, do not alter the interval because many services likely depend on the pacer-clock routine. Note that the routine can achieve delays of as much as 255 times the Timer 0 overflow period.

Listing 1 is written for Microchip's PIC18F242 flash-memory controller, but porting the routine to another microcontroller should pose few problems. When copying the code to paste it into routines, note that you must change the labels—in this example, "wait_ loop100"—at each application of the code between the rows of asterisks in the listing.

Click here for more Design Ideas!

 

RSS
Reprints/License
Print
Email
Talkback
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)
Engineering Careers
Jobs sponsored by
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