 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Remko
Joined: 24 Sep 2003 Posts: 14
|
|
Posted: Tue Jun 27, 2006 7:21 am |
|
|
Hello Ttelmah,
Thank you very much for you help. I have to go through a few projects now to check these things.
I have checked the pieces of programs where it went wrong and it all fits. The FSR0L and H and 01, 02 and 03 are also used on that part of the program. It is nice to see where and why it goes wrong. Thanks again.
What about the scratch memory. Is it possible to tell the compiler to use a little memory range for scratch in one function (the isr) and use another range of memory for scratch in the other functions. What I mean is, when I let the compiler make the IRS by not using the #GLOBAL but the #INT_xxx, the compiler saves 00 till 04 to tempory addresses 0F till 13. This costs 5 plus another 5 memory addresses for scratch and it costs 10 MOVFF instructions extra. The compiler 'knows' when a function is an isr function by the #INT_xxx command. So why not using the memory 0F till 13 for the ISR and use the 00 till 04 for the rest. It uses the same memory but it saves 10 MOVFF instructions whitin the isr which has to be as quick as possible.
Also my thoughts about the FSR's, the compiler also 'knows' which FSR's are used within the ISR. A function call within the ISR is blocked by the compiler with the error: unprotected call. So why not saving only the registers used by the ISR to speed up the ISR.
regards,
Remko |
|
 |
Ttelmah Guest
|
|
Posted: Tue Jun 27, 2006 8:19 am |
|
|
I must admit, the latter is a 'wish list' item, for many people. It would seem relatively easy to have a 'table' of resources like the FSR's, and for every routine, calculate which are used, and only save the ones that are actually used inside the interrupt.
The scratch is not quite so simple. The problem is that a simple move, of a byte to/from a particular fixed location, is a single word instruction. Doing it to two different locations, would involve either having 'indexed' addressing (which is a lot slower and bulkier), or generating two copies of the routines. In some cases, you can generate two copies (for instance, if you declare a seperate '#use delay', in front of the interrupt routines), but doing it for everything would be bulky.
Best Wishes |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Jun 27, 2006 8:28 am |
|
|
| Have you even tried the default interrupt handlers? Just briefly looking at you receive interrupt, its huge so I don't see how the compiler's handler could cause you a problem. Why not receive the serial data into a buffer and process it in main() and just use the default int handler. |
|
 |
Remko
Joined: 24 Sep 2003 Posts: 14
|
|
Posted: Tue Jun 27, 2006 8:41 am |
|
|
Hello Mark,
I understand your question and I agree. My 'receive' must be very quick but I mean my RF receiver on 868MHz, not my RS232 receiver. I agree my RS232 receiver is to big but it has grown from earlier versions and I have to stay compatible. I am going to change the RS232 isr in this version but I had to understand what went wrong with my ISR. The problem went away when I made a simple buffer and process it in main() but I could not generate the faults anymore to find out what the real problem was.
Yes I have tried the default interrupt handlers, it helped me to understand what Ttelmah ment. It showed me the overhead what it makes but also the mistakes I can make and how I have to pay attention when I change the isr.
Thanks for the reply.
(My next code will look like:
| Code: | if (RCIE) {
while (RCIF) {
string2[PutRs232_i] = RCREG;
PutRs232_i++;
} // end while (RCIF) {
} // end if (RCIE) |
with a rs232 ring buffer of 256) |
|
 |
