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.

PIC18F4550 interrupts only once

Status
Not open for further replies.

WizStefan

Newbie level 3
Joined
Dec 15, 2008
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
pic18f4550

Hi everybody!
I'm working on a clock for a university practice. I'm using two interruptions on the pic; one by timer0, that happens every 1 second and is used as my base time, and another one by timer1, that happens every 10ms and is used to multiplex between my 4 seven segment displays. The problem is that only the first interruption is happening (at 10ms) then it gets out of the interruption, and continue with the program and doesn't care about any other interruption anymore... I'm clearing the interrupt flag bit on every timer once the interruption ends, and even re-setting the enable bits for every interruption at the end too (although it's not even necessary)... I'm stuck on this, and don't know what else to do, the simulation on Proteus works perfect, i don't get any error there =S

Can anyone give me any advice? Sorry for the bad english =)

Added after 23 minutes:

This is the code that's giving me problems, the name of the functions and the comments are on spanish, sorry for that =)

This is the initial configuration:
Code:
;	Directivas de inicio

			LIST		P=PIC18F4550
			#include	<P18F4550.INC>

;---------------------------------------------------
;	Configuracion
			CONFIG     WDT = OFF            ; Guardián desactivado
			CONFIG     FOSC = HS            ; Operación con Oscilador de alta velocidad externo.
			CONFIG     BOR = OFF
			CONFIG     MCLRE = OFF          ; Pin 1 como Master reset, RE3 desabilitada
			CONFIG     LVP = OFF            ; Programación de bajo voltaje desactivada

;---------------------------------------------------
;	Declaracion de variables

j			equ			0x8A					;
k			equ			0x8E						;	Constantes usadas en la
l			equ			0x8F						;	funcion de demora
m			equ			0x90						;

seg1		equ			0x92						;
seg2		equ			0x93						;
min1		equ			0x94						;
min2		equ			0x95						;
hor1		equ			0x96						;
hor2		equ			0x97						;

modomux		equ			0x98						;

aux			equ			0x9D						;
aux2		equ			0x99						;

;---------------------------------------------------
;	Vectores de inicio e interrupciones

			ORG			0x00						;	Vector de inicio
			goto		INICIO						;

			ORG			0x08						;
			movwf		aux2						;
			btfsc		INTCON,TMR0IF				;	Vector de interrupcion
			goto		Reloj						;
			btfsc		PIR1,TMR1IF					;
			goto		Multiplexacion				;
			goto		fin_interrupcion			;

;---------------------------------------------------

INICIO:												
			clrf 		LATA						;
			clrf 		LATB						;	Limpieza de latch de todos
			clrf 		LATC						;	los puertos
			clrf 		LATD						;
			clrf 		LATE						;
													
			clrf		PORTA						;
			clrf		PORTB						;	
			clrf		PORTC						;	Limpieza de los puertos
			clrf		PORTE						;
			clrf		PORTD						;
													
			movlw		b'00000000'					;
			movwf		TRISB						;
			movlw		b'00000000'					;	Configuracion de los puertos
			movwf		TRISC						;	B, C y D como salida, y RA0
			movlw		b'00000000'					;	RA1 y RA2 como entradas
			movwf		TRISD						;
			movlw		b'00001111'					;
			movwf		TRISA						;
			movlw		b'00000000'
			movwf		TRISE						;

			movlw		b'00001111'					;	Configuracion de RA0, RA1 y
			movwf		ADCON1						;	RA2 como entradas digitalesoo 
       
			movlw		b'11100000'					;	interrupciones, de la prioridad
			movwf		INTCON						;	de las interrupciones y de la
												
			movlw		0xf0						;	Carga el numero de 16 bits
			movwf		TMR0H						;	61629 en hexadecimal al registro
			movlw		0xbd						;	de timer0
			movwf		TMR0L						;

			movlw		b'10000111'					;	Carga el preescalar del timer0
			movwf		T0CON						;	a 256 y activa el timer0

			movlw		0xfd						;	Carga el numero de 16 bits
			movwf		TMR1H						;	en hexadecimal al registro
			movlw		0x8f						;	de timer1
			movwf		TMR1L						;

			movlw		b'10110001'					;	Carga el preescalar del timer1
			movwf		T1CON						;	a 1 y activa el timer1

			bsf			PIE1,.0	

			bsf			PORTE,.0					;
			movlw		.0							;
			movwf		seg1						;
			movwf		seg2						;
			movwf		min1						;
			movwf		min2						;
			movlw		.1							;
			movwf		hor2						;
			movlw		.2							;
			movwf		hor1						;

