dsPIC trap

Post Reply
Author
Message
cmiguens
Posts: 10
Joined: 20 Sep 2011 17:00

dsPIC trap

#1 Post by cmiguens » 02 Dec 2020 20:45

Hello, I am testing a math error trap (I cause a division by zero. See code below). I find that the Trap Service Routine executes first and then it is executed the instruction that performs division by zero (3). I have tested the following code on an esay24-33 v6 development board. Each time the button connected to RA6 is pressed, the alfa value decreases. When alfa = 0, a trap occurs and instructions (1) and (2) are executed before instruction (3). But the value of alfa and LATB in the interrupt service routine of INT2 does not change with the execution of the trap service routine. Can you explain to me what is due?. If the operation is correct, what is the use of the trap if from the trap service routine it is not possible to change the alfa value or the LATB value?
Thank you very much

//P24F16KA102, easy24-33 v6

unsigned int alfa = 4;

void INT2_interrupt() org 0x00004E
{
alfa--;
LATB = 20/alfa; //(3)
IFS1.INT2IF = 0;
}


void Math_Error_interrupt() org 0x00000C
{
alfa = 6; //(1)
LATB = 0x0001; //(2)
INTCON1.B4 = 0;
}


void main()
{
CLKDIV = 0x0000; //FRC (Fast RC Oscillator)
AD1PCFG = 0x1C3F;
TRISA = 0xFFFF;
TRISB = 0x0000;
LATB = 0x0000;

INTCON2.INT2EP = 0;
IFS1.INT2IF = 0;
IPC7.INT2IP0 = 1;
IPC7.INT2IP1 = 0;
IPC7.INT2IP2 = 0;
IEC1.INT2IE = 1;

INTCON1 = 0;

while(1)
asm nop;
}

Post Reply

Return to “dsPIC Compilers General”