40 cycles @ 2us per cycle = 80us. 1/80us = 12.5Khz
But then you have to add the extra few cycles that pulsout uses to set the TRIS register for the pin and set and reset the logic level for that pin. AND you have to add in the 2 cycles it takes to GOTO the beginning of the loop. Not to mention any WDT clearing instructions and/or any PBP 'ON INTERRUPT' handling instructions stuffed in there. Those extra instructions are probably slowing the loop down to 7.5Khz.
Add:
DEFINE NO_CLEARWDT 1
to the top of your program whether you are using the WDT or not (but turn it off in the CONFIGs just in case)
Also, add a
DISABLE
to take care of any PBP 'ON INTERRUPT' handling around that tight loop.
That should speed up the loop a bit.
But, IMO, using pulsout is just a bad way to get a train of pulses @ 100Khz because, for one thing, the duty cycle won't be constant, especially if you're doing anything else in the program.
You might want to try to use some of the 'Instant Interrupts' and TMR0 with a high reload value (don't know what that value would be off the top of my head, maybe 232 with 1:1 prescale), then each time the interrupt fires, toggle the state of the pin.
http://www.mister-e.org/pages/utilitiespag.html





Bookmarks