Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interrupt does not working in debug mode

Status
Not open for further replies.

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,936
Dear all,
I wrote a program for interrupt. so it is working well for my demo board but when I debug the program using my PICkit2 clone it does not interrupt
please advice

Code:
status		equ		0x03
portb		equ		0x06
trisb		equ		0x86
portc		equ		0x07
trisc		equ		0x87
portd		equ		0x08
trisd		equ		0x88
option_reg	equ		0x81
intcon		equ		0x0b
temp_w		equ		0x23
temp_sta	equ		0x24

#include <p16f877a.inc>
__config	3f39

			org		0x000
stsrt		clrwdt
			goto	main
			org		0x004
			goto	isr
			goto	check
			
main		clrwdt
			call	sys_init
			call	check
check
loop1		goto	loop
loop		goto	loop1

isr			movwf	temp_w
			swapf	status,w
			movwf	temp_sta	

			movlw	0xff
			movwf	portc

			swapf	temp_sta,w
			movwf	status
			swapf	temp_w,f
			swapf	temp_w,w
			bcf		intcon,0	;RBIF
			retfie

sys_init	bsf		status,5	;BANK1
			clrf	trisc
			clrf	trisd
			movlw	b'11110000'
			movwf	trisb
			bcf		option_reg,7;RBPU
			bcf		status,5	;BANK0
			bsf		intcon,7	;GIE
			bsf		intcon,3 	;RBIE
			movlw	0xf0
			movwf	portb
			clrf	portc
			clrf	portd
			bcf		intcon,0	;RBIF
			return
			
end
 

Re: Interrupt dose not working in debug mode

Is that your code, or what you got after the debugging program was through with it? Compare the two, because the debugging got rid of something that worked.
 

Re: Interrupt dose not working in debug mode

Is that your code, or what you got after the debugging program was through with it? Compare the two, because the debugging got rid of something that worked.

Dear wa1kij,
Thanks for reply
That is my code and in the debugging mode it is come to check subroutine and continue loop but does not response for interrupt
please advice
 

Re: Interrupt dose not working in debug mode

Dear all,
I wrote a program for interrupt. so it is working well for my demo board but when I debug the program using my PICkit2 clone it does not interrupt
please advice

hai... i am not much familiar with assembly language. May be the below information help you

As u said, your code doesn't go to interrupt during debug mode could be a reason of timeout. I have faced such problem when i interface I2C slave with my controller.
 

Re: Interrupt dose not working in debug mode

hai... i am not much familiar with assembly language. May be the below information help you

As u said, your code doesn't go to interrupt during debug mode could be a reason of timeout. I have faced such problem when i interface I2C slave with my controller.


Dear karthikkrv85,
Thank you very much for reply
What do you mean timeout and how may is sort out the problem?
please advice
 

Re: Interrupt dose not working in debug mode

What do you mean timeout and how may is sort out the problem?
please advice

When initial experience of I2C programming, i was enabled timeout for I2C (25 ms) with a configuration tool. I didn't face problem when it is on execution but i didn't get proper data during debug because the master device has recognized the delay of transmission and resets the bus to default mode. (In my case both slave and master are micro controllers)

Can you tell me what kind of interrupt you are trying to generate?
 

Re: Interrupt dose not working in debug mode

When initial experience of I2C programming, i was enabled timeout for I2C (25 ms) with a configuration tool. I didn't face problem when it is on execution but i didn't get proper data during debug because the master device has recognized the delay of transmission and resets the bus to default mode. (In my case both slave and master are micro controllers)

Can you tell me what kind of interrupt you are trying to generate?

Dear Thank you so much for reply
I am using PORTB change interrupt, and please look in to my code in my fist post
 

Re: Interrupt dose not working in debug mode

To successfully clear the interrupt flag for a PORTB Interrupt-on-Change, you must first clear the mismatch condition of PORTB, by either reading or writing to PORTB and the clear the RBIF.

The mismatch condition does not appear to be cleared in your ISR before clearing the RBIF.

