Microchip Technology SW006021-1N 用户手册
How To’s
2012 Microchip Technology Inc.
DS52053B-page 63
3.6.6
How Can I Make My Interrupt Routine Faster?
Consider suggestions made in Section 3.6.2 “How Can I Make My Code Smaller?”
(code size) for any interrupt code. Smaller code is often faster code.
(code size) for any interrupt code. Smaller code is often faster code.
In addition to the code you write in the ISR there is the code the compiler produces to
switch context. This is executed immediately after an interrupt occurs and immediately
before the interrupt returns, so must be included in the time taken to process an inter-
rupt, see Section 5.9.3 “Context Switching”. This code is optimal in that only regis-
ters used in the ISR will be saved by this code. Thus, the less registers used in your
ISR will mean potentially less context switch code to be executed.
switch context. This is executed immediately after an interrupt occurs and immediately
before the interrupt returns, so must be included in the time taken to process an inter-
rupt, see Section 5.9.3 “Context Switching”. This code is optimal in that only regis-
ters used in the ISR will be saved by this code. Thus, the less registers used in your
ISR will mean potentially less context switch code to be executed.
Mid-range devices have only a few registers that are used by the compiler, and there
is little context switch code. Even fewer registers are considered for saving when com-
piling for enhanced mid-range device. PIC18 devices will benefit most from the above
suggestion as they use a larger set of registers in generated code, see Section 5.7
“Register Usage”.
is little context switch code. Even fewer registers are considered for saving when com-
piling for enhanced mid-range device. PIC18 devices will benefit most from the above
suggestion as they use a larger set of registers in generated code, see Section 5.7
“Register Usage”.
Generally simpler code will require less resources than more complicated expressions.
Use the assembly list file to see which registers are being used by the compiler in the
interrupt code, see Section 6.6 “Assembly List Files”.
Use the assembly list file to see which registers are being used by the compiler in the
interrupt code, see Section 6.6 “Assembly List Files”.
Consider having the ISR simply set a flag and return. The flag can then be checked in
main-line code to handle the interrupt. This has the advantage of moving the compli-
cated interrupt-processing code out of the ISR so that it no longer contributes to its reg-
ister usage. Always use the volatile qualifier (see Section 5.4.7.2 “Volatile Type
Qualifier”for variables shared by the interrupt and main-line code, see Section 3.5.5
“How Do I Share Data Between Interrupt and Main-line Code?”.
main-line code to handle the interrupt. This has the advantage of moving the compli-
cated interrupt-processing code out of the ISR so that it no longer contributes to its reg-
ister usage. Always use the volatile qualifier (see Section 5.4.7.2 “Volatile Type
Qualifier”for variables shared by the interrupt and main-line code, see Section 3.5.5
“How Do I Share Data Between Interrupt and Main-line Code?”.
3.6.7
How Big Can C Variables Be?
This question specifically relates to the size of individual C objects, such as arrays or
structures. The total size of all variables is another matter.
structures. The total size of all variables is another matter.
To answer this question you need to know in which memory space the variable will be
located. Objects qualified const will be located in program memory; other objects will
be placed in data memory. Program memory object sizes are discussed in
Section 5.5.3.1 “Size Limitations of Const Variables”. Objects in data memory are
broadly grouped into autos and non-autos and the size limitations of these objects,
respectively, are discussed in Section 5.5.2.3 “Size Limits of Auto Variables” and
Section 5.5.2.1.2 “Non-Auto Variable Size Limits”.
located. Objects qualified const will be located in program memory; other objects will
be placed in data memory. Program memory object sizes are discussed in
Section 5.5.3.1 “Size Limitations of Const Variables”. Objects in data memory are
broadly grouped into autos and non-autos and the size limitations of these objects,
respectively, are discussed in Section 5.5.2.3 “Size Limits of Auto Variables” and
Section 5.5.2.1.2 “Non-Auto Variable Size Limits”.
3.6.8
What Optimizations Will Be Applied to My Code?
The optimizations in OCG compilers can broadly be broadly grouped into C-level and
assembly level optimizations. These are described in Section 5.13 “Optimizations”
and can be controlled by he option detailed in Section 4.8.42 “--OPT: Invoke Com-
piler Optimizations”.
assembly level optimizations. These are described in Section 5.13 “Optimizations”
and can be controlled by he option detailed in Section 4.8.42 “--OPT: Invoke Com-
piler Optimizations”.
3.6.9
How Do I Utilize All the RAM Banks on My Device?
The compiler will automatically use all the available RAM banks on the device you are
programming. It is only if you wish to alter the default memory allocation that you need
take any action. Special bank qualifiers, see Section
“--RAM=default,+20000-2FFFF.”, and an option (see Section 4.8.16 “--ADDRQUAL:
Set Compiler Response to Memory Qualifiers”) to indicate how these qualifiers are
interpreted are used to manually allocate variables.
programming. It is only if you wish to alter the default memory allocation that you need
take any action. Special bank qualifiers, see Section
“--RAM=default,+20000-2FFFF.”, and an option (see Section 4.8.16 “--ADDRQUAL:
Set Compiler Response to Memory Qualifiers”) to indicate how these qualifiers are
interpreted are used to manually allocate variables.
Note that there is no guarantee that all the memory on a device can be utilized as data
and code is packed in sections, or psects.
and code is packed in sections, or psects.