PDA

View Full Version : DT-INt and Interrupt on Change



Luckyborg
- 23rd April 2013, 22:00
I have used DT-Ints for a couple other projects and I finally had a need to use interrupt on change. I thought it would be fairly easy compared to the RX_int and timers, but I seem to be missing something basic as I can not get the interrupts to trigger. Basically I want to monitor Pins B.5 and B.6 on a PIC18F45k22 and if there is ever a change on either pin the to put that output onto PORTA.0. I have added some lines to toggle an LED on A.1 just for a visual check, but it never changes either. I have stripped the code down to the basics and still nothing. I'm assuming there is one register I need to setup but I have tried playing with several with no luck and was under the impression the DT-INTS would take care of the register setting anyway.



#CONFIG
CONFIG FOSC = HSHP
CONFIG PLLCFG = ON
CONFIG PRICLKEN = ON
CONFIG FCMEN = ON
CONFIG IESO = OFF
CONFIG PWRTEN = ON
CONFIG BOREN = ON
CONFIG BORV = 250
CONFIG WDTEN = ON
CONFIG WDTPS = 512
CONFIG PBADEN = OFF
CONFIG MCLRE = EXTMCLR
CONFIG STVREN = OFF
CONFIG LVP = OFF
CONFIG XINST = OFF
CONFIG CP0 = ON
CONFIG CP1 = ON
CONFIG CP2 = ON
CONFIG CP3 = ON
#ENDCONFIG

Clear
DEFINE OSC 40 ' Set Xtal Frequency

INCLUDE "C:\PBP\DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "C:\PBP\ReEnterPBP-18.bas" ; Include if using PBP interrupts

'Set Ports for Outputs/Inputs

TRISA = %11111100
TRISC = %10000111 'Set PORTC 0,1,2 to input for switches, 7 for RX
TRISD = 0
TRISE = 0
TRISB = %01110011
PORTA.1 = 1
PORTC.4 = 1

ANSELA = 0
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0

;****************Using Darrel Taylor Interrupts****************************
;----[High Priority Interrupts]--------------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT1_INT, _IntPORTB5, PBP, yes
INT_Handler INT2_INT, _IntPORTB6, PBP, yes
endm
INT_CREATE ;Creates the High Priority interrupt processor
ENDASM

@ INT_ENABLE INT1_INT ; enable external (INT) interrupts
@ INT_ENABLE INT2_INT ; enable external (INT) interrupts

main
toggle PORTC.4
pause 500
goto main

;---[INT - interrupt handler]---------------------------------------------------
IntPORTB5: 'cloop
PORTA.0 = PORTB.5
toggle PORTA.1
@ INT_RETURN

IntPORTB6: '232/485
PORTA.0 = PORTB.6
toggle PORTA.1
@ INT_RETURN

Thanks for taking a moment to look

David

Darrel Taylor
- 24th April 2013, 00:05
INT1 is on RB1
INT2 is on RB2

And both of those INT's only trigger on one edge, not both.

What you want is RBC_INT.
Which will give interrupts on any change of RB4-7.

Luckyborg
- 24th April 2013, 17:44
Thanks Darrel, that definitely helps clear things in my head. I kept merging the two types of interrupts in my mind for some reason, which through me off when trying to understand the data sheet.

Unfortunately, it looks like the interrupt will not allow me to do what I was hoping for after all. I have an 8 pin micro that monitors signal from two sources and whenever there is a change on either pin it passes the signal along a third pin to a 40 pin chip. I was hoping to get rid of the 8 pin chip and use interrupts to take the two signals with IOC and pass them out a third pin which was tied to my original serial pin and use serin2 to get the data as before. It appeared to work with 1200 and 2400 baud, but when I went to anything faster the data became unusable. The interrupt must just be too slow to do everything needed before missing bits.

Thanks for the help though,
David

Darrel Taylor
- 24th April 2013, 19:00
Since there's nothing in the ISR that uses PBP's SYSTEM variables, change the TYPE of interrupt to ASM for faster execution.

Luckyborg
- 24th April 2013, 21:23
Tried the asm version, also increased clock speed form 40 to 64 MHz. I was able to get some data at 4800, but not reliable. Thanks for helping though

David