Ttelmah Guest
|
|
Posted: Tue Jun 27, 2006 8:42 am |
|
|
Yes.
I think though that it is another interrupt that he actually wants to handle quickly. However using 'high' for this would seem worth considering if this is the case.
I did a similar thing some time ago, when I wanted a quadrature interrupt, a timer interrupt, and RS232 interrupts. My 'global', was:
| Code: |
/* There is a major problem with the PIC18F252. If the 'high priority'
interrupt is used for an asynchronous event (like the quadrature
signal), it can result in damage to the stack.
Unfortunately, swapping the interrupt use, won't work, since then
another function could interrupt this code, preventing the 'fast register
stack' from being used in this routine.
Hence I bodge round the problem, by writing my own 'two stage'
interrupt handler. The handler checks if the source is the quadrature
interrupt, and if so executes this, and exits using the fast stack. If
not, it then saves the other registers, and tests for the other interrupts.
This way, the latency on the quadrature interrupt is kept as low as
possible.
*/
#int_global
void myint(void) {
static int INT_scratch[10];
#ASM
//Here for maximum speed, I test the RB interrupt - since it is allways
//enabled, I don't have to test the enable bit
BTFSS INTCON,RBIF
GOTO NXT
#endasm
quad(); //Quadrature handler.
#asm
BCF INTCON,RBIF
GOTO FEXIT //Use the fast stack for exit
NXT:
//Now I save the registers for the other interrupt handlers
MOVFF FSR0L,INT_scratch
MOVFF FSR0H,INT_scratch+1
MOVFF FSR1L,INT_scratch+2
MOVFF FSR1H,INT_scratch+3
MOVFF FSR2L,INT_scratch+4
MOVFF FSR2H,INT_scratch+5
MOVFF scratch,INT_scratch+6
MOVFF scratch1,INT_scratch+7
MOVFF scratch2,INT_scratch+8
MOVFF scratch3,INT_scratch+9
//Test for the external interrupt (power about to fail).
BTFSS INTCON,INT0E
GOTO NEXTA
BTFSC INTCON,INT0
#endasm
pfail();
#asm
NEXTA:
//Now for Timer 2
BTFSS PIE1,TMR2
GOTO NEXT1
BTFSC PIR1,TMR2
#endasm
TIMER2_isr();
#asm
NEXT1:
//Receive data available
BTFSS PIE1,RCIE
GOTO NEXT2
BTFSC PIR1,RCIE
#endasm
RDA_isr();
#asm
NEXT2:
//Transmit buffer empty
BTFSS PIE1,TXIE
GOTO EXIT
BTFSC PIR1,TXIE
#endasm
TBE_isr();
#asm
EXIT:
//Restore registers
MOVFF INT_scratch,FSR0L
MOVFF INT_scratch+1,FSR0H
MOVFF INT_scratch+2,FSR1L
MOVFF INT_scratch+3,FSR1H
MOVFF INT_scratch+4,FSR2L
MOVFF INT_scratch+5,FSR2H
MOVFF INT_scratch+6,scratch
MOVFF INT_scratch+7,scratch1
MOVFF INT_scratch+8,scratch2
MOVFF INT_scratch+9,scratch3
//Here the 'fast' exit.
FEXIT:
RETFIE 1
#ENDASM
}
|
I suspect the approach required is something similar.
Best Wishes |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Jun 27, 2006 8:49 am |
|
|
| Remko wrote: | Hello Mark,
I understand your question and I agree. My 'receive' must be very quick but I mean my RF receiver on 868MHz, not my RS232 receiver. I agree my RS232 receiver is to big but it has grown from earlier versions and I have to stay compatible. I am going to change the RS232 isr in this version but I had to understand what went wrong with my ISR. The problem went away when I made a simple buffer and process it in main() but I could not generate the faults anymore to find out what the real problem was.
Yes I have tried the default interrupt handlers, it helped me to understand what Ttelmah ment. It showed me the overhead what it makes but also the mistakes I can make and how I have to pay attention when I change the isr.
Thanks for the reply.
(My next code will look like:
| Code: | if (RCIE) {
while (RCIF) {
string2[PutRs232_i] = RCREG;
PutRs232_i++;
} // end while (RCIF) {
} // end if (RCIE) |
with a rs232 ring buffer of 256) |
You will need to save different registers based on what you are doing. By keeping it simple, you will need to save less. Accessing a single dimension array is much easier than a multi-dim one and is most likely why it worked. Keep things short and sweet. Do as little as possible in the interrupt. Examine what registers are used and then modify the CCS routine to suit what registers you actually use. |
|
 |
Remko
Joined: 24 Sep 2003 Posts: 14
|
|
Posted: Tue Jun 27, 2006 1:40 pm |
|
|
Thank you all very much. It is much clearer now and I have learned a lot.
Best regards,
Remko |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|