PDA

View Full Version : Multi Interrupt How To ?



capitano
- 2nd February 2005, 18:15
I write this program for multi interrupt routine but it don't work fine..
help me please....
thank you in advance





DEFINE LOADER_USED 1




DEFINE OSC 20




DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50


OPTION_REG=%00000111 ' Pull-up PORTB: Enabled


T1CON=%00100000
CCP1CON=%00000101

T2CON=%00000101 ' Timer 2 is ON - Timer 2 Prescaler 1
CCP2CON=%00001100 ' PWM mode


ADCON0=%00000001 ' A/D converter module is operating
ADCON1=%00000100 ' Confing D D D D A D A A


TRISA = %11101011
TRISB = %11111100
TRISC = %10011100
TRISD = %00000000
TRISE = %00000011




RCSTA = $90 ' Enable USART receive
TXSTA = %00100100 ' Set USART parameters High Speed
SPBRG = 20 ' Set baud rate to 57600



TMR1L=0 ' Reset Timer
TMR1H=0 ' Remember Timer is OFF
pir1.2=0 ' Reset Capture Flag
pir1.0=0

CCP1CON = %00000101



clear










' Interrupt


INTCON = %11100000
PIE1=%00101011


ON INTERRUPT GoTo interr





mainloop:



' Main program



GoTo mainloop





' Interrupt Header


Disable

interr:




'********************************************
'Interrupt PWM


IF PIR1.1=1 Then ' TMR2 to PR2 interrupt flag
PIR1.1=0

' Interrupt routine



endif






'************************************
'Interrupt Velocità


If pir1.2=1 then
pir1.2=0

' Interrupt routine

endif



'************************************
'Interrupt TMR0


If INTCON.2=1 then


' Interrupt routine


INTCON.2=0
endif












'************************************
'Interrupt Network

IF PIR1.5=1 Then

' Interrupt routine

endif



Resume
Enable




the problem is that the interrupt routine are very slow ....
and i have problem tu use te CCP module, the measure are wrong....


there is another via to manage interrupt ???

mister_e
- 2nd February 2005, 18:29
we will be more than grateful if you can tell us wich PIC you're using ;)

Dwayne
- 2nd February 2005, 22:34
Hello Capitano,

C>>' Interrupt Header


Disable

interr:
<<


Just a quick glance through your code.. and I notice one thing....

Your disable is BEFORE your interupt label. It should be just after the interupt label..

interr:
Disable
...
....
...
Enable
return

capitano
- 3rd February 2005, 08:39
The PIC is 16F8777 at 20 Mhz

I try to change :

Disable
interr:

...
....
...
Enable
return

to

interr:
Disable
...
....
...
Enable
return

but i have problem to ccp module to capture period of 1 ms the measure are instable but without interrupt the measure are correctly



This program work fine


' Main Program Loop
' -----------------
Loop:
'
' Sample Section
' --------------
TMR1L=0 ' Reset Timer
TMR1H=0 ' Remember Timer is OFF
capture=0 ' Reset Capture Flag
CCP1CON = %00000100
' Enable the CCP1 capture, falling edge
While Capture=0:Wend
' Junk 1st Result
T1CON.0=1
' Enable Timer
capture=0 ' Reset Capture Flag
While Capture=0:Wend
' Wait for 2nd Result
period.lowbyte = CCPR1L
period.highbyte = CCPR1H
' Store the captured value in period variable
T1CON.0=0 ' Timer is OFF
CCP1CON=0 ' Capture is OFF

Hserout[period.highbyte,period.lowbyte]

pause 500


Goto Loop







This program don't work fine


INTCON = %11100000
PIE1=%00101111


ON INTERRUPT GoTo interr



mainloop:

' Main program

GoTo mainloop





' Interrupt Header


Disable

interr:



'********************************************
'Interrupt PWM


IF PIR1.1=1 Then ' TMR2 to PR2 interrupt flag
PIR1.1=0

' Interrupt routine



endif






'************************************
'Interrupt Period


If pir1.2=1 then
pir1.2=0

If state=0 then

T1CON.0=1 ' Enable Timer
pir1.2=0 ' Reset Capture Flag
state =1
CCP1CON = %00000101


else


' Store the captured value in period variable
T1CON.0=0 ' Timer is OFF
CCP1CON=0 ' Capture is OFF
Period.lowbyte = CCPR1L
Period.highbyte = CCPR1H
TMR1L=0 ' Reset Timer
TMR1H=0 ' Remember Timer is OFF
pir1.2=0 ' Reset Capture Flag
CCP1CON = %00000101
state=0

endif






endif



'************************************
'Interrupt TMR0


If INTCON.2=1 then


' Interrupt routine


INTCON.2=0
endif












'************************************
'Interrupt Network

IF PIR1.5=1 Then

' Interrupt routine

endif



Resume
Enable

mister_e
- 3rd February 2005, 14:00
Originally posted by Dwayne

Just a quick glance through your code.. and I notice one thing....

Your disable is BEFORE your interupt label. It should be just after the interupt label..


NOP, you must disable before the label an ENABLE after RESUME. it's in the PBP manual ;)

capitano

looks wierd... at this point i've never use CCP module and manage many interrupt together... interesting thread. I'll try something and let you know. BTW, i'm sure there's also somebody here who'll see the problem quick.



The PIC is 16F8777 at 20 Mhz

can we assume it's a 16F877 or a really brand new demo unknow at this point ;-)

Dwayne
- 3rd February 2005, 14:48
Hello Mister_e,

Hello Steve...Thanks for correcting me. I appreciate it.

I was looking through my philips books and it is just opposite of PBP for the PHilips chips <g>. Oh well...I will always learn something new every day.... and as I get older, I will learn more things in one day...because I forgot them yesterday...<g>

Dwayne