slow response int on RB change

Status
Not open for further replies.

williB

New Member
This program works but the response is slow
like a half second when i switch RB4 between 5v and ground ?
its running at 1.25 Mhz Fosc
i'm not complaining really , i just thought it would respond a little faster
any ideas on how to speed up the response time?


Code:
        LIST    P=16F877A 
        include "P16F877A.inc" 
        errorlevel      -302    ;Eliminate bank warning
                          
; program tests  RB4 interrupt on change feature 
; the pulse is a short pulse



TEMP    EQU     0x20 
COUNT   EQU     0X21
ADON    EQU     0X00 
ADIF    EQU     0X06 
GO_DONE EQU     0X02 
TMR2ON  EQU     0X02 
TMR2IF  EQU     0X01 
RP0     EQU     0x05 
RP1     EQU     0x06 
W                            EQU     H'0000' 
F                            EQU     H'0001' 
RB4	equ	0x04

;----- Register Files------------------------------------------------------ 

INDF                         EQU     H'0000' 
TMR0                         EQU     H'0001' 
PCL                          EQU     H'0002' 
STATUS                       EQU     H'0003' 
FSR                          EQU     H'0004' 
PORTA                        EQU     H'0005' 
PORTB                        EQU     H'0006'
PORTC                        EQU     0x0007
PORTD                        EQU     0x0008	 
PORTE                        EQU     0x0009
PCLATH                       EQU     H'000A' 
INTCON                       EQU     H'000B'
RBIF			     EQU     H'0000'		 
PIR1                         EQU     H'000C' 
PIR2                         EQU     H'000D' 
TMR1L                        EQU     H'000E' 
TMR1H                        EQU     H'000F' 
T1CON                        EQU     H'0010' 
TMR2                         EQU     H'0011' 
T2CON                        EQU     H'0012' 
CCPR1L                       EQU     H'0015' 
CCPR1H                       EQU     H'0016' 
CCP1CON                      EQU     H'0017' 
RCSTA                        EQU     H'0018' 
TXREG                        EQU     H'0019' 
RCREG                        EQU     H'001A' 
ADRESH                       EQU     H'001E' 
ADCON0                       EQU     H'001F' 

OPTION_REG                   EQU     H'0081' 
RBPU			     EQU     0x0007		
TRISA                        EQU     H'0085' 
TRISB                        EQU     H'0086' 
TRISC                        EQU     0x0087
TRISD                        EQU     0x0088
TRISE                        EQU     0x0089
PIE1                         EQU     H'008C' 
PCON                         EQU     H'008E' 
PR2                          EQU     H'0092' 
TXSTA                        EQU     H'0098' 
SPBRG                        EQU     H'0099' 
EEDATA                       EQU     H'010C' 
ANSEL                        EQU     H'009B' 
CMCON                        EQU     H'009C' 
EECON2                       EQU     H'018D' 
ADRESL                       EQU     H'009E' 
ADCON1                       EQU     H'009F' 



        org     0x00 		; Reset Vector
	goto    START            ; 
        org     0x04            ; int vector
        goto    ISR
START                                        
        clrf    PORTA      	;B0
    	clrf    PORTB           ;B0 
        clrf    PORTC           ;B0  
        clrf    PORTD           ;B0
        CLRF    STATUS 		;B0
          			;B0
	Banksel TRISA		;B1 
        CLRF    TRISA 		;B1
	clrf	TRISB		;B1
    	CLRF	TRISC           ;B1 
        CLRF    TRISD 		;B1
	bsf	OPTION_REG,RBPU ;B1
				;B1
        BCF     STATUS ,RP0 	;B0
	

LOOP2   movlw   0x00            ;clear PORTD  while no Interrupt
        movwf   PORTD
        goto    LOOP2           ; Wait for int and loop forever


ISR     btfss   INTCON, RBIF    ;PortB Interrupt?
	goto    other_int       ;Other interrupt   
       ;btfsc   PORTB, RB4      ; Wide pulse check for rising edge
       ;goto    clear_RBINTF    ;Falling edge clear portB int flag
                
        movLw    0xFF           ; Blink portD LEDs on Interrupt
        Movwf    COUNT          ;
LOOP    MOVWF    PORTD          ;
        decfsz   COUNT          ;
        goto     LOOP           ;

clear_RBINTF 
        movf    PORTB,1         ;read PORTB (to itself) to end
                                ;mismatch condition
        bcf	INTCON,RBIF     ;Clear RB interrupt flag.
	retfie                  ;RETurn From IntErrupt

other_int                       ;was it another interrupt?
	retfie                  ;return from int
   



        END
 
Actually it behaves as a switch debounce , i thought it would respond to a fast pulse , but it really responds about a half a second after i switch levels .
lots of fun though
 
You may use external interrupt on RB0? I would use the "on-change" feature for wake-up after a button is pressed.
 
Willi,

I'm not sure what your code is doing because you don't enable any interrupts. The on change interrupt should (will) happen immediately.
Try adding the following code.
Code:
      movlw	(1<<GIE|0<<PEIE|0<<TMR0IE|0<<INTE|1<<RBIE|0<<TMR0IF|0<<INTF|0<<RBIF)
      movwf	INTCON;		enable PortB interrupts

Or, more simply but not as self explanatary,
Code:
      movlw   0x88
      movwf   INTCON

HTH

Mike.
 
oops forgot that small detail , but should i enable the peripherial interrupts too?
what is the difference between global interrupts and peripherial ones?

ps i added that code segment and got no response from the program at all
 
i tried
Code:
   movlw   0x88
   movwf   INTCON