Code:
isr			movwf	temp_w
			swapf	status,w
			movwf	temp_sta	

			movlw	0xff
			movwf	portc

			swapf	temp_sta,w
			movwf	status
			swapf	temp_w,f
			swapf	temp_w,w
			bcf		intcon,0	;RBIF
			retfie

Reference: PIC16F87XA Datasheet, Section: 4.2 PORTB and the TRISB Register, pg 44

Four of the PORTB pins, RB7:RB4, have an interrupton-
change feature. Only pins configured as inputs can
cause this interrupt to occur (i.e., any RB7:RB4 pin
configured as an output is excluded from the interrupton-
change comparison). The input pins (of RB7:RB4)
are compared with the old value latched on the last
read of PORTB. The “mismatch” outputs of RB7:RB4
are OR’ed together to generate the RB port change
interrupt with flag bit RBIF (INTCON<0>).

This interrupt can wake the device from Sleep. The
user, in the Interrupt Service Routine, can clear the
interrupt in the following manner:

a) Any read or write of PORTB. This will end the
mismatch condition.

b) Clear flag bit RBIF.

A mismatch condition will continue to set flag bit RBIF.
Reading PORTB will end the mismatch condition and
allow flag bit RBIF to be cleared.


The interrupt-on-change feature is recommended for
wake-up on key depression operation and operations
where PORTB is only used for the interrupt-on-change
feature. Polling of PORTB is not recommended while
using the interrupt-on-change feature.

The following appnotes may be of interest:

Using the Port B Interrupt on Change as an External Interrupt

Code:
PER_INT      BTFSS INTCON, RBIF         ; PortB interrupt?
                 GOTO   OTHER_INT           ; Other interrupt
                 BTFSC  PORTB, RB7          ; Check for rising edge
                 GOTO   CLR_RBINTF          ; Falling edge, clear PortB int
                          :                          ;   flag
                          :                          ; Do task for INT on RB7
                          :
[COLOR="#FF0000"]CLR_RBINTF   MOVF  PORTB, 1             ; Read PortB (to itself) to end
                                                      ;    mismatch condition
                 BCF    INTCON, RBIF         ; Clear the RB interrupt flag. 
                 RETFIE                           ; Return from interrupt[/COLOR]

OTHER_INT                 :                    ; Do what you need to here
                                :
RETFIE                     ; Return from interrupt


Another issue which can be the source of problems is a relatively long delay between closure and reopening of a switch when pressed.
This can trigger two interrupts on change if not properly handled, Appnote AN566 above addresses this issue.

AN552 Implementing Wake-up on Key Stroke

The debugging issues maybe do to the failure to clear the mismatch condition before clearing RBIF, also delays and pauses in the debug process can greatly exacerbate the issue of long pin transitions discussed in the above two appnotes.

BigDog
 
Re: Interrupt dose not working in debug mode

The debugging issues maybe do to the failure to clear the mismatch condition before clearing RBIF, also delays and pauses in the debug process can greatly exacerbate the issue of long pin transitions discussed in the above two appnotes.

Dear BigDogguru
It is really helpful me your explanation and thank you so much,
I edited my code as you advice but when I set debugger mode it works well in run mode and response for interrupt but not works for animate mode
I mean in animate mode the interrupt does not occur

please advice


run.GIF

Code:
status		equ		0x03
portb		equ		0x06
trisb		equ		0x86
portc		equ		0x07
trisc		equ		0x87
portd		equ		0x08
trisd		equ		0x88
option_reg	equ		0x81
intcon		equ		0x0b
temp_w		equ		0x23
temp_sta	equ		0x24
int_reg		equ		0x25
#define	int_flag	int_reg,0

#include <p16f877a.inc>
__config	3f39

			org		0x000
stsrt		clrwdt
			goto	main
			org		0x004
			goto	isr
			goto	check
			
main		clrwdt
			call	sys_init
			call	check
check

			btfss	int_flag
			goto	loop1
			clrf	portc
loop1		goto	loop
loop		goto	loop1

