• AVR Freaks

Hot!External interrupt 2 problem

Author
RKS
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2019/11/25 04:31:12
  • Location: INDIA
  • Status: online
2020/02/14 02:52:57 (permalink)
0

External interrupt 2 problem

Hi everyone, 
I am facing problem in external interrupt 2. Square wave with 50% duty cycle is coming every 20 ms.My problem is first rising edge getting detected by controller and its going to ISR , But next rising edge on wards not detecting  and not going to ISR where could be problem. square wave i can  see on oscilloscope.
 
controller :-PIC18F46K22
compiler:-XC8
MPLAB X IDE
 
 
//code

#include<stdio.h>
#include<xc.h>
#include<p18cxxx.h>
#include"uart.h"


#define _XTAL_FREQ 64000000
#define CLEAR 0

#pragma config FOSC = INTIO67 //V2.7-3OC&EF
#pragma config WDTPS = 1024 //watchdog timer configured for 4s on 6dec12 16384 //8192 cmmented temporarily
#pragma config WDTEN = OFF //OFF //added temporarily
#pragma config CP0 = ON //V2.8
#pragma config CP1 = ON //V2.8
#pragma config CP2 = ON //V2.8
#pragma config CP3 = ON //V2.8
#pragma config PBADEN = OFF //V2.8
#pragma config BOREN = ON //V2.8
#pragma config BORV = 285 //for 46k22 //1 //BOR Voltage level 2.8V //for 46k22 //1 //BOR Voltage level 2.8V




void Global_Interrupt_Enable( void )
{
   RCONbits.IPEN = 1; //Enable priorities for intrrupts
   INTCONbits.GIE = 1; // set global intrupts
   INTCONbits.PEIE = 1; // Peripheral Interrupt Enable bit
}
 

void PIN_MANAGER_Initialize(void)
{
    TRISB = 0xFF; // make portB PIN as input
    INTCON2bits.RBPU=0; //enable PUll up resister this bit is required
    WPUB = 0xFF; //weak pull_up enable
    INTCON2bits.INTEDG2=1;
    INTCON3bits.INT2IE=1; ///enable the external interrupt1 bit
}
 
void interrupt IOC_INTERRUPT (void)
{
  if(INTCON3bits.INT2IF == 1) //checking IOC enable AND OVERFLOW FLAG BIT
 {
     uart_string("\r\n HII \r\n");
     LATAbits.LATA4=~LATAbits.LATA4;
     uart_string("\r\n HELLO \r\n");
     INTCON3bits.INT2IF=0;
  }
}
 
 
void main(void)
{

  OSCCONbits.IRCF0 = 1; //46k22 16 MHZ
  OSCCONbits.IRCF1 = 1;
  OSCCONbits.IRCF2 = 1;
  OSCTUNEbits.PLLEN = 1; //PLL enable bit

  TRISA=0x00; //use for checking purpose when interrupt occour
  ANSELA=0x00; //protC as digital pin

   uart_init(115200);

   Global_Interrupt_Enable();
   PIN_MANAGER_Initialize();


    while(1);
}
 
i can see output on serial terminal  like 
 
HII
HELLO
 
 
 
 
 
 
 
 
 
 
 
 
 
     
post edited by Microchip_RAM - 2020/02/14 02:57:27
#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 25632
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: External interrupt 2 problem 2020/02/14 06:00:42 (permalink)
    +1 (1)
    Not your problem, but you should NOT have this line
    #include<p18cxxx.h>
     
    xc.h has already included all the device specific declarations you need.
     
    You really should NOT call long slow functions like uart_string from inside an ISR. That's just asking for trouble.
    Can you show us the code for that function, as your interrupts sem to stop striaght after you call it.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    RKS
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2019/11/25 04:31:12
    • Location: INDIA
    • Status: online
    Re: External interrupt 2 problem 2020/02/14 20:58:51 (permalink)
    0
    Thank you ric,
     
    //code  uart part
     
    #include<xc.h>
    #include"uart.h"
     
    void uart_tx(unsigned char ch)
    {

        while(PIR3bits.TX2IF==0); /*wait for transmit interrupt flag*/
        TXREG2=ch;
    }
     
    void uart_string(char *s)
    {
       while(*s!='\0')
       {
         uart_tx(*s++);
       }
    }
     
     
     
    #3
    ric
    Super Member
    • Total Posts : 25632
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: External interrupt 2 problem 2020/02/14 21:03:09 (permalink)
    0
    What happens if you simplify your ISR down to just
    void interrupt IOC_INTERRUPT (void)
    {
      if(INTCON3bits.INT2IF == 1) //checking IOC enable AND OVERFLOW FLAG BIT
     {
         uart_tx('+');
         LATAbits.LATA4=~LATAbits.LATA4;
         INTCON3bits.INT2IF=0;
      }
    }

     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    RKS
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2019/11/25 04:31:12
    • Location: INDIA
    • Status: online
    Re: External interrupt 2 problem 2020/02/14 21:23:31 (permalink)
    0

    void interrupt IOC_INTERRUPT (void)
    {
      if(INTCON3bits.INT2IF == 1) //checking IOC enable AND OVERFLOW FLAG BIT
     {
         uart_tx('+');
         LATAbits.LATA4=~LATAbits.LATA4;
         INTCON3bits.INT2IF=0;
      }
    }

     
    '+' one time printing
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5