then i tried just the movlw 0x08
no joy
is there something i'm doing wrong?
there is a lot to understand , that i havnt got a handle on yet

Code:
        LIST    P=16F877A 
        include "P16F877A.inc" 
        errorlevel      -302    ;Eliminate bank warning
                          
; program tests  RB4 interrupt on change feature 
; the pulse is a short pulse
; as seen in DS00566B Application note 566


TEMP    EQU     0x20 
COUNT   EQU     0X21
ADON    EQU     0X00 
ADIF    EQU     0X06 
GO_DONE EQU     0X02 
TMR2ON  EQU     0X02 
TMR2IF  EQU     0X01 
RP0     EQU     0x05 
RP1     EQU     0x06 
W                            EQU     H'0000' 
F                            EQU     H'0001' 
RB4	equ	0x04

;----- Register Files------------------------------------------------------ 

INDF                         EQU     H'0000' 
TMR0                         EQU     H'0001' 
PCL                          EQU     H'0002' 
STATUS                       EQU     H'0003' 
FSR                          EQU     H'0004' 
PORTA                        EQU     H'0005' 
PORTB                        EQU     H'0006'
PORTC                        EQU     0x0007
PORTD                        EQU     0x0008	 
PORTE                        EQU     0x0009
PCLATH                       EQU     H'000A' 
INTCON                       EQU     H'000B'
RBIF			     EQU     H'0000'		 
PIR1                         EQU     H'000C' 
PIR2                         EQU     H'000D' 
TMR1L                        EQU     H'000E' 
TMR1H                        EQU     H'000F' 
T1CON                        EQU     H'0010' 
TMR2                         EQU     H'0011' 
T2CON                        EQU     H'0012' 
CCPR1L                       EQU     H'0015' 
CCPR1H                       EQU     H'0016' 
CCP1CON                      EQU     H'0017' 
RCSTA                        EQU     H'0018' 
TXREG                        EQU     H'0019' 
RCREG                        EQU     H'001A' 
ADRESH                       EQU     H'001E' 
ADCON0                       EQU     H'001F' 

OPTION_REG                   EQU     H'0081' 
RBPU			     EQU     0x0007		
TRISA                        EQU     H'0085' 
TRISB                        EQU     H'0086' 
TRISC                        EQU     0x0087
TRISD                        EQU     0x0088
TRISE                        EQU     0x0089
PIE1                         EQU     H'008C' 
PCON                         EQU     H'008E' 
PR2                          EQU     H'0092' 
TXSTA                        EQU     H'0098' 
SPBRG                        EQU     H'0099' 
EEDATA                       EQU     H'010C' 
ANSEL                        EQU     H'009B' 
CMCON                        EQU     H'009C' 
EECON2                       EQU     H'018D' 
ADRESL                       EQU     H'009E' 
ADCON1                       EQU     H'009F' 



        org     0x00 		; Reset Vector
	goto    START            ; 
        org     0x04            ; int vector
        goto    ISR
START                                        
        clrf    PORTA      	;B0
    	clrf    PORTB           ;B0 
        clrf    PORTC           ;B0  
        clrf    PORTD           ;B0
        CLRF    STATUS 		;B0
          			;B0
	Banksel TRISA		;B1 
        CLRF    TRISA 		;B1
	clrf	TRISB		;B1
    	CLRF	TRISC           ;B1 
        CLRF    TRISD 		;B1
	bsf	OPTION_REG,RBPU ;B1
				;B1
        BCF     STATUS ,RP0 	;B0
	movlw   0x08            ;B0
        movwf   INTCON          ;B0

LOOP2   movlw   0x00            ;clear PORTD  while no Interrupt
        movwf   PORTD
        goto    LOOP2           ; Wait for int and loop forever


ISR     btfss   INTCON, RBIF    ;PortB Interrupt?
	goto    other_int       ;Other interrupt   
       ;btfsc   PORTB, RB4      ; Wide pulse check for rising edge
       ;goto    clear_RBINTF    ;Falling edge clear portB int flag
                
        movLw    0xFF           ; Blink portD LEDs on Interrupt
        Movwf    COUNT          ;
LOOP    MOVWF    PORTD          ;
        decfsz   COUNT          ;
        goto     LOOP           ;

clear_RBINTF 
        movf    PORTB,1         ;read PORTB (to itself) to end
                                ;mismatch condition
        bcf	INTCON,RBIF     ;Clear RB interrupt flag.
	retfie                  ;RETurn From IntErrupt

other_int                       ;was it another interrupt?
	retfie                  ;return from int
   



        END
 
Willi,

I copied your code into MPLAB and deleted all your equates as they are included in the P16F877A.inc file. When I compiled it, the assembler complained that RBPU was not defined. I checked the include file to find that it's called NOT_RBPU and herein lies a clue. You have to clear this bit in order to enable the WPUs.

Try changing it to,
Code:
	bcf	OPTION_REG,NOT_RBPU ;B1
				;B1
        BCF     STATUS ,RP0 	;B0
	movlw   0x88            ;B0
        movwf   INTCON          ;B0

Note, it now clears the bit.

HTH

Mike.
 
you are right , i was setting bit 7 , when i should have cleared it..

i made the change

still no joy
 
I think I may have found your problem. You have got port B set as all output. The interrupt on change only works on pins that are input.
Try putting 0xff in TRISB and 0x88 in INTCON.

Mike.
 
nope , not yet
i appreciate your time
i just loaded the origional back in and ran it , just to make sure everything was working properly ,so to speak ,
yeah its still working.
does my PORTD routine look ok? because on the slow version when i scope the output it dosnt look like its counting down ..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…