isr			btfss	intcon,0
			retfie
			bsf		int_flag
			movwf	temp_w
			swapf	status,w
			movwf	temp_sta
				

			movlw	0xff
			movwf	portc

			swapf	temp_sta,w
			movwf	status
			swapf	temp_w,f
			swapf	temp_w,w
			movf	portb,f
			bcf		intcon,0	;RBIF
			retfie

sys_init	bsf		status,5	;BANK1
			clrf	trisc
			clrf	trisd
			movlw	b'11110000'
			movwf	trisb
			bcf		option_reg,7;RBPU
			bcf		status,5	;BANK0
			bsf		intcon,7	;GIE
			bsf		intcon,3 	;RBIE
			movlw	0xf0
			movwf	portb
			clrf	portc
			clrf	portd
			bcf		intcon,0	;RBIF
			return
			
end
 
Last edited:

Re: Interrupt dose not working in debug mode

I edited my code as you advice but when I set debugger mode it works well in run mode and response for interrupt but not works for animate mode
I mean in animate mode the interrupt does not occur

As I indicated above, debugging methods can in fact create issues with interrupts, particularly when the trigger of the interrupt is stimulus external to the microcontroller.

This is due in part from the "pausing effect" of some phases in the debugging procedure.

For instance when debugging in animate mode, the microcontroller executes an instruction and then is temporarily halted, the MPLAB IDE is then updated, register settings, code execution position, etc. The code execution is then restarted, the next instruction inline is executed, the microcontroller is temporarily halted, MPLAB is updated and the process continues, ad infinitum.

However, temporarily halting the microcontroller, in the majority of cases, does not effect or halt the external stimuli triggering the Interrupt-On-Change.

If, for example, the microcontroller is in this "paused" state at the time external stimuli would normally trigger an Interrupt-On-Change, the microcontroller is unable to service the interrupt due to its "paused" state.

Being unable to service the interrupt, may result in the interrupt being missed or result in an out-of-sync condition, where the microcontroller enters an undefined/unplanned state in relationship to the stimuli triggering the interrupt causing the system to exhibit unexpected behavior.

The use of breakpoints when debugging interrupts/ISR can also be the source of similar issues, care must be taken when placing a breakpoint to avoid the interrupting the execution of the Interrupt Service Routine (ISR), particularly when the ISR is servicing stimuli external to the microcontroller.

Often the best method of "debugging" an ISR is to make use of a few of the microcontroller's unused pins, temporarily adding code within the ISR to transition the state of these pins depending on the point of code execution within the ISR, then monitoring these pin states with a oscilloscope or logic analyzer. Some of the Microchip PICkits actually have a simple 3 channel logic analyzer which could serve quite useful for such a purpose.

Be aware that debugging a UART can also be a similar source of frustration, due to improperly placed breakpoints temporarily halting code execution, the other device attached to the RS-232 connection senses a "time out" condition and ultimately resets the RS-232 communication channel.

BigDog
 
So, should the code be modified to get around the shortcomings of the debugging program, or do we need a better debugger?

---------- Post added at 13:59 ---------- Previous post was at 13:57 ----------

...maybe this is more of a philosophical question.
 

Re: Interrupt dose not working in debug mode

Dear All
I found AN552 from microchips website. as I know return from the ISR we used RETFIE command but in this they used return command please advice
see attachment
 

Attachments

  • 00552e.pdf
    96.2 KB · Views: 66

Re: Interrupt dose not working in debug mode

Dear All
I found AN552 from microchips website. as I know return from the ISR we used RETFIE command but in this they used return command please advice
see attachment

I believe the routine to which you are referring, ServiceInterrupt, is actually NOT the Interrupt Service Routine (ISR), but is instead essentially a switch routine which detects whether an Interrupt-On-Change has occurred and if it has routes execution to the actual ISR, ServiceWakup, which does employ the RETFIE instruction to enable GIE and returns execution back to the routine ServiceInterrupt.

Review the highlight code below:

