I think this is what Mike was talking about?
This will give you 2.5MHz with every 16th logic 1 bit stretched to 4 cycles VS 1. If you can live with this bit being a tad longer, it will definitely speed things up.
Code:
' define port & pin use in _Pulse
@ #DEFINE PORT PORTB ' use any port you prefer, but declare it here
@ #DEFINE PIN 6 ' same as above
PORTB.6 = 1 ' initialize pin to idle state
TRISB.6 = 0 ' make the pin an output
C1 VAR BYTE BANK0 SYSTEM
Main:
C1 = 0 ' clear loop count
CALL Pulse ' generate 4096 pulses
GOTO Main
ASM
_Pulse
BCF PORT,PIN ; clear pin / 1
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 2
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 3
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 4
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 5
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 6
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 7
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 8
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 9
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 10
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 11
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 12
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 13
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 14
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 15
BSF PORT,PIN ; set pin
BCF PORT,PIN ; clear pin / 16
BSF PORT,PIN ; set pin
DECFSZ C1,F ; decrement count, skip if 0
GOTO _Pulse ; not done, keep going
RETURN
ENDASM
With either version, make sure you have WDT disabled.
Bookmarks