PDA

View Full Version : Problems with DT interrupts (PT_INT interrupt)



pxidr84
- 8th October 2014, 09:27
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 :


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 :


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

pedja089
- 8th October 2014, 10:08
Hey, you don't have any loop in you 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).

pxidr84
- 8th October 2014, 10:43
Thanks a lot Pedja!

I didn't know that a main loop was mandatory in order to execute an interrupt ;)

pxidr84
- 8th October 2014, 10:45
However what's that "reset flag"?

Do I need to clear myself the PIR3.4 flag?

HenrikOlsson
- 8th October 2014, 10:59
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.

pxidr84
- 8th October 2014, 11:12
Thanks Henrik :)

I will let the DT-INTS clear the flag, I think it's more "efficient" than clear the flag manually...

Demon
- 8th October 2014, 18:31
Nevermind...

Robert

andywpg
- 8th October 2014, 19:49
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!

Demon
- 8th October 2014, 22:22
I had quoted Pedja thinking I had selected the OP and saw nothing wrong with the Main routine.

Robert
:D