1) A timer could be used as a source for the 400Hz(2250us)-1500Hz(667us) timing. This would certainly be best with interrupts. The unavoidable latency involved could be dealt with by adjusting the value loaded into the timer by an offset.
As a primer, have a look at Darrel Taylor's Instant Interrupts. It's a long thread, but the key stuff is in the first 8 posts, and also on his web site. Also, he has a little calculator to help come up with the values to add to the timer registers. This sould help to get the 400-1500Hz timing sorted out.
2) If you want to get an accurate 2us pause (only 20 instruction at 40 Mhz) between pulses, you are not likely to do this with timers and interrupts, and still have an accuracy of .25us, and get anything else accomplished. It would take most of 20 instructions cylcles just to vector to the interrupt routine, save context, toggle a pin, restore context, and return to the code (the 18F does have some context saving features that help here, but not that much).
So, use the interrupts to trigger the start of the pulse string, then control the pulse width/timing actively using PBP or ASM routines. Worst case you would have a 350us interruption in you main code to send out the pulse string followed by about 317us for the main code to run before the next interrupt. Not ideal, but consider that 317us is 3170 instruction cycles, and a fair bit can be accomplised it that time. Also, as the freqency decreases, much more time becomes available between interrupts.
SteveB
Bookmarks