Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C18 - 18f2550 RB0 external interrupt error?

Status
Not open for further replies.

bayabi

Newbie level 6
Joined
Jan 28, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,392
Hello there
I have the following code in order to drive my step motor and use some functions I want to implement. However; whenever it is supposed to undergo interrupt part, it does not work and stops right there? I want to use RB0 pin s external interrupt feature. I dont want to use interrupt priority, thus I didnt define interrupt_high_vector nor low_vector:

*Is it because I forgot to include some header files?
*Or I define interrupt incorrectly?
*Or is there another way to use RB0 interrupt that i am missing?
*Or do i have to define interrupt_high and interrupt_low even if i dont use priority?



#include <p18cxxx.h>
#include <delays.h>
#include "..\usb\typedefs.h"
//-----------------------------
#pragma config CPUDIV = OSC1_PLL2,PLLDIV = 5,USBDIV = 2
#pragma config FOSC = HSPLL_HS,IESO = OFF
#pragma config PWRT = OFF,BOR = OFF,VREGEN = ON
#pragma config WDT = OFF,MCLRE = OFF,LPT1OSC = OFF
#pragma config PBADEN = OFF,LVP = OFF
static BOOL optCnt = TRUE;
//byte const step[4] = {0xAA,0x99,0x55,0x66}; //sag=1, sol=0
byte const step[4] = {0x33,0xAA,0xCC,0x55};

void inter(void);
void MotorSur(int Adim,int Yon);
void SetOutput(byte output);
void hassas_ayar();

#pragma interrupt inter

void inter(void)
{
INTCONbits.INT0IF = 0;
INTCONbits.GIE = 0;
hassas_ayar();


//hassas_ayar();


}

void hassas_ayar()
{
while (PORTBbits.RB0 == 0 && optCnt )
{
MotorSur(8,1); //sağa 5 adım
}

while (PORTBbits.RB0 == 1 && optCnt )
{
MotorSur(5,0); //sola 1 adım
}
optCnt =FALSE;
}

void send_to_left()
{
MotorSur(50,0); //sola 50 adım
}


void main (void)
{
TRISB = 0x01;
ADCON1 = 0xFF;
TRISA = 0x00;
if (PORTBbits.RB0 == 1)
{

INTCONbits.GIE = 1;
INTCONbits.INT0IE = 1;
INTCONbits.INT0IF = 0;
INTCON2bits.INTEDG0 = 0;



while(optCnt)
{
send_to_left();
}

}
else if(PORTBbits.RB0 == 0)
{
hassas_ayar();

}

}



void MotorSur (int Adim,int Yon)
{
int i;
if (Yon == 1)
{
for(i = Adim; i>0; i--)
{
byte output = step[i%4];
SetOutput(output);
Delay10KTCYx(2);
SetOutput(0x00);
Delay10KTCYx(2);
}

}
else if (Yon == 0)
{
for(i = 0; i<Adim; i++)
{
byte output = step[i%4];
SetOutput(output);
Delay10KTCYx(2);
SetOutput(0x00);
Delay10KTCYx(2);
}
}

}


The code continues but important part for me is the interrupt part

Thanks for your attention :)
 

Hi,

May be you program stuck inside ISR (in a loop ? waiting some input ?....). Simulate your code and find it properly exit from ISR.

Thank you,
 
  • Like
Reactions: bayabi

    bayabi

    Points: 2
    Helpful Answer Positive Rating
yep I debug it via proteus.. It does activates interrupt however it does not runs the code inside interrupt function. What should I do to solve this problem?
 

Hi,
Is it correctly enter to ISR ?
Correctly identify your intended itnerrupt.( may be some other interrupt can trigger ISR, check it)
Check the logic inside it; may be you have incorrect logic there.

Thank you,
 
  • Like
Reactions: bayabi

    bayabi

    Points: 2
    Helpful Answer Positive Rating
Thank you for your care it is ISR problem as you said
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top