• AVR Freaks

AnsweredHot!External Interrupt PIC24FJ128GA204

Author
NCosta
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2021/01/12 10:31:14
  • Location: 0
  • Status: offline
2021/01/19 10:05:34 (permalink)
0

External Interrupt PIC24FJ128GA204

I am trying to use a external interruption with a swich button RC9 (Pin 5) and ther is no way to work. I look everywhere for the problem and i didn't find it. The program seems not to enter on the interruption.
Anyone can help me?
 
#include "xc.h"

int main(void) {
    SetInterrupt();
    while(1){
        
    }

}

void SetInterrupt(void){
    TRISC|=(1<<9); //input switch botton
    TRISC&=~(1<<6); //output led
    LATC&=~(1<<6); // logic value 0 to led
    RPINR0bits.INT1R = 5; //set the switch botton as the trigger of interruption
                          // RC9 corresponds to pin 5
   
    IPC5bits.INT1IP = 2; //priority level
    INTCON2bits.INT1EP = 1; // Interrupt on negative Edge
    IFS1bits.INT1IF = 0; //clear flag
    IEC1bits.INT1IE = 1; //ennable interrupt
}

void __attribute__((__interrupt__, __shadow__)) _INT1Interrupt(void)
{
    LATC^=(1<<6); // change de logic value of led
    IFS1bits.INT2IF = 0;
}

#1
NCosta
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2021/01/12 10:31:14
  • Location: 0
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/19 10:06:59 (permalink)
0
In the code should be "button" not "botton", of course
#2
MBedder
Circuit breaker
  • Total Posts : 6969
  • Reward points : 0
  • Joined: 2008/05/30 11:24:01
  • Location: Zelenograd, Russia
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/19 11:22:08 (permalink)
2 (1)
Why did you start a new thread instead of following the previous one?
post edited by MBedder - 2021/01/19 11:26:01
#3
Howard Long
Super Member
  • Total Posts : 887
  • Reward points : 0
  • Joined: 2005/04/04 08:50:32
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/19 12:00:54 (permalink) ☼ Best Answerby NCosta 2021/01/20 04:18:18
5 (1)
I think it's because you've set the PPS wrongly. Itn your code it's set to RB5 (RP5), not RC9 (RP25).
 
The code below runs on a PIC24F Curiosity with your device on it, S1 is on RC9 and LED3 Green is on RC6. Note, there is no debounce.
 


// PIC24FJ128GA204 Configuration Bit Settings
// 'C' source line config statements
// CONFIG4
#pragma config DSWDTPS = DSWDTPS1F // Deep Sleep Watchdog Timer Postscale Select bits (1:68719476736 (25.7 Days))
#pragma config DSWDTOSC = LPRC // DSWDT Reference Clock Select (DSWDT uses LPRC as reference clock)
#pragma config DSBOREN = OFF // Deep Sleep BOR Enable bit (DSBOR Disabled)
#pragma config DSWDTEN = OFF // Deep Sleep Watchdog Timer Enable (DSWDT Disabled)
#pragma config DSSWEN = OFF // DSEN Bit Enable (Deep Sleep operation is always disabled)
#pragma config PLLDIV = DISABLED // USB 96 MHz PLL Prescaler Select bits (PLL Disabled)
#pragma config I2C1SEL = DISABLE // Alternate I2C1 enable bit (I2C1 uses SCL1 and SDA1 pins)
#pragma config IOL1WAY = OFF // PPS IOLOCK Set Only Once Enable bit (The IOLOCK bit can be set and cleared using the unlock sequence)
// CONFIG3
#pragma config WPFP = WPFP127 // Write Protection Flash Page Segment Boundary (Page 127 (0x1FC00))
#pragma config SOSCSEL = OFF // SOSC Selection bits (Digital (SCLKI) mode)
#pragma config WDTWIN = PS25_0 // Window Mode Watchdog Timer Window Width Select (Watch Dog Timer Window Width is 25 percent)
#pragma config PLLSS = PLL_FRC // PLL Secondary Selection Configuration bit (PLL is fed by the on-chip Fast RC (FRC) oscillator)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset Disabled)
#pragma config WPDIS = WPDIS // Segment Write Protection Disable (Disabled)
#pragma config WPCFG = WPCFGDIS // Write Protect Configuration Page Select (Disabled)
#pragma config WPEND = WPENDMEM // Segment Write Protection End Page Select (Write Protect from WPFP to the last page of memory)
// CONFIG2
#pragma config POSCMD = NONE // Primary Oscillator Select (Primary Oscillator Disabled)
#pragma config WDTCLK = LPRC // WDT Clock Source Select bits (WDT uses LPRC)
#pragma config OSCIOFCN = OFF // OSCO Pin Configuration (OSCO/CLKO/RA3 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSECMD // Clock Switching and Fail-Safe Clock Monitor Configuration bits (Clock switching is enabled, Fail-Safe Clock Monitor is disabled)
#pragma config FNOSC = FRC // Initial Oscillator Select (Fast RC Oscillator (FRC))
#pragma config ALTCMPI = CxINC_RB // Alternate Comparator Input bit (C1INC is on RB13, C2INC is on RB9 and C3INC is on RA0)
#pragma config WDTCMX = WDTCLK // WDT Clock Source Select bits (WDT clock source is determined by the WDTCLK Configuration bits)
#pragma config IESO = OFF // Internal External Switchover (Disabled)
// CONFIG1
#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler Select (1:32,768)
#pragma config FWPSA = PR128 // WDT Prescaler Ratio Select (1:128)
#pragma config WINDIS = OFF // Windowed WDT Disable (Standard Watchdog Timer)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config ICS = PGx1 // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC1/PGED1)
#pragma config LPCFG = OFF // Low power regulator control (Disabled - regardless of RETEN)
#pragma config GWRP = OFF // General Segment Write Protect (Write to program memory allowed)
#pragma config GCP = OFF // General Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF // JTAG Port Enable (Disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <stdint.h>
#define FCY 4000000
#include <libpic30.h>
void __attribute__((interrupt(auto_psv))) _INT1Interrupt(void)
{
IFS1bits.INT1IF=0;
LATCbits.LATC6=!LATCbits.LATC6;
}
int main(void)
{
TRISCbits.TRISC6=0; // LED, RGB Green LED active high on PIC24F Curiosity board DM240004
TRISCbits.TRISC9=1; // Switch, S1 active low, pull up on board. *** Note no debounce ***
RPINR0bits.INT1R=25; // Map RC9/RP25 to INT1
INTCON2bits.INT1EP=1; // Falling edge
IPC5bits.INT1IP=3;
IFS1bits.INT1IF=0;
IEC1bits.INT1IE=1;

while (1)
{
}
return 0;
}

#4
ric
Super Member
  • Total Posts : 29861
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: External Interrupt PIC24FJ128GA204 2021/01/19 12:50:11 (permalink)
4 (1)
The correct answer(s) appear in your OTHER thread at https://www.microchip.com/forums/m1163138.aspx
Please don't start multiple threads about the same question.
 

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!
#5
NCosta
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2021/01/12 10:31:14
  • Location: 0
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/20 03:48:06 (permalink)
4 (1)
I didn't see the answer of Howard Long, so srry.
post edited by NCosta - 2021/01/20 04:37:46
#6
NCosta
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2021/01/12 10:31:14
  • Location: 0
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/20 04:32:02 (permalink)
0
Howard Long, It worked. Thanks for your tip.
But i dont understand why is RC9=RP25,as you can see in the attachment, in the pin diagrams RC9 corresponds to RP5.
Anyway i'm very grateful for your help.
post edited by NCosta - 2021/01/20 04:34:54
#7
ric
Super Member
  • Total Posts : 29861
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: External Interrupt PIC24FJ128GA204 2021/01/20 05:28:16 (permalink)
5 (1)
NCosta
But i dont understand why is RC9=RP25,as you can see in the attachment, in the pin diagrams RC9 corresponds to RP5.

The image you posted does not show the RP numbers at all, because they ran out of space.
Look at the table immediately below the image, and you will see the full label for that pin is:
 
5: RP25/CTED7/PMA6/CN19/RC9
 
 

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!
#8
Howard Long
Super Member
  • Total Posts : 887
  • Reward points : 0
  • Joined: 2005/04/04 08:50:32
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/20 05:31:58 (permalink)
5 (1)
See page 5 of the datasheet DS30010038C, Table 1.
 
Pin 5: RP25/CTED7/PMA6/CN19/RC9

Attached Image(s)

#9
Howard Long
Super Member
  • Total Posts : 887
  • Reward points : 0
  • Joined: 2005/04/04 08:50:32
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/20 05:36:06 (permalink)
0
ric
NCosta
But i dont understand why is RC9=RP25,as you can see in the attachment, in the pin diagrams RC9 corresponds to RP5.

The image you posted does not show the RP numbers at all, because they ran out of space.
Look at the table immediately below the image, and you will see the full label for that pin is:
 
5: RP25/CTED7/PMA6/CN19/RC9

 
Gonna have to stop meeting like this!
#10
ric
Super Member
  • Total Posts : 29861
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: External Interrupt PIC24FJ128GA204 2021/01/20 05:40:53 (permalink)
0
There seems to be an echo in this room! ;)
 

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!
#11
NCosta
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2021/01/12 10:31:14
  • Location: 0
  • Status: offline
Re: External Interrupt PIC24FJ128GA204 2021/01/20 05:41:47 (permalink)
0
Ok i understood it. Thanks for your tips.
 
Best Regards
#12
Jump to:
© 2021 APG vNext Commercial Version 4.5