sirvo> OR, increase timer1 interrupt and decrease the number of the sine table points..
Actually, I was thinking you should have a larger table at a faster rate. 
But it'll take a few changes.
Here's a couple things that will help speed things up.
First, change the interrupt TYPE for TMR1_INT to ASM.
The handler only set's the flag and loads the timer, so it doesn't need to save all the PBP system registers. This should save about 40us.<hr>
Then if the SAG() values ranged from 0-255 instead of 0-100, this could replace what you had ...
Code:
va = v */ (255-sag[0]+1)
It will save 75us each time, which brings the whole loop down to 220us. Just barely under the Timer1_INT period. But if you want to add more features, or increase the sin table, there won't be any time left.
<hr>
Going a bit further, here's a little asm routine that'll really help.
It Scales an 8-bit value to another 8-bit value.
Essentially it does Result=Value*(Scale+1), with the actual result being in the HighByte of the R2 variable.
With this you can do ...
Code:
; va = (v*(100-sag[0]))/100
R0 = V ; Put the value in R0
R1 = 255-SAG[0] ; Inverted SAG to R1
CALL Scale8 ; Scale R0*(R1+1)
VA = R2.HighByte ; result is in R2.HighByte
Here's the ASM part. Put it somewhere above the Main loop.
Code:
ASM ; ---- [Scale8 - Scale an 8-bit value]----------
; Input: R0 = Value to scale |
; R1 = Scale (0-255) |
; Output: R2 = R0*(R1+1) |
; Result is in R2.HighByte |
;---------------------------------------------------
goto OverScale8
_Scale8
clrf R2 ; result LowWord
clrf R2 + 1 ; result HighWord
movlw 8
movwf R3 ; Loop counter
movf R1, W ; Load Scale in W reg
bcf STATUS, C ; clear carry
Scale8Loop
rrf R0, F ; Rotate the Value, lsb goes to carry
btfsc STATUS, C ; if the carry = 1 then
addwf R2 + 1, F ; add Scale to result.highbyte
rrf R2 + 1, F ; rotate the result.highbyte, lsb goes to carry
rrf R2, F ; rotate carry into result.lowbyte
decfsz R3, F ; next loop
goto Scale8Loop
addwf R2, F ; add 1 more Scale
btfsc STATUS, C ; if carry
incf R2 + 1, F ; inc highbyte
return
;----[Macro to make things easier]------------------
Scale8 macro Value, Scale, Bout
MOVE?BB Value, R0
MOVE?BB Scale, R1
L?CALL _Scale8
MOVE?BB R2 + 1, Bout
endm
OverScale8
ENDASM ; ---- [End of Scale8]-----------------------
Using the above code, each call to Scale8 takes about 18us or 54us for all three. With 70us for the rest, it ends up doing the whole thing in about 125us. Well within the 230us periods. And time left over for a bigger/faster table.
I'm not using the macro at this point. It's just there for future reference.
Just remember ... SAG is 0-255 now. So if you need to convert it...
Code:
SAG(0) = SAG0value*255/100
Which is much like what you had in the beginning. But now it's only done when setting the SAG values, instead of 12000 times a second.
HTH,
Bookmarks