Of course I'm using DT-INTS_18. Above is the sample code provided by Darrel.
I've misreaded this line : "The frequency will remain constant and cannot be changed during Run-Time." F*ck.
You tell me to stop the timer, make a copy, and restart it. Only the "Timer1" variable can be changed in this DT's routine. Some routines are already made on this program : "StartTimer" and "StopTimer".
I'm sorry, but I'd like you modify my program, because I'm completly stuck at this point so many days... 
The only thing I want is control the TMR1 interrupt frequency precisely, even in runtime.
I've tried
Code:
TimerShadow VAR WORD
TimerShadow=5000
.
.
.
StartTimer:
Timer1=TimerReload+TimerShadow
TMR1ON=1
RETURN
But of course it didn't works.
I've also modified the code assuming your tips :
Code:
' PIC initialization
DEFINE OSC 40
DEFINE LCD_DREG PORTC
DEFINE LCD_EREG PORTD
DEFINE LCD_RSREG PORTD
DEFINE LCD_EBIT 0
DEFINE LCD_RSBIT 1
DEFINE LCD_COMMANDUS 4000
DEFINE LCD_DATAUS 1000
' BAS includes
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "Sine_table.bas"
' Port registers configuration
TRISB=%11000000 ' PWM 0,1,2,3,4,5 outputs
TRISC=%00110000 ' +/- buttons
' PCPWM registers configuration
DTCON=%110 ' Deadtime (600ns)
PTCON0=%0 ' 1:1 postscale, Fosc/4 1:1 prescale, free running mode
PTCON1=%10000000 ' PWM time base is ON, counts up, 19.45kHz/4
PWMCON0=%1000000 ' PWM 0,1,2,3,4,5 set in pair mode
PWMCON1=%1 ' PWM timer sync configuration
' PWM calculation variables
ustep var byte
vstep var byte
wstep var byte
uduty var word
vduty var word
wduty var word
frequency var word
amplitude var word
carrier VAR word
flag var bit
' Variables definition
ustep=90 ' 360 degrees phase angle
vstep=60 ' 240 degrees phase angle
wstep=30 ' 120 degrees phase angle
frequency=1200 ' Frequency adjust
amplitude=65535 ' Sinewave amplitude adjust (65535=max amplitude)
carrier=1023 ' Carrier frequency adjust (1023=13kHz)
flag=%0 ' Menu flag
' PWM carrier frequency register configuration
PTPERL=carrier.lowbyte
PTPERH=carrier.highbyte
' Interrupt processors
ASM
INT_LIST macro
INT_Handler TMR1_INT,ReloadTMR1,ASM,no
INT_Handler TMR1_INT,_pwmint,PBP,yes
endm
INT_CREATE
ENDASM
' Timers configuration
@Freq=4050
@Prescaler=1
T1CON=$00
' Interrupts enable
@INT_ENABLE TMR1_INT
GOSUB StartTimer
' Main program loop
mainlp:
' Debug display
if flag=0 then
LCDOUT $FE,$2,"Freq. adjust :"
LCDOUT $FE,$C0, DEC frequency
if PORTC.4=1 then frequency=frequency-1
if PORTC.5=1 then frequency=frequency+1
IF PORTC.4 AND PORTC.5=1 then flag=%1
else
LCDOUT $FE,$2,"Amp. adjust :"
LCDOUT $FE,$C0,DEC4 amplitude
if PORTC.4=1 then amplitude=amplitude-1
if PORTC.5=1 then amplitude=amplitude+1
endif
goto mainlp
' PWM calculation and update interrupt (Timer 1)
pwmint:
' PWM U phase calculation
uduty=sine[ustep]
uduty=uduty<<4**amplitude
' PWM V phase calculation
vduty=sine[vstep]
vduty=vduty<<4**amplitude
' PWM W phase calculation
wduty=sine[wstep]
wduty=wduty<<4**amplitude
' PWM U, V and W update
PDC0L=uduty.lowbyte
PDC0H=uduty.highbyte
PDC1L=vduty.lowbyte
PDC1H=vduty.highbyte
PDC2L=wduty.lowbyte
PDC2H=wduty.highbyte
' Phase angle calculation
ustep=ustep-1
vstep=vstep-1
wstep=wstep-1
' Phase angle reinitialization
if ustep=0 then ustep=90
if vstep=0 then vstep=90
if wstep=0 then wstep=90
@INT_RETURN
' Timer1 interrupt handler
ASM
ReloadInst=8
MaxCount=65536+(ReloadInst/Prescaler)
TimerReload=MaxCount-(OSC*1000000/4/Prescaler/Freq)
ENDASM
' Timer1 variables
@Timer1=TMR1L
Timer1 VAR WORD EXT
TimerReload CON EXT
TMR1ON VAR T1CON.0
' Timer1 reload
ASM
ReloadTMR1
MOVE?CT 0,T1CON,TMR1ON
MOVLW LOW(TimerReload)
ADDWF TMR1L,F
BTFSC STATUS,C
INCF TMR1H,F
MOVLW HIGH(TimerReload)
ADDWF TMR1H,F
MOVE?CT 1,T1CON,TMR1ON
INT_RETURN
ENDASM
' Timer1 start/stop control
StartTimer:
Timer1=TimerReload
TMR1ON=1
RETURN
StopTimer:
TMR1ON=0
RETURN
Also, this afternoon, I will modify the ISR and replace it with TOGGLE PORTB.0, to measure interrupt frequency. I'll give you results.
Bookmarks