Math error trap
by Microchip Technology
Microchip's 16-bit PIC24F microcontrollers feature an on-chip mechanism to detect software errors and take corrective action.
About this Code Example
Microchip's 16-bit PIC24F microcontrollers feature an on-chip mechanism to detect software errors and
take corrective action. Specifically, the ability to detect arithmetic (math) errors is provided by means of
automatic Math Error Trap detection.
Math error is caused by a Divide by Zero operation
If the application defines an Math Error Trap service routine (trap handler), the processor will vector to the
trap handler when it detects a math error.
NOTE: This routine also estimates the instruction that caused the math error trap to occur by examining the
PC value that is stored in the stack prior to entering the Math Error Trap. Since the instruction that causes
divide by zero error to occur is not executed, the stacked PC points to the offending instruction.
It should also be noted that since this trap routine is written in C the estimation of the stacked PC will
depend on the compiler optimization level set up for this file. In the trap routine presented here, a comiler
optimization level of 0 is assumed for this file.
The user should note that the MPLAB?C30 C compiler will not intentionally generate any instructions that
cause an arithmetic error trap to occur.
- Current Version: 1.0.0
- Updated: Jun 21, 2012
- Downloads: 897
- Status: Released
- MPLAB Version: V8.xx or above
- C Compiler: MCC18 v3.30 or above
- Development Tools: Explorer 16 Development Board
- Supported Devices: PIC24FJ128GA010
- There are no reviews for this Code Example.
- Math error trap (current version) June 21, 2012
- First Release to ECS