electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Problem with external interrupts


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Problem with external interrupts
Author Message
Swys



Joined: 22 Jul 2008
Posts: 11


Post06 Nov 2009 17:56   

Problem with external interrupts


I really hope someone can help me on this. I have to count pulses from an external source. For some reason, only the first pulse is counted. Can someone please have a look at my code to see what I am doing wrong?

I am using the MPLAB C18 compiler with a PIC18F13K50

Here are my interrupt functions:
Code:
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
   _asm
      GOTO high_isr
   _endasm
}
#pragma code

#pragma interrupt high_isr
void high_isr(void)
{
   if ((INTCONbits.INT0IF == 1) &  (INTCONbits.INT0IE == 1))
   {
      //Pulse received
      INTCONbits.INT0IF = 0;
      flow_int = 1;        //Flag indicating when interrupt occurred
      
      
      //PORTCbits.RC0 = 1;
   }
}



This is how my PIC is set up:

Code:
void SetupPIC(void)
{
   //Setup ports
   TRISA = 0x00;
   TRISB = 0x00;
   TRISC = 0x00;
   
   PORTA = 0;
   PORTB = 0;
   PORTC = 0;   
   
   //Disable all analog inputs
   ANSEL = 0x00;
   ANSELH = 0x00;
   
   //Setup USART
   TRISBbits.TRISB5 = 1;
   TRISBbits.TRISB7 = 1;
   
   //SetupUART();
   
   OpenUSART(   USART_TX_INT_OFF   &
            USART_RX_INT_ON      &
            USART_ASYNCH_MODE   &
            USART_EIGHT_BIT      &
            USART_CONT_RX      &
            USART_BRGH_HIGH,
            129);
            
   PIE1bits.RCIE = 1;      //Enable USART receive interrupt
   PIR1bits.RCIF = 0;      //Clear USART receive interrupt flag
   
   //Setup FRAM
   init_FRAM();
   
   //Setup ADC
   init_ADC();
   TRISCbits.TRISC6 = 0;
   
   //Setup Timers
   //Timer0
   T0CON = 0b00000111;      //Timer stopped;16-bit timer;
                     //Internal instruction cycle clock;
                     //Timer0 prescaler assigned;
                     //1:256 prescale value
   INTCONbits.TMR0IE = 1;   //Enable Timer0 interrupts
   INTCONbits.TMR0IF = 0;   //Clear Timer- interrupt flag
   
   //Setup external interrupts INT0 and INT1
   
   INTCONbits.INT0IF = 0;   //Clear the interrupt flag
   INTCONbits.INT0IE = 1;   //Enable external interrupt INT0
   INTCON2bits.INTEDG0 = 0;//Interrupt on the falling edge
   PORTCbits.RC0 = 1;      //Pull HIGH to create falling edge
                     //on contact
   
   INTCON3bits.INT1IE = 1;   //Enable external interrupt INT1
   INTCON2bits.INTEDG1 = 0;//Interrupt on the falling edge
   INTCON3bits.INT1IF = 0;   //Clear the interrupt flag
   PORTCbits.RC1 = 1;
   
   INTCONbits.PEIE = 1;   
   INTCONbits.GIE = 1;
   
}

In my main function, I am just checking the flow_int flag and outputting some text on the UART when the flag is set. Please help, since I don't have much time to solve this?

P.S. I've tried it with PORTCbits.RC0 = 1 and PORTCbits.RC0 = 0
Back to top
btbass



Joined: 20 Jul 2001
Posts: 1187
Helped: 113
Location: Oberon


Post06 Nov 2009 19:42   

Re: Problem with external interrupts


Maybe a silly question, but are you clearing the 'flow_int' flag after checking it in your main routine?
Back to top
Google
AdSense
Google Adsense




Post06 Nov 2009 19:42   

Ads




Back to top
Swys



Joined: 22 Jul 2008
Posts: 11


Post07 Nov 2009 8:49   

Re: Problem with external interrupts


Not silly, I've overlooked something like that quite a few times, but yes, I am clearing that flag
Back to top
btbass



Joined: 20 Jul 2001
Posts: 1187
Helped: 113
Location: Oberon


Post07 Nov 2009 10:37   

Re: Problem with external interrupts


I cant see where you have set up INT0, RC0 as an input?
Back to top
Swys



Joined: 22 Jul 2008
Posts: 11


Post07 Nov 2009 14:13   

Re: Problem with external interrupts


Thanks, that was the problem. I didn't realize it should be an input. I changed it...and it works!

Thanks guys!
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Problem with external interrupts
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Problem with interrupts (3)
MSP430F148. Problem with multiple interrupts in TimerB. (1)
HARDWARE INTERRUPTS AND SOFTWARE INTERRUPTS (8)
PROBLEM: Using interrupts in CCS and dsPIC & PIC24 (2)
Designing with Interrupts (2)
interrupts with mikroC (2)
How to solve the interrupts with little intermediat period? (2)
External RAM Problem (2)
problem in external Ram interface (1)
Passing External Enviroment Variable Problem (4)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS