Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Its a trap....

Status
Not open for further replies.

granddad

Well-Known Member
Most Helpful Member
Let me say , my C code implementation is not ‘good’ It would make a ‘pro’ cry.. I’m using MPLABX 5.45 and XC16 1.60
I was about to ask ETO for help. Then realized after some hours ! I had the problem before and had found my error, but then promptly forgot. Basically my dsPIC33EV code compiled without errors. and ran in Debug till it hit the error line. ( a missing argument on an array .. char Loco_register[9][16]; )then halted with little indication why.

The STACK window reported

No source code lines were found at current PC ( some Hex address). Open program memory view to see.

The memory view of the address and line number was little help , just a BREAK and RESET inserted by the compiler I guess.
#include “traps.c” was what I was missing. Now I see an Address Error trap, had halted the run . And lead me to my amateur error .

Thought I would post anyway..
C:
/***********************************************************************
 * This file provides a basic template for writing dsPIC30F trap       *
 * handlers in C language for the C30 compiler                         *
 *                                                                     *
 * Add this file into your MPLAB project. Build your project, program  *
 * the device and run. If any trap occurs during code execution, the   *
 * processor vectors to one of these routines.                         *
 *                                                                     *
 * For additional information about dsPIC architecture and language    *
 * tools, refer to the following documents:                            *
 *                                                                     *
 * MPLAB C30 Compiler User's Guide                        : DS51284    *
 * dsPIC 30F MPLAB ASM30, MPLAB LINK30 and Utilites                    *
 *                                           User's Guide : DS51317    *
 * Getting Started with dsPIC DSC Language Tools          : DS51316    *
 * dsPIC 30F Language Tools Quick Reference Card          : DS51322    *
 * dsPIC 30F 16-bit MCU Family Reference Manual           : DS70046    *
 * dsPIC 30F General Purpose and Sensor Families                       *
 *                                           Data Sheet   : DS70083    *
 * dsPIC 30F/33F Programmer's Reference Manual            : DS70157    *
 *                                                                     *
 * Template file has been compiled with MPLAB C30 v3.00.               *
 *                                                                     *
 ***********************************************************************
 *                                                                     *
 *    Author:                                                          *
 *    Company:                                                         *
 *    Filename:       traps.c                                          *
 *    Date:           04/11/2007                                       *
 *    File Version:   3.00                                             *
 *    Devices Supported:  All PIC24F,PIC24H,dsPIC30F,dsPIC33F devices  *
 *                                                                     *
 **********************************************************************/

#ifdef __dsPIC30F__

        #include "p30fxxxx.h"

#endif

#ifdef __dsPIC33F__

        #include "p33Fxxxx.h"

#endif

#ifdef __PIC24F__

        #include "p24Fxxxx.h"

#endif

#ifdef __PIC24H__

        #include "p24Hxxxx.h"

#endif


#define _trapISR __attribute__((interrupt,no_auto_psv))

/* ****************************************************************
* Standard Exception Vector handlers if ALTIVT (INTCON2<15>) = 0  *
*                                                                 *
* Not required for labs but good to always include                *
******************************************************************/
void _trapISR _OscillatorFail(void)
{

        INTCON1bits.OSCFAIL = 0;
        while(1);
}

void _trapISR _AddressError(void)
{

        INTCON1bits.ADDRERR = 0;
        while(1);
}

void _trapISR _StackError(void)
{

        INTCON1bits.STKERR = 0;
        while(1);
}

void _trapISR _MathError(void)
{

        INTCON1bits.MATHERR = 0;
        while(1);
}




/* ****************************************************************
* Alternate Exception Vector handlers if ALTIVT (INTCON2<15>) = 1 *
*                                                                 *
* Not required for labs but good to always include                *
******************************************************************/
void _trapISR _AltOscillatorFail(void)
{

        INTCON1bits.OSCFAIL = 0;
        while(1);
}

void _trapISR _AltAddressError(void)
{

        INTCON1bits.ADDRERR = 0;
        while(1);
}

void _trapISR _AltStackError(void)
{

        INTCON1bits.STKERR = 0;
        while(1);
}

void _trapISR _AltMathError(void)
{

        INTCON1bits.MATHERR = 0;
        while(1);
}
 
Last edited:
It took me 4 hours to get MPLABX and XC8 installed :D, then another hour to install and get MCC generator added. But I do like the code generator, its handy to read through the code and see how they set things up.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top