Hello,
I added a page in the Articles section of the Wiki on interrupts. Any feed back and edits/corrections would be appreciated.
http://www.sfcompiler.co.uk/wiki/pmwiki ... Interrupts
-Tom
Interrupts tips and observations
Moderators: David Barker, Jerry Messina
Interrupts/events
Tom,
This is great stuff, I am trying to digest it! An example showing the use of events to handle multiple interrupts would be extremely helpful.
Gordon
This is great stuff, I am trying to digest it! An example showing the use of events to handle multiple interrupts would be extremely helpful.
Gordon
Multiple interrupts
Tom,
I want to thank you again for organizing this. Using the approach you suggest, I now have three interrupts going simultaneously, all high priority.
Here is the core piece of code- is this how you were suggesting it should be done?
Obviously, the events are in the separate modules.
Module MyInts
Const
ipLow = 1,
ipHigh = 2
Include "MyRx.bas"
Include "MyTimer.bas"
Include "USART.bas"
Include "MyPortB.bas"
Interrupt ISR(ipHigh) ' High Priority ISR code
If (RCIE=1) And (RCIF=1) Then ' USART interrupt code
MyRX.FOnDataEvent()
EndIf
If (Timer1IF=1) And (Timer1IE=1) And (Timer1On=1) Then ' TIMER 1 interrupt code
Timer1 = Timer1 + Word(TimerValue) ' Force integer arithmetic
Dec(TimerCounter)
MyTimer.FOnTimerEvent()
Timer1IF = 0
End If
If (INT0IF=1) And (INT0IE=1) Then ' RB0 interrupt code
MyPortB.FOnInt0Event()
INT0IF=0
End If
End Interrupt
Public Sub Initialize()
MyRX.ActivateRX()
MyTimer.ActivateTimer()
MyPortB.ActivateInt0()
Enable(ISR)
End Sub
I want to thank you again for organizing this. Using the approach you suggest, I now have three interrupts going simultaneously, all high priority.
Here is the core piece of code- is this how you were suggesting it should be done?
Obviously, the events are in the separate modules.
Module MyInts
Const
ipLow = 1,
ipHigh = 2
Include "MyRx.bas"
Include "MyTimer.bas"
Include "USART.bas"
Include "MyPortB.bas"
Interrupt ISR(ipHigh) ' High Priority ISR code
If (RCIE=1) And (RCIF=1) Then ' USART interrupt code
MyRX.FOnDataEvent()
EndIf
If (Timer1IF=1) And (Timer1IE=1) And (Timer1On=1) Then ' TIMER 1 interrupt code
Timer1 = Timer1 + Word(TimerValue) ' Force integer arithmetic
Dec(TimerCounter)
MyTimer.FOnTimerEvent()
Timer1IF = 0
End If
If (INT0IF=1) And (INT0IE=1) Then ' RB0 interrupt code
MyPortB.FOnInt0Event()
INT0IF=0
End If
End Interrupt
Public Sub Initialize()
MyRX.ActivateRX()
MyTimer.ActivateTimer()
MyPortB.ActivateInt0()
Enable(ISR)
End Sub
Yes, basically enable the interrupts you want using conditionals.
It took over a month to get this all sorted out and the code we created was pretty complicated but it works. Unfortunately, some of the code is not mine thus I couldn't post it. It would take a long time to paraphase it for a working example as well, and we are behind schedule in our project as it is.
Since we could "reuse" the two interrupts, we were able to keep using the 18F instead of having to lose 5 months of Swordfish work and move the project to a PIC 24F and a C compiler. We still filled the 96K memory but thankfully were able to move it to a compatible 128K part in the same family.
-Tom
It took over a month to get this all sorted out and the code we created was pretty complicated but it works. Unfortunately, some of the code is not mine thus I couldn't post it. It would take a long time to paraphase it for a working example as well, and we are behind schedule in our project as it is.
Since we could "reuse" the two interrupts, we were able to keep using the 18F instead of having to lose 5 months of Swordfish work and move the project to a PIC 24F and a C compiler. We still filled the 96K memory but thankfully were able to move it to a compatible 128K part in the same family.
-Tom