external interrupts + RTCC internal interrupts
Hallo everybody,
I have a dubt about interrupt configuration. I need to fix a SX28p to accept 3 external signal (from 3 proximity sensors). For every edge I have to check a counter value to define the time between pulses.
I got the following code from SX-KEY help file. I think this is enough to detect the external pulses from the sensors.
Now I don't know How can I use the internal interrupts to incremement the counters (counter1, counter2 and counter3: 1 for each sensor).
In SX-KEY help file I found the following code to repeat a function a specific times for second:
How can I have both kind of interrupts in one program??? I'm not sure I can do this.
Any help will be apreciate.
Thanks in advance
Loojade
I have a dubt about interrupt configuration. I need to fix a SX28p to accept 3 external signal (from 3 proximity sensors). For every edge I have to check a counter value to define the time between pulses.
I got the following code from SX-KEY help file. I think this is enough to detect the external pulses from the sensors.
' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "ISRPORTB" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Buttons VAR RB ' button inputs TRIS_Btns VAR TRIS_B ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- sensor VAR Byte ' sensor conneted to RB.0, RB.1 and RB.2 A VAR Word counter1 VAR Word counter2 VAR Word counter3 VAR Word ' ------------------------------------------------------------------------- INTERRUPT ' ------------------------------------------------------------------------- ISR_Start: WKPND_B = sensor ' get which sensor cause the pulse Ch1: ' check channel IF sensor <> %0001 THEN Ch2 ' if not, try next A=counter1 counter1=0 GOTO ISR_Exit Ch2: IF sensor <> %0010 THEN Ch3 A=counter2 counter2=0 GOTO ISR_Exit Ch3: IF sensor <> %0100 THEN Ch4 A=counter3 counter3=0 GOTO ISR_Exit ISR_Exit: WKEN_B = %11111111 ' no ISR until reset RETURNINT ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: WKPND_B = %00000000 ' clear pending WKED_B = %00000111 ' falling edge detect WKEN_B = %11111000 ' use bits 0..3 for inputs END
Now I don't know How can I use the internal interrupts to incremement the counters (counter1, counter2 and counter3: 1 for each sensor).
In SX-KEY help file I found the following code to repeat a function a specific times for second:
' ------------------------------------------------------------------------- INTERRUPT 77_000 ' ------------------------------------------------------------------------- ISR_Start: INC counter1 INC counter2 INC counter3 RETURNINT
How can I have both kind of interrupts in one program??? I'm not sure I can do this.
Any help will be apreciate.
Thanks in advance
Loojade
Comments
There are much more efficient ways to do this, but hopefully the above is clear enough that you get the basic idea. Others may have much cleverer suggestions as well.
Remember too that WKPEND is set whether or not you are using it to trigger an interrupt, so you could check (and deal with results of, and clear) WKPEND each time through the regular interrupt. The biggest issue is sample rate -- you want the regular interrupt to check the edges often enough that you won't miss an edge change while you are dealing with an edge change (i.e., the interrupt needs to run much faster than the possible fastest edge changes so that the interrupt runs and is done before the next possible edge change comes). There are ways around that too, and others have posted some pretty clever code in that regard, but hopefully this will get you started.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 2/17/2008 6:48:02 PM GMT
I'm sorry for all my questions...
Actually for beginners with SX (like me) it's difficult to learn about SXB. The documentation about SX assembly is very complete but I's not the same regarding SXB. For this reason many time I need to ask many things to forum users.
Anyway... this is my question: When I use PAUSE (or PAUSEUS) in my code (for example in main code), the SX is able to answer to interrupt requests or even interrupts routines are stoped???
Basically I would like to use PAUSE in main program but I would like to keep interrupts routines working well too. It's possible??
One more question: If the code included in interrupt routines take more time that interval between 2 interrupts call, what happen?
I would have a interrupts routine 50000 time per second (by INTERRUPT 50_000) , but if routine code take more time than minimum available the next interrupt call will be delayed or ... what???
Thanks in advance for your help
If the interrupt code takes too long, you will miss an interrupt. The RTCC will have to wrap around again to trigger the next interrupt.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
About my second question.. this mean that when the code is too long, simply the next interrupt call will not execute.
My problem is the following: Normally the interrupts must check (50_000 time per second = 20 uSec) the state of 2 sensors (working freq max = 350 Hz) and 2 buttons for user interface. Some time a user can press a button to save some data in external eeprom and display some value to LCD. This procedure can take (I think) more than 20 uSec. So If every time this happen (user press a button) simply the next interrupt call will not execute, is very good!!! Basically I don't need a good accuracy when the user is managing the ECU by buttons, but I need it when the ECU is far away from user...
Everytime you are very kind.
Check out the Nuts n Volts articles from the last 6 months or so -- there are lots of good SX/B examples of doing this.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php