Problems with DT interrupts (PT_INT interrupt)
Hello everyone :smile:
I'm trying to use Instant Interrupts with the PT_INT interrupt (PWM time base) in my code.
I'm using a 18F2431 with a 40MHz clock frequency. My PWM interrupt frequency is about 15kHz (PTPER=333).
With a code like that (with no interrupt, just waiting the PIR3.4 flag in a loop), it works very well :
Code:
DEFINE OSC 40
' PCPWM registers configuration
PTCON0=%00000010
PTCON1=%10000000
PWMCON0=%01000000
PWMCON1=%00000001
DTCON=%00110110
PTPERH=$1:PTPERL=$4d
' PWM ISR
pwmint:
' Wait PIR3 interrupt
while PIR3.4=%0
wend
PIR3.4=%0
.
.
.
(there is my PWM code)
.
.
.
GOTO pwmint
However, this code below should give me the same results and execute my PWM ISR at each PWM pulse, but it doesn't work :
Code:
DEFINE OSC 40
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
' PCPWM registers configuration
PTCON0=%00000010
PTCON1=%10000000
PWMCON0=%01000000
PWMCON1=%00000001
DTCON=%00110110
PTPERH=$1:PTPERL=$4d
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler PT_INT, _pwmint, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE PT_INT
' PWM ISR
pwmint:
' Wait PIR3 interrupt
PIR3.4=%0
.
.
.
(there is my PWM code)
.
.
.
@ INT_RETURN
I need help :) thanks
Re: Problems with DT interrupts (PT_INT interrupt)
Hey, you don't have any loop in you code.
Code:
DEFINE OSC 40
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
' PCPWM registers configuration
PTCON0=%00000010
PTCON1=%10000000
PWMCON0=%01000000
PWMCON1=%00000001
DTCON=%00110110
PTPERH=$1:PTPERL=$4d
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler PT_INT, _pwmint, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE PT_INT
Main:
GOTO Main
' PWM ISR
pwmint:
' Wait PIR3 interrupt
PIR3.4=%0
.
.
.
(there is my PWM code)
.
.
.
@ INT_RETURN
With this code, you stay in main, and wait for interrupt. When interrupt fire PC will jump to to pwmint. And with INT_RETURN you return to main.
Without Main loop, PIC execute every instruction, and when execute INT_RETURN processor reset PIC(reset on stack underflow).
Re: Problems with DT interrupts (PT_INT interrupt)
Thanks a lot Pedja!
I didn't know that a main loop was mandatory in order to execute an interrupt ;)
Re: Problems with DT interrupts (PT_INT interrupt)
However what's that "reset flag"?
Do I need to clear myself the PIR3.4 flag?
Re: Problems with DT interrupts (PT_INT interrupt)
Hi,
When you tell DT-INTS to clear the flag (by setting the reset flag option to YES) you don't need to clear it manually in the ISR. If you set the option to NO then DT-INTS will leave the flag alone and its up to you (or the hardware) to handle it the flag as needed.
/Henrik.
Re: Problems with DT interrupts (PT_INT interrupt)
Thanks Henrik :)
I will let the DT-INTS clear the flag, I think it's more "efficient" than clear the flag manually...
Re: Problems with DT interrupts (PT_INT interrupt)
Re: Problems with DT interrupts (PT_INT interrupt)
Quote:
Originally Posted by
Demon
Nevermind...
Last edited by Demon; Today at 12:37. Reason: dummy at keyboard
Robert
I'm glad someone else feels the same way I do when I try to answer things!
Re: Problems with DT interrupts (PT_INT interrupt)
I had quoted Pedja thinking I had selected the OP and saw nothing wrong with the Main routine.
Robert
:D