Code:
	include "p16c71.inc"
;
	org     0
	goto    start
;
	org     4
	goto    ServiceInterrupt
;
;
start
	call    InitPortB       ;initalize port B
loop
;        sleep                   ;sleep till key is hit
	nop
	goto    loop
;
ServiceInterrupt
	btfsc   INTCON,RBIF     ;change on rb int?
	[COLOR="#FF0000"]goto    ServiceWakup    ;yes then service[/COLOR]
	bcf     INTCON,T0IE     ;clear TMR0 int mask
	bcf     INTCON,T0IF     ;clear flag
	return
;
;This routine checks which keys is hit and lights up the
;corresponding LED associated with it. eg. RB0's LED when
;RB4's key is pressed. Finally it waits till all keys have 
;been released before returning form the service routine.
[COLOR="#FF0000"]ServiceWakup[/COLOR]
	bcf     INTCON,RBIE     ;clear mask
	comf    PORTB,W        ;read PORTB
	bcf     INTCON,RBIF     ;clear flag
	call    delay16         ;do de-bounce for 16mSecs
	comf    PORTB,W        ;read port B again
	andlw   B'11110000'     ;mask outputs
	movwf   temp            ;save in temp
	swapf   temp,W          ;switch low and high
	movwf   PORTB          ;send as outputs.
	call    KeyRelease      ;check for key release
	[COLOR="#FF0000"]retfie[/COLOR]

;
;This sub-routine, waits till all key have been released
;In order to save power, the chip is in sleep mode till
;all keys are released.
KeyRelease
	call    delay16         ;do debounce
	comf    PORTB,W        ;read PORTB
	bcf     INTCON,RBIF     ;clear flag
	bsf     INTCON,RBIE     ;enable mask
	andlw   B'11110000'     ;clear outputs
	btfsc   STATUS,z        ;key still pressed?
	return                  ;no then return
	sleep                   ;else save power
	bcf     INTCON,RBIE     ;on wake up clear mask
	comf    PORTB,W
	bcf     INTCON,RBIF     ;clear flag
	goto    KeyRelease      ;try again

;
;
;This sub-routine, initializes PortB.
InitPortB
	bsf     STATUS,RP0      ;select bank 1
	movlw   B'00000011'     ;Port_A digital I/O
	movwf   ADCON1          ;               /
	movlw   0               ;
	movwf   PORTA          ;set port a as outputs
	movlw   B'11110000'     ;RB0-RB3 outputs
	movwf   PORTB          ;RB4-RB7 inputs
	bcf     OptionReg,RBPU  ;enable pull up
	bcf     STATUS,RP0      ;select page 0
	clrf    PORTB          ;init port B
	clrf    PORTA          ;make port a all low
	bsf     PORTA,0        ;make first bit high
	bcf     INTCON,RBIE     ;disable mask
	movf    PORTB,W        ;read port
	bcf     INTCON,RBIF     ;clear flag
	bsf     INTCON,RBIE     ;enable mask
	retfie                  ;enable global and return
;
;delay16 waits for approx 16.4mSecs using TMR0 interrupts
;fosc speed is 4Mhz.
delay16
	bsf     STATUS,RP0      ;select page 1
	movlw   B'00000111'     ;fosc/256 --> TMR0
	movwf   OptionReg       ;       /
	bcf     STATUS,RP0      ;select page 0
	clrf    TMR0
	bcf     INTCON,T0IF     ;clear flag
	bsf     INTCON,T0IE     ;enable mask
CheckAgain
	btfss   INTCON,T0IF     ;timer overflowed?
	goto    CheckAgain      ;no check again
	bcf     INTCON,T0IE     ;else clear mask
	bcf     INTCON,T0IF     ;clear flag
	return
;
	end

Does this answer your questions concerning RETFIE?


BigDog
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Re: Interrupt dose not working in debug mode

Dear Bigdog thanks again you always help us and reply very perfectly

I sow one subroutine call initportB which call from main loop also used RETFIE command. can I have some explanation on that
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top