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.

interrupt in dsPIC30F

Status
Not open for further replies.

faysal_002299

New Member
Dear All,
I am a newbie. I am using dsPIC30F3011 interrupts. Problem is, say I have activated the ISR of int0 only, but that ISR of int0 always gets activated if I input (no matter 0 or 1) something in any other interrupts pins or some other pins of the MCU which has no relation with interrupt. Even the ISR is called if I touch those pins with any metal in stead of any 1/0 input.

This is the code I am using-

Code:
void InitINT(void)
{
 INTCON2=0x0001;         //the result is same whether I set 1 or 0 here

 //External Interrupt 0
 IEC0bits.INT0IE=1;        //enable INT0 ISR
 IFS0bits.INT0IF=0;        //clear INT0 interrupt flag
 IPC0bits.INT0IP = 4;      // interrupt priority

 return;
}

void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void)
{
 SendData('e');             // Send this to PC
IFS0bits.INT0IF=0;        //clear INT0 interrupt flag
}


Please tell me all the possible reasons (in both firmware and hardware parts) behind it so that I can troubleshoot

with thanks,
 
Even the ISR is called if I touch those pins with any metal in stead of any 1/0 input.

I have not used dsPIC but some general ideas that might help you:
- check if you enabled only the interrupt you want triggered
- check if you set the interrupt to trigger on the proper edge (rising or falling)
- be sure to use pull up/down on the interrupt pin and not leave it floating


The behaviour you experienced (touch pins with any metal ..) lead me to believe that the floating pin is the problem ... pull the input pin up with 10K resistor and short to ground in order to trigger the interrupt or push down with 10K resistor and short to vcc to trigger the interrupt...
 
lol a intterupt generates on EDGE not on 1 or 0 really. You have to check your self if its high or low. You can trigger it on FALLING or RISING edge . A Logical 1 can be anything remember a HIGH Voltage or a Long one. A zero can be a Low Voltage or a HIGH short pulse.

You get it?

Here is my sample code tested to work:
Code:
#include "p30F4013.h"
//#include <p30fxxxx.h>

_FOSC(FRC_PLL4);
_FWDT(WDT_OFF)
_FBORPOR(MCLR_EN & PWRT_OFF)  
_FGS(CODE_PROT_OFF)    


void INT_Init(void);
void __attribute__((__interrupt__)) _INT0Interrupt(void);

#define SW1 PORTAbits.RA11
char isSet;

int main(void)
{
    isSet = 0;    
    TRISB = 0;
    LATB = 0;

    INT_Init();

    while(1)
    {
        if(isSet == 1)
            LATBbits.LATB0 = 1;
        else
            LATBbits.LATB0 = 0;

    }
}

void INT_Init(void)
{
        INTCON2 = 0x0001;       //Setup INT0 pin to interupt on falling edge
        IFS0bits.INT0IF = 0;    //Reset INT0 interrupt flag
        IEC0bits.INT0IE = 1;    //Enable INT0 Interrupt Service Routine

        TRISAbits.TRISA11 = 1;
}

void __attribute__((__interrupt__)) _INT0Interrupt(void)
{
        while (SW1 == 1); 

        if(isSet == 0)
            isSet = 1;
        else
            isSet = 0;

        IFS0bits.INT0IF = 0;
}

EDIT Just noticed ... did you set it to input? (the pin)
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top