Hi, > Well, this approach is fine for occasions when a time "granularity" of > 18.2Hz suits, but often a millisecond or finer resolution is needed. > There is still a proper way to do this in a completely processor- > independent fashion and it is rather easy. The timer which produces the > 18.2Hz interrupt IS readable, albeit with some difficulty on later > silicon (I DO invite anyone who has a good explanation of this problem > to contribute here! I understand it IS fixable). > > Timing is implemented by reading the timer value, calculating a > "compare" value and proceeding to loop reading the timer and comparing > it until the target is reached or exceeded (overflow considerations > apply). With certain limitations, other tasks such as checking for > keypresses, even asynchronous (i.e., other than isosynchronous) tasks > can be performed within the loop. > > We are talking about writing programming algorithms for PICs, aren't > we? This would be the obvious way to go about it. Of course, it is > unlikely this will work properly with Windoze but then, no software > approach will. An interesting hardware approach involves using a spare > serial port and interrupt (with buffers disabled) as a programmable > interrupt timer. Subverting the main clock "tick" timer interrupt a la > GWBASIC or certain games is NOT recommended and under Windoze, not > possible. > The PC contains three programmable timers (8254's). Timer 0 is used to generate the timer interrupt as mentioned above. By default it is programmed with a maximum divisor. This can easily be changed to cause interrupts at faster rates. This can be very useful if you need to have a part of your program execute at a known rate (like a digital control algorithm). It is also useful to generate medium to long delay periods that need to be consistent when run on various PC's (like time-outs). Short delay periods ( <1ms ), is best done (as discussed above) by reading back the timer value. You would set the timer to a calculated start value, and then read it back until it reaches 0 or wraps around. This is best done with timer 2. Timer 2 is a general purpose timer that can be used to drive the speaker as well. It is not connected to an interrupt line, so it cannot generate an interrupt like timer 0. Reading back the timer value is not difficult. Another interesting delay technique on the PC, is to 'calibrate' a particular software loop at the beginning of the program using one of the timers (adjust the loop counter until the loop gives about the right delay period). I have used all of the above techniques (under DOS) and they work very well. If you need code or more info, mail me privately - I think we have strayed a bit far from PIC's here! Regards, Niki