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.

[PIC] pic18F87k22 timer 5 and 7 interrupt problem

Status
Not open for further replies.

hodahussein

Full Member level 2
Joined
Apr 17, 2007
Messages
144
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,276
hi

i am using pic18f87k22 in our product battery charger, so we need to use timer 3 and timer 5 and timer 7

for Timer3 the initialization code as following

Code:
	CLRF	TMR3H
	CLRF	TMR3L


	MOVLW	B'01011000'
	MOVWF	T3CON
	clrf	       T3GCON
	bcf		PIR2,TMR3GIF
	bcf		PIR2,TMR3IF
	bsf		PIE2,TMR3IE
	bsf		T3CON,TMR3ON

so it work as we want after TMR overflow the interrupt is occurred.

for timer 5

Code:
	CLRF	TMR5H
	CLRF	TMR5L

	clrf	      T5GCON
	MOVLW	B'00011000'
	MOVWF	T5CON

	bcf		PIR3,TMR5GIE
	bcf		PIR3,TMR5GIF
	bcf		PIR5,TMR5IF
	bsf		PIE5,TMR5IE

	bSf		T5CON,TMR5ON
	BSF		INTCON,GIE
	BSF		INTCON,PEIE
first problem in Timer 5 the pre-scale is adjusted with 1:2 so we observed that the timer count each 8 cycle not 2 cycle
second problem the interrupt did not happen although the flag bit "PIR5,TMR5IF" become one
========
for timer 7

Code:
	banksel	T7CON
	MOVLW	B'00011000'
	MOVWF	T7CON
	clrf	T7GCON

	CLRF	TMR7H
	CLRF	TMR7L
	bsf		T7CON,TMR7ON
	CLRF	BSR	

	bcf		PIR5,TMR7GIF
	bcf		PIR5,TMR7IF
	bsf		PIE5,TMR7IE
	bCf		PIE5,TMR7GIE
	bCf		IPR5,TMR7IP
	CLRF	BSR


	BSF		INTCON,GIE
	BSF		INTCON,PEIE
the timer 7 will count each 2 cycle ok the pre scale is right
but also the interrupt not happen

i need to fix this problem

thanks
 
Last edited by a moderator:

Can you show us the ISR - the chances are that you are not handling the IF flags properly.
Susan
 

Can you show us the ISR - the chances are that you are not handling the IF flags properly.
Susan

whatever the ISR code. On MPLAB watch menu the Interrupt flags of timer 5 & timer 7 are set at the time of overflow,and the interrupt enable of the timers(In PIR registers) are set,and the general & peripheral interrupt enables also are set.(GIE=1,PEIE=1,TMR5GIF=0,TMR7GIF=0,TMR7IF=1,TMR5IF=1,TMR5GIE=0,TMR7GIE=0,TMR7IE=1,TMR5IE=1,TMR5GIP=1,TMR7GIP=1,TMR7IP=1,TMR5IP=1,IPEN=1/0)
 

OK, you you have shown that the conditions for calling the Interrupt Service Routine (ISR) should be met but if the ISR is not being called correctly then you need to show us the code for both the low and hig priority interrupts.
Susan
 

OK, you you have shown that the conditions for calling the Interrupt Service Routine (ISR) should be met but if the ISR is not being called correctly then you need to show us the code for both the low and hig priority interrupts.
Susan



Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ISRLORG    CODE  
                MOVFF   STATUS,STATUS_TEMP      ;save STATUS register
                MOVFF   WREG,WREG_TEMP          ;save working register
                MOVFF   BSR,BSR_TEMP            ;save BSR register
;----------------------------------------------------------------------
                banksel       PORTB
                movlw        0x080
                xorwf         PORTB
 
;----------------------------------------------------------------------
EndISRL
                bcf             BSR,0   
                MOVFF   BSR_TEMP,BSR            ;restore BSR register
                MOVFF   WREG_TEMP,WREG          ;restore working register
                MOVFF   STATUS_TEMP,STATUS      ;restore STATUS register
 
 
                RETFIE





this a demo code just to test the interrupt of timers
 
Last edited by a moderator:

Thanks for that.
If this is the actual ISR then you have the preamble and postamble OK but the part that does the real work is not testing for which interrupt source(s) triggered the call and does not reset the appropriate IF flag.
What this ISR will do is to be called repeatedly with virtually no time provided to the main program code.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top