OK, I can see the difficulty there.
5 uS isn't much to work with.
I have been able to get your program from the other thread to work with just a few changes.
By setting PR2 to 39, TMR2 doesn't have to be reloaded on each interrupt, saving 2 instructions.
A TMR2 = PR2 match will reset the timer value and trigger the interrupt.
The actual period is PR2+1 (40 instructions).
The TOGGLE EN1 can be replaced with LATF = LATF ^ 1 which saves another 2 instructions because TOGGLE also sets the TRIS bit to output everytime.
So after setting PR2 in your initialization ...
Code:
PR2 = 39 ; set TMR2 period to 5 uS
The interrupt handler looks like this ...
Code:
'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
LATF = LATF ^ 1 ; TOGGLE EN1
CNT =CNT+1
LATC = PORTA
@ INT_RETURN
There's still a couple instruction cycles left ... but to answer your original question, you can get a few more cycles back with straight ASM handlers.
_________________________ _____________________________
To do that, let's take the same handler and remove DT_INTS.
DEFINE the ISR's routine (_FiveMicroSec).
Set the TMR2IE, PEIE and GIE bits.
Clear the INT flag at the end.
And instead of @ INT_RETURN ... use @ RETFIE.
Code:
PR2 = 39
PIE1.1 = 1 ; Enable Timer2 interrupts
INTCON.6 = 1 ; enable PEIE
INTCON.7 = 1 ; enable GIE
T2CON = %00000100 ; Start Timer2
DEFINE INTHAND _FiveMicroSec
'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
LATF = LATF ^ 1 ; TOGGLE EN1
CNT =CNT+1
PORTC = PORTA
PIR1.1 = 0 ; clear the interrupt flag
@ RETFIE
That should give another 20 instruction cycles.
Don't go crazy in the ISR.
You can only use PBP statements that DO NOT change PBP's system variables.
___________________________ _________________________________
On a different note ... You shouldn't use LATx.x with HIGH, LOW, TOGGLE or any other PBP commands.
Direct assignments to LATx are OK, but when PBP tries to set the tris bit, referenced to the LAT bit, it overwrites the wrong registers.
PBP commands that accept Pins, only work properly with PORTx.x, not LATx.x.
HTH,
Bookmarks