And this is the code for the interruptions, there's two types of multiplexation because you can set the pic to show you 'Minutes-Seconds' or 'Hours-Minutes':

Code:
;-------------------------------------------------------------------------
; Interrupciones

Multiplexacion:
			bcf			PIR1,TMR1IF					;	Pone a cero la bandera timer1

			movlw		0xfd						;
			movwf		TMR1H						;	Vuelve a cargar el valor
			movlw		0x8f						;	55536 en el timer1
			movwf		TMR1L						;

			btfss		modomux,.0					;
			goto		min_seg0					;	Para modomux = 0
			goto		hor_min0					;	Para modomux = 1

min_seg0:
			btfsc		PORTE,.0
			goto		min_seg1
			btfsc		PORTE,.1
			goto		min_seg2
			btfsc		PORTE,.2
			goto		min_seg3
			btfsc		PORTC,.2
			goto		min_seg4

min_seg1:
			bcf			PORTE,.0
			bsf			PORTE,.2
			movff		seg2,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

min_seg2:
			bcf			PORTE,.1
			bsf			PORTE,.2
			movff		min1,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

min_seg3:
			bcf			PORTE,.2
			bsf			PORTC,.2
			movff		min2,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

min_seg4:
			bcf			PORTC,.2
			bsf			PORTE,.0
			movff		seg1,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

hor_min0
			btfsc		PORTE,.0
			goto		hor_min1
			btfsc		PORTE,.1
			goto		hor_min2
			btfsc		PORTE,.2
			goto		hor_min3
			btfsc		PORTC,.2
			goto		hor_min4

hor_min1:
			bcf			PORTE,.0
			bsf			PORTE,.2
			movff		min2,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

hor_min2:
			bcf			PORTE,.1
			bsf			PORTE,.2
			movff		hor1,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

hor_min3:
			bcf			PORTE,.2
			bsf			PORTC,.2
			movff		hor2,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

hor_min4:
			bcf			PORTC,.2
			bsf			PORTE,.0
			movff		min1,aux					;
			rlncf		aux,0						;
			call		Tabla						;
			movwf		PORTD						;
			goto		fin_interrupcion

Reloj:
			bcf			INTCON,TMR0IF				;	Pone a cero la bandera timer0

			movlw		0xf0						;
			movwf		TMR0H						;	Vuelve a cargar el valor
			movlw		0xbd						;	61629 en el timer0
			movwf		TMR0L						;

			movlw		.9							;
			cpfseq		seg1						;
			goto		SumarSeg1					;
			clrf		seg1						;
			movlw		.5							;
			cpfseq		seg2						;
			goto		SumarSeg2					;
			clrf		seg2						;
			movlw		.9							;
			cpfseq		min1						;
			goto		SumarMin1					;
			clrf		min1						;
			movlw		.5							;
			cpfseq		min2						;
			goto		SumarMin2					;
			clrf		min2						;
			movlw		.1							;
			cpfseq		hor2						;
			goto		SumarHor1_01				;	Cuando hor2 = 0
			goto		SumarHor1_11				;	Cuando hor2	= 1

SumarSeg1:
			movlw		.1							;
			addwf		seg1						;
			goto		fin_interrupcion

SumarSeg2:
			movlw		.1							;
			addwf		seg2						;
			goto		fin_interrupcion

SumarMin1:
			movlw		.1							;
			addwf		min1						;
			goto		fin_interrupcion

SumarMin2:
			movlw		.1							;
			addwf		min2						;
			goto		fin_interrupcion

SumarHor1_01:
			movlw		.9							;
			cpfseq		hor1						;
			goto		SumarHor1_02				;
			clrf		hor1						;
			movlw		.1							;
			movwf		hor2						;
			goto		fin_interrupcion
			
SumarHor1_02:
			movlw		.1							;
			addwf		hor1						;
			goto		fin_interrupcion

SumarHor1_11:
			movlw		.2							;
			cpfseq		hor1						;
			goto		SumarHor2					;
			movlw		.1							;
			movwf		hor1						;
			clrf		hor2						;							
			goto		fin_interrupcion

SumarHor2:
			movlw		.1							;
			addwf		hor1 						;
			goto		fin_interrupcion

