| PIC PRESS HELP |
Time Delay Macro |
The Time Delay Macro creates code which produces time delays, either using TMR0, or just by counting clock cycles. Effectively, you tell the macro how long you want the delay to last, and the correct code is inserted into your program. When you click on the Time Delay Macro button, the following window appears:
Time Delay Settings
- Clock Speed This is set by you in the Project Information Form which appeared when you first started the program.
- TMR0 Prescaler This again is set by you using the OPTION register. It is only significant if you are using the TMR0 for the delay. It indicates by how much the TMR0 is slowed down. You should have set a prescaler value in the Init subroutine, when first prompted by the SFR Configuration Form. In either case, the macro assumes the prescaler value which you have entered here is in agreement with the value entered in the program. If you don't understand prescaling, the best advice is to exit this form and use the number-into-SFR macro to configure the OPTION register such that the TMR0 is prescaled by 256, and then execute this Time Delay Macro, setting the prescaler to 256.
- Delay Length You can enter the required delay length in seconds, or in clock cycles. Using clock cycles is really only useful when you are using really, really short delays, otherwise it is simplest to use seconds.
- Actual Length The way the time delays operate, the exact time you require may not be obtained exactly. The error is usually very small indeed, and you can overcome descrepancies of a number of clock cycles by introducing a few nop instructions, which waste a clock cycle each.
- Name of Delay The macro will use a subroutine to store bulk of the time delay code. You can choose the name it will call this subroutine her.
- Wait Until Delay Has Elapsed Before Returning You can either ask the macro to create a simple delay (i.e. kill time), in which case this box should be checked. Alternatively, you might simply want to see if the relevant amount of time has elapsed, returning from the subroutine if it hasn't, and continuing in the subroutine if it has. This way you can get along with other tasks while testing to see if a certain amount of time has passed. For this option the box should be unchecked - but note this option requires the use of the TMR0.
- Use TMR0 for Increased Accuracy If you have selected a simple delay (i.e. waiting until the delay has elapsed befor returning), you have the choice of using the TMR0, or simply counting clock cycles. Counting clock cycles frees up the TMR0 for other tasks (e.g. counting pulses on the T0CKI pin), however using the TMR0 can be more accurate if interrupts might take place during the delay.
Back to PIC PRESS Features
Copyright ©2006 Perfect Square Ltd.