;-------------------------------------------------------------------------
; Otros

Cambio:
			movlw		.15
			call		Demora
			btfss		PORTA,.3
			goto		Cambio
			btg			modomux,0
			return

fin_interrupcion:
			bsf			PORTC,.6
			bcf			PIR1,TMR1IF					;	Pone a cero la bandera timer1
			bsf			INTCON,TMR0IE
			bsf			PIE1,TMR1IE
			movf		aux2,0
			retfie

fin_call:
			return
;-------------------------------------------------------------------------
; Tabla

Tabla:
			addwf		PCL,1
			retlw		b'11000000'
			retlw		b'11111001'
			retlw		b'10100100'
			retlw		b'10110000'
			retlw		b'10011001'
			retlw		b'10010010'
			retlw		b'10000011'
			retlw		b'10111000'
			retlw		b'10000000'
			retlw		b'10011000'
 

pic18f4550 interrupts

Hi,

Will not try to work out your code - it looks like you are using the Interrupts like I used to which similarly gave me wild results.

Help from the Microchip forums put me on the right track - a typical layout attached.

The important points they made:-
The ISR code should be before your main code.
Keep the ISR routine as short as possible, rather than exectute loads of code in the isr, set a flag that triggers those routines back in the main code.
Do not use a lot of goto or calls within the ISR code
Do not use goto or calls to routines outside the ISR code.

Since following these basic rules I have never had any ISR problems



Code:
;******************************************************************************
;
;	Reset vector
;	============

		ORG	0x0000
		nop
bootup	goto	Main		;go to start of main code

;******************************************************************************
;
;	High priority interrupt vector
;	==============================

; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.

		ORG	0x0008

		bra	HighInt		;go to high priority interrupt routine

;******************************************************************************
;
;	Low priority interrupt vector
;	=============================
 
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.

		ORG	0x0018

;		movff	STATUS,STATUS_TEMP	;save STATUS register
;		movff	WREG,WREG_TEMP		;save working register
;		movff	BSR,BSR_TEMP		;save BSR register

;	*** low priority interrupt code goes here ***


;		movff	BSR_TEMP,BSR		;restore BSR register
;		movff	WREG_TEMP,WREG		;restore working register
;		movff	STATUS_TEMP,STATUS	;restore STATUS register
		retfie

;******************************************************************************
;
;	High priority interrupt routine
;	===============================

; The high priority interrupt code is placed here to avoid conflicting with
; the low priority interrupt vector.
; should be placed before the Main program code

; Timer1 and Clock ; Timer1 and Clock Increment routines

HighInt		nop

isrtm1	btfsc PIR1,TMR1IF		; timer1 overflow int
		goto	tm1over		        ; timer1 has overflowed
		goto 	hisrend				; not tmr1 overflow - error - go back

tm1over bsf	TMR1H, 7			; preload for 1 sec overflow
		bcf	PIR1,TMR1IF				; reset timer1




hisrend	retfie	FAST



;******************************************************************************
;******************************************************************************
;
;	Start of main program
;	=====================

; initialisation of system, clear RAM , setup i/o ports



Main	movlw	b'01100010'		; set internal osc to 4 mhz
		movwf	OSCCON
 

    WizStefan

    Points: 2
    Helpful Answer Positive Rating
config fosc=hs

Thanks, but i still have the problem... Can you give me the link to the forum thread where they told you that?
 

registro osccon pic18f452

Hi,

Its microchips own Users Forum https://www.microchip.com/forums/Default.aspx?

Look in the Sub forum - micros 14bit and 16 bit processors.

My original ISR question was years ago so it might be gone, but its a common problem so first search on' ISR' - if nothing of help then post a question.
 

    WizStefan

    Points: 2
    Helpful Answer Positive Rating
multiplexacion timer pic18f

I haven't run the code on MPLAB Sim, I have tried, but it get's stuck on the delay rutine... I have run the code on Proteus VSM, and it runs ok...
 

portd pic18f4550

@wp100. Thanks for that interrupt guide line. I guess it's applicable to all the microchip PIC as far as interrupt routine is concerned. I did get some ISR problem occasionally and manage to solve it without knowing these clearly stated rules. I have learnt something today. Thank you.
 

pic 18f4550 low priority interrupt not working

I solved my problem! I did what wp101 said, I just didn't understood him at first XD

That should be on the datasheet. Thanks a lot!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top