• AVR Freaks

Hot!Input Interrupt not working with MPLAB X Simulator

Page: 12 > Showing page 1 of 2
Author
Bruno_Bellini
Junior Member
  • Total Posts : 103
  • Reward points : 0
  • Joined: 2009/06/09 12:24:10
  • Location: Montevideo, Uruguay
  • Status: offline
2020/04/19 12:24:18 (permalink)
0

Input Interrupt not working with MPLAB X Simulator

Hi All,
I'm professor of an Embedded Systems course at University in Uruguay. Due to Coronavirus, classes turned to be remotely dictated and I'm in the urgent need to adapt them.
We typically use at class development boards with PIC32MM0256GPM064 microcontrollers and MPLAB SNAP programmer/debuggers. But now, we are using the MPLAB X simulator, as students couldn't get the boards before COVID-19 break into our country.

The problem is that I'm trying to simulate interrupts of a couple switch buttons, and ISRs never seem to be called in an low to high edge.
System and Peripherals are configured via MCC v3, and the button press is simulated via Asynchronous Stimulus.
When the stimuli is Fired, it can be seen at PORT register (pin state change), ISR is never called.

It's worth to say that I tried the same code in a board I have with me, and code is working perfectly, so I think that is a Simulator problem.

I would like to know if there is any special configuration for the simulator to be made and I'm missing, or if it is a simulator problem.
A very similar problem is happening when I try to send a byte via UART2 using interrupts.

Just in case:
* MPLAB X IDE v5.35
* XC32 Compiler v2.40

Waiting for your kind help.
 
Bruno Bellini

Bruno
#1

20 Replies Related Threads

    dan1138
    Super Member
    • Total Posts : 3843
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/20 09:31:51 (permalink)
    +3 (3)
    Using:
    MPLABX v5.25
    XC32 v2.20
    MCC v 3.95.0
     
    I setup a new MCC project for the PIC32MM0256GPM064 with all external interrupt sources enabled to assert for a positive edge (low to high transition).
     
    All the external interrupts work in the simulation tool.
     
    Using the MCC seems complicated and there are a lot of ways to do this wrong.
     
    I have attached my project with my stimulus file.
     
    Please see if it will work with the Microchip tool chain you have installed.
    #2
    Bruno_Bellini
    Junior Member
    • Total Posts : 103
    • Reward points : 0
    • Joined: 2009/06/09 12:24:10
    • Location: Montevideo, Uruguay
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/20 15:43:27 (permalink)
    0
    Hi Dan, thank you so much for your answer.
    Effectively, your code works perfectly. However, I'm trying to simulate CN interrupts (not External Interrupt Peripheral).
    I guess there is a problem with simulator, as if I run code over hardware platform it works ok.
    Below you can find a link with 2 videos, one for running on hardware, and another with simulator:

    https://drive.google.com/file/d/1MRO8HEBUmiEY25JH-oTdlGhNa8ZsKDMF/view?usp=sharing

    I changed pull-down configuration to pull-up and to none, but nothing changes.
     
    I hope somebody could manage to make it work before I give up on simulator.
     
    Thank you for your help!

    Bruno
    #3
    ric
    Super Member
    • Total Posts : 28378
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/20 16:13:04 (permalink)
    +1 (1)
    Did you try lodging a "support ticket" ?
    This is just a user forum. Some Microchip staff look in here on their own time, but the official channel to notify Microchip of problems is via:
    http://support.microchip.com
     
     

    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
    GeorgePauley
    Moderator
    • Total Posts : 1268
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/21 06:39:22 (permalink)
    +2 (2)
    The simulator "team" has a head-cold and is having difficulty focusing.  wink: wink

    Can you spell out exactly what you mean by CN interrupt?  A cursory look at the datasheet doesn't show me a peripheral with initials CN.  We do (believe we) implement Interrupt-On-Change (IOC) for these devices, which is what I would guess you are trying to use?  Can you show us a small snippet of code that doesn't do what you expect?  Thanks.
    #5
    Bruno_Bellini
    Junior Member
    • Total Posts : 103
    • Reward points : 0
    • Joined: 2009/06/09 12:24:10
    • Location: Montevideo, Uruguay
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/21 10:59:38 (permalink)
    0
    Hi George, thanks for your answer.
    By CN interrupt I mean I'm using Input Change Notification interrupt feature for I/O Ports, as you say, it's shown as Interrupt On Change (IOC) in the datasheet.
    One post earlier, I posted a Google Drive link with some videos showing the problem for Simulator, but working with Snap Debugger and a Board.


    Attached you can find the .X project to see MCC configurations and generated code. I'm using breakpoints to see if ISR is called after an Asynchronous Stimuli is Fired (from low to high).

    Waiting for your news.

    Bruno
    #6
    dan1138
    Super Member
    • Total Posts : 3843
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/21 11:46:25 (permalink)
    +2 (2)
    GeorgePauley,

    The MPLABX v5.25 simulation model for Interrupt-On-Change works on the PIC32MX795F512L
    /*
    * File: main.c
    * Target: PIC32MX795F512L
    * Compiler: C32 v2.02, XC32 v2.20
    * IDE: MPLABX v5.25
    *
    * Description:
    * Test Interrupt On Change function with simulation tool
    *
    * (2020-04-21) Confirmed that IOC works in the simulation tool.
    *
    * Notes:
    * Define symbol USE_XTAL to use an external 8.0MHz crystal.
    * Define symbol USE_PLL to enable the PLL and set clock to 80MHz.
    * Does not use the PLIB library so should build with any Microchip compiler for PIC32.
    * When building with XC16 v1.44 MPLAB v8.92 asserts an error dialog box.
    */

    /*
    * Configuration words
    */
    #pragma config FSRSSEL = PRIORITY_7 /* SRS Select (SRS Priority 7) */
    #pragma config FMIIEN = OFF /* Ethernet RMII/MII Enable (RMII Enabled) */
    #pragma config FETHIO = OFF /* Ethernet I/O Pin Select (Alternate Ethernet I/O) */
    #pragma config FCANIO = OFF /* CAN I/O Pin Select (Alternate CAN I/O) */
    #pragma config FUSBIDIO = OFF /* USB USID Selection (Controlled by Port Function) */
    #pragma config FVBUSONIO = OFF /* USB VBUS ON Selection (Controlled by Port Function) */
    #pragma config FPLLIDIV = DIV_2 /* PLL Input Divider (2x Divider) */
    #pragma config FPLLMUL = MUL_20 /* PLL Multiplier (20x Multiplier) */
    #pragma config UPLLIDIV = DIV_2 /* USB PLL Input Divider (2x Divider) */
    #pragma config UPLLEN = OFF /* USB PLL Enable (Disabled and Bypassed) */
    #pragma config FPLLODIV = DIV_1 /* System PLL Output Clock Divider (PLL Divide by 1) */
    #pragma config FSOSCEN = OFF /* Secondary Oscillator Enable (Disabled) */
    #pragma config IESO = OFF /* Internal/External Switch Over (Disabled) */
    #pragma config OSCIOFNC = OFF /* CLKO Output Signal Active on the OSCO Pin (Disabled) */
    #pragma config FPBDIV = DIV_1 /* Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1) */
    #pragma config WDTPS = PS1 /* Watchdog Timer Postscaler (1:1) */
    #pragma config FWDTEN = OFF /* Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls)) */
    #pragma config ICESEL = ICS_PGx2 /* ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2) */
    #pragma config PWP = OFF /* Program Flash Write Protect (Disable) */
    #pragma config BWP = OFF /* Boot Flash Write Protect bit (Protection Disabled) */
    #pragma config CP = OFF /* Code Protect (Protection Disabled) */
    #pragma config FNOSC = FRC /* Oscillator Selection Bits (Fast RC Osc) */
    #pragma config FCKSM = CSECMD /* Clock Switching and Monitor Selection (Clock Switch Enable, FSCM Disabled) */

    #define USE_PLL

    #if defined(USE_XTAL)

    #pragma config POSCMOD = XT /* Primary Oscillator Configuration (XT osc mode) */
    #define OSC_FREQUENCY (8000000ul) /* External crystal frequency */
    #define PLL_INPUT_DIVIDER (2ul)
    #define PLL_MULTIPLIER (20ul)

    #if defined(USE_PLL)
    #define OSC_SELECTOR (0b011) /* Use Primary Oscillator + PLL*/
    #else
    #define OSC_SELECTOR (0b010) /* Use Primary Oscillator */
    #endif

    #else

    #pragma config POSCMOD = OFF /* Primary Oscillator Configuration (Primary osc disabled) */
    #define OSC_FREQUENCY (8000000ul) /* Internal Fast RC oscillator frequency */
    #define PLL_INPUT_DIVIDER (2ul)
    #define PLL_MULTIPLIER (20ul)

    #if defined(USE_PLL)
    #define OSC_SELECTOR (0b001) /* Use FRC + PLL */
    #else
    #define OSC_SELECTOR (0b000) /* Use FRC */
    #endif

    #endif

    #if defined(__XC32)
    #include <xc.h>
    #elif defined(__C32__)
    #include <p32xxxx.h>
    #else
    #error "Unknown PIC32 compiler"
    #endif



    #if defined(USE_PLL)
    #define GetSystemClock() ((OSC_FREQUENCY/PLL_INPUT_DIVIDER)*PLL_MULTIPLIER)
    #define PB_CLOCK_DIVIDER (1ul)
    #else
    #define GetSystemClock() (OSC_FREQUENCY)
    #define PB_CLOCK_DIVIDER (1ul)
    #endif
    #define GetPeripheralClock() (GetSystemClock()/PB_CLOCK_DIVIDER)
    #define GetInstructionClock() (GetSystemClock())


    #define FLASH_SPEED_HZ 30000000ul //Max Flash speed
    #define PB_BUS_MAX_FREQ_HZ 80000000ul //Max Peripheral bus speed

    /***************************************************************
    * <combinewith CHE_CONF_PF_ALL, CHE_CONF_PF_C, CHE_CONF_PF_NC>
    *
    * Flash Prefetch option - Values are mutually exclusive
    **************************************************************
    */
    #define CHE_CONF_PF_DISABLE (0 << _CHECON_PREFEN_POSITION)
    #define CHE_CONF_PF_C (1 << _CHECON_PREFEN_POSITION )
    #define CHE_CONF_PF_NC (2 << _CHECON_PREFEN_POSITION)
    #define CHE_CONF_PF_ALL (3 << _CHECON_PREFEN_POSITION)

    /* Initialize this PIC */
    void __attribute__ ((nomips16)) PIC_Init(void)
    {
    // Configure the device for maximum performance,
    // This function will change the program Flash wait states,
    // RAM wait state and enable prefetch cache
    // The PBDIV value must be already set via the pragma FPBDIV option in configuration words.

    unsigned int sys_clock;
    unsigned int pb_clock;
    unsigned int int_status;
    unsigned int wait_states;
    register unsigned long cache_tmp;
    register unsigned long clock_switch_timeout;

    sys_clock = GetSystemClock();

    /* Save current interrupt enable state and disable interrupts */
    asm volatile("di %0" : "=r"(int_status));

    /* Check that we can change the system clock frequency */
    if(!OSCCONbits.CLKLOCK)
    {
    /* swich system clock to FRC, no PLL */
    SYSKEY = 0, SYSKEY = 0xAA996655, SYSKEY = 0x556699AA;
    OSCCONbits.NOSC = 0b000; /* select FRC as system oscillator */
    OSCCONbits.OSWEN = 1; /* start a clock switch */
    SYSKEY = 0x33333333;
    for(clock_switch_timeout=80000; clock_switch_timeout; clock_switch_timeout--)
    {
    if(!OSCCONbits.OSWEN) break;
    }
    }
    /* Disable the JTAG interface */
    DDPCONbits.JTAGEN = 0;

    /* Disable the JTAG TDO output */
    DDPCONbits.TDOEN = 0;

    /* Disable the TRACE interface */
    DDPCONbits.TROEN = 0;

    /* Set RAM to use MAX wait states */
    BMXCONCLR = _BMXCON_BMXWSDRM_MASK;

    /* Set FLASH wait states for desired system clock */
    wait_states = 0;
    while(sys_clock > (FLASH_SPEED_HZ * (wait_states + 1)))
    {
    wait_states++;
    }

    /* turn on cache and set FLASH wate states */
    CHECON = CHE_CONF_PF_ALL | wait_states;

    /* Select Kseg0 coherency algorithm as 3, cacheable. */
    asm("mfc0 %0,$16,0" : "=r"(cache_tmp));
    cache_tmp = (cache_tmp & ~7) | 3;
    asm("mtc0 %0,$16,0" :: "r" (cache_tmp));

    /* compute peripherial bus clock frequency from sys_clock */
    pb_clock = (sys_clock >> OSCCONbits.PBDIV);

    if(!OSCCONbits.CLKLOCK)
    {
    /* swich system clock to Primary oscillation amplifier with PLL */
    SYSKEY = 0, SYSKEY = 0xAA996655, SYSKEY = 0x556699AA;
    #if (PLL_INPUT_DIVIDER == 1)
    OSCCONbits.FRCDIV =0b000;
    #elif (PLL_INPUT_DIVIDER == 2)
    OSCCONbits.FRCDIV =0b001;
    #elif (PLL_INPUT_DIVIDER == 4)
    OSCCONbits.FRCDIV =0b010;
    #elif (PLL_INPUT_DIVIDER == 8)
    OSCCONbits.FRCDIV =0b011;
    #elif (PLL_INPUT_DIVIDER == 16)
    OSCCONbits.FRCDIV =0b100;
    #elif (PLL_INPUT_DIVIDER == 32)
    OSCCONbits.FRCDIV =0b101;
    #elif (PLL_INPUT_DIVIDER == 64)
    OSCCONbits.FRCDIV =0b110;
    #elif (PLL_INPUT_DIVIDER == 256)
    OSCCONbits.FRCDIV =0b111;
    #else
    #error PLL input divider has bad value
    #endif

    #if (PLL_MULTIPLIER == 15)
    OSCCONbits.PLLMULT =0b000;
    #elif (PLL_MULTIPLIER == 16)
    OSCCONbits.PLLMULT =0b001;
    #elif (PLL_MULTIPLIER == 17)
    OSCCONbits.PLLMULT =0b010;
    #elif (PLL_MULTIPLIER == 18)
    OSCCONbits.PLLMULT =0b011;
    #elif (PLL_MULTIPLIER == 19)
    OSCCONbits.PLLMULT =0b100;
    #elif (PLL_MULTIPLIER == 20)
    OSCCONbits.PLLMULT =0b101;
    #elif (PLL_MULTIPLIER == 21)
    OSCCONbits.PLLMULT =0b110;
    #elif (PLL_MULTIPLIER == 24)
    OSCCONbits.PLLMULT =0b111;
    #else
    #error PLL multiplier has bad value
    #endif
    OSCCONbits.PLLODIV = 0b000; /* set PLL output divider to 1:1 */
    OSCCONbits.NOSC = OSC_SELECTOR;
    OSCCONbits.OSWEN = 1; /* start a clock switch */
    SYSKEY = 0x33333333;
    for(clock_switch_timeout=80000; clock_switch_timeout; clock_switch_timeout--)
    {
    if(!OSCCONbits.OSWEN) break;
    }
    }

    /* set GPIO pins for digital I/O */
    AD1PCFG = (0xFFFFul);

    /* Restore interrupt state */
    if(int_status & 0x00000001)
    {
    asm volatile("ei %0" : "=r"(int_status));
    }
    /*
    * At this point the values for sys_clock and pb_clock
    * should be assigned.
    */
    }
    /*
    *
    */
    void DelayMS( unsigned long Delay )
    {
    #define TICKS_IN_ONE_MILLISECOND (GetSystemClock() / 2000ul)
    unsigned long Time0, Time1;

    Time0 = _CP0_GET_COUNT(); /* 2 system clocks per count */

    if (Delay < (unsigned long)(0xFFFFFFFFul) / TICKS_IN_ONE_MILLISECOND)
    Delay = Delay * TICKS_IN_ONE_MILLISECOND;
    else
    Delay = (unsigned long)(0xFFFFFFFFul);

    for(;;)
    {
    Time1 = _CP0_GET_COUNT();
    Time1 = Time1 - Time0; /* Get cycle from start of spin */
    if (Time1 >= Delay)
    break;
    }
    }
    /*
    * Main application
    */
    volatile uint32_t PORTB_data;

    void main(void)
    {
    PIC_Init();

    IFS1bits.CNIF = 0;
    IEC1bits.CNIE = 0;
    IPC6bits.CNIP = 1;
    IPC6bits.CNIS = 0;

    AD1PCFGbits.PCFG0 = 1; /* Set AN0 as a digital input */
    TRISBbits.TRISB0 = 1; /* Set RB0/CN2 as a digital input */
    CNENbits.CNEN2 = 1; /* Enable notification on CN2 */
    CNCONbits.ON = 1; /* Enable change notifications */
    IFS1bits.CNIF = 0; /* Clear CN interrupt flag */

    DelayMS(5);

    while(1)
    {
    if(IFS1bits.CNIF)
    {
    Nop();
    PORTB_data = PORTB; /* Read PORTB state */
    IFS1bits.CNIF = 0; /* Clear CN interrupt flag */
    }
    Nop();
    }
    }


    The MPLABX v5.25 simulation model for Interrupt-On-Change fails on the PIC32MM0256GPM064
    /*
    * File: main.c
    * Author: dan1138
    * Target: PIC32MM0256GPM064
    * Compiler: XC32 v2.20
    * IDE: MPLABX v5.25
    *
    * Description:
    * Test Interrupt On Change function with simulation tool
    *
    * (2020-04-21) Interrupt on change function does not work in simulation tool
    *
    */
    // FDEVOPT
    #pragma config SOSCHP = OFF //Secondary Oscillator High Power Enable bit->SOSC oprerates in normal power mode.
    #pragma config ALTI2C = OFF //Alternate I2C1 Pins Location Enable bit->Primary I2C1 pins are used
    #pragma config FUSBIDIO = OFF //USBID pin control->USBID pin is controlled by the USB module
    #pragma config FVBUSIO = OFF //VBUS Pin Control->VBUS pin is controlled by the USB module

    // FICD
    #pragma config JTAGEN = OFF //JTAG Enable bit->JTAG is disabled
    #pragma config ICS = PGx1 //ICE/ICD Communication Channel Selection bits->Communicate on PGEC1/PGED1

    // FPOR
    #pragma config BOREN = BOR3 //Brown-out Reset Enable bits->Brown-out Reset enabled in hardware; SBOREN bit disabled
    #pragma config RETVR = OFF //Retention Voltage Regulator Enable bit->Retention regulator is disabled
    #pragma config LPBOREN = ON //Downside Voltage Protection Enable bit->Low power BOR is enabled, when main BOR is disabled

    // FWDT
    #pragma config SWDTPS = PS1048576 //Sleep Mode Watchdog Timer Postscale Selection bits->1:1048576
    #pragma config FWDTWINSZ = PS25_0 //Watchdog Timer Window Size bits->Watchdog timer window size is 25%
    #pragma config WINDIS = OFF //Windowed Watchdog Timer Disable bit->Watchdog timer is in non-window mode
    #pragma config RWDTPS = PS2048 //Run Mode Watchdog Timer Postscale Selection bits->1:2048
    #pragma config RCLKSEL = LPRC //Run Mode Watchdog Timer Clock Source Selection bits->Clock source is LPRC (same as for sleep mode)
    #pragma config FWDTEN = OFF //Watchdog Timer Enable bit->WDT is disabled

    // FOSCSEL
    #pragma config FNOSC = FRCDIV //Oscillator Selection bits->Fast RC oscillator (FRC) with divide-by-N
    #pragma config PLLSRC = FRC //System PLL Input Clock Selection bit->FRC oscillator is selected as PLL reference input on device reset
    #pragma config SOSCEN = OFF //Secondary Oscillator Enable bit->Secondary oscillator is disabled
    #pragma config IESO = ON //Two Speed Startup Enable bit->Two speed startup is enabled
    #pragma config POSCMOD = OFF //Primary Oscillator Selection bit->Primary oscillator is disabled
    #pragma config OSCIOFNC = OFF //System Clock on CLKO Pin Enable bit->OSCO pin operates as a normal I/O
    #pragma config SOSCSEL = ON //Secondary Oscillator External Clock Enable bit->SCLKI pin configured for Digital mode
    #pragma config FCKSM = CSDCMD //Clock Switching and Fail-Safe Clock Monitor Enable bits->Clock switching is disabled; Fail-safe clock monitor is disabled

    #include <xc.h>
    #ifndef _XTAL_FREQ
    #define _XTAL_FREQ 8000000UL
    #endif

    volatile uint32_t PORTB_data;

    void main(void)
    {
    /* RegUnlock */
    SYSKEY = 0x0; //write invalid key to force lock
    SYSKEY = 0xAA996655; //write Key1 to SYSKEY
    SYSKEY = 0x556699AA; //write Key2 to SYSKEY

    // ORPOL disabled; SIDL disabled; SRC SOSC; TUN Center frequency; POL disabled; ON disabled;
    OSCTUN = 0x00;
    // SBOREN disabled; VREGS disabled; RETEN disabled;
    PWRCON = 0x00;
    //CF No Clock Failure has been detected;; FRCDIV FRC/1; SLPEN Device will enter Idle mode when a WAIT instruction is issued; NOSC FRCDIV; SOSCEN disabled; CLKLOCK Clock and PLL selections are not locked and may be modified; OSWEN Switch is Complete;
    OSCCON = (0x00);

    /* RegLock */
    SYSKEY = 0x00000000;

    // ON disabled; DIVSWEN disabled; RSLP disabled; ROSEL SYSCLK; OE disabled; SIDL disabled; RODIV 0;
    REFO1CON = 0x00;
    // ROTRIM 0;
    REFO1TRIM = 0x00;

    ANSELBbits.ANSB0 = 0; // Set RB0 as digital input
    TRISBbits.TRISB0 = 1; // Set RB0 as input
    /****************************************************************************
    * Interrupt On Change: any
    ***************************************************************************/
    CNEN0Bbits.CNIE0B0 = 1; //Pin : RB0
    CNEN1Bbits.CNIE1B0 = 1; //Pin : RB0
    /****************************************************************************
    * Interrupt On Change: flag
    ***************************************************************************/
    CNFBbits.CNFB0 = 0; //Pin : RB0
    /****************************************************************************
    * Interrupt On Change: config
    ***************************************************************************/
    CNCONBbits.CNSTYLE = 1;
    CNCONBbits.ON = 1;
    /****************************************************************************
    * CNBI: PORT B Change Notification
    ***************************************************************************/
    IPC2bits.CNBIP = 1; // Priority: 1
    IPC2bits.CNBIS = 0; // Sub Priority: 0

    /****************************************************************************
    * Interrupt On Change: Clear Interrupt Flag
    ***************************************************************************/
    IFS0CLR= 1 << _IFS0_CNBIF_POSITION;

    for(;;)
    {
    if (IFS0bits.CNBIF)
    {
    PORTB_data = PORTB;
    CNFBbits.CNFB0 = 0; //Pin : RB0
    IFS0CLR= 1 << _IFS0_CNBIF_POSITION;
    Nop();
    }
    Nop();
    }
    }

    The code I created for the PIC32MM0256GPM064 is what the MLABX Code Configurator generated, just trimmed and stuffed into a single file.

    Please show me that I did something wrong for the PIC32MM0256GPM064.
    post edited by dan1138 - 2020/04/21 11:55:35
    #7
    GeorgePauley
    Moderator
    • Total Posts : 1268
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/21 13:18:41 (permalink)
    +1 (1)
    Thanks Dan, you just saved me a lot of time.
     
    It looks like the same old thing.  Silicon designers have changed the way IOC works, or at least changed names of the associated SFRs, and simulator is the last group to learn about it.  I will write a fix-it request for this.  It looks like the 16 bit devices have an IOC that is very similar to the on on this device, just need to port it over to the 32 bit side.
    #8
    ric
    Super Member
    • Total Posts : 28378
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/21 14:54:40 (permalink)
    +1 (3)
    GeorgePauley
    The simulator "team" has a head-cold and is having difficulty focusing. 

    I hope that's all it is George!
    Look after yourself, and keep maintaining your social distance :)

    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!
    #9
    dan1138
    Super Member
    • Total Posts : 3843
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/21 14:57:03 (permalink)
    +1 (3)
    GeorgePauley
    It looks like the same old thing. 

    This ain't the first time I've seen a bull of this breed at the rodeo.
     
    What are the criteria for turning the dot green for the simulation tool? Do you guys even look for issues before a customer reports a bug? Is there anyone to actually check that the simulation models that are claimed to be functional do in fact actually work?
     
    So this is broken in the MPLABX v5.25 and later releases.
     
    How broken does the simulator need to be before it gets any thing but a green dot?
     

    post edited by dan1138 - 2020/04/22 15:56:59

    Attached Image(s)

    #10
    GeorgePauley
    Moderator
    • Total Posts : 1268
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/22 06:33:30 (permalink)
    0
    ric
    GeorgePauley
    The simulator "team" has a head-cold and is having difficulty focusing. 

    I hope that's all it is George!
    Look after yourself, and keep maintaining your social distance :)


    Thanks Ric.  A couple of days rest and I'm feeling much better.  mr green: mr green  Almost all MCHP'ers are working from home these days.  So except for an occasional trip to the grocery store, there's nothing but social distancing going here in Chandler.
    #11
    Jim Nickerson
    User 452
    • Total Posts : 6736
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/22 06:40:20 (permalink)
    0
    George,
    My bout with the flu started with nasal congestion.
    I used antihistamine to clear it up.
    It was slow and insidious, slowly getting worse with each day for 2 weeks after the first symptoms.
    I do hope you do not come down with the flu Smile: Smile
    #12
    Bruno_Bellini
    Junior Member
    • Total Posts : 103
    • Reward points : 0
    • Joined: 2009/06/09 12:24:10
    • Location: Montevideo, Uruguay
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/22 08:59:16 (permalink)
    0
    Thanks for the investigation Dan!
     
    George, please update us when the fix is done so we can check again.
     
    Keep safe

    Bruno
    #13
    dan1138
    Super Member
    • Total Posts : 3843
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/22 15:53:15 (permalink)
    0
    @Bruno,
     
    Like your students I have no access to PIC32MM0256GPM064 hardware.
     
    If you get a change please try this code in your hardware:
    /*
     * File:   main.c
     * Author: dan1138
     * Target: PIC32MM0256GPM064
     * Compiler: XC32 v2.20
     * IDE: MPLABX v5.25
     *
     * Description:
     *  Test Interrupt On Change function with simulation tool
     *
     * (2020-04-21) Interrupt on change function does not work in simulation tool
     *
     * History:
     *
     * (2020-08-07) Update as per: https://www.microchip.com/forums/FindPost/1139618
     *
     */
    // FDEVOPT
    #pragma config SOSCHP = OFF     //Secondary Oscillator High Power Enable bit->SOSC oprerates in normal power mode.
    #pragma config ALTI2C = OFF     //Alternate I2C1 Pins Location Enable bit->Primary I2C1 pins are used
    #pragma config FUSBIDIO = OFF   //USBID pin control->USBID pin is controlled by the USB module
    #pragma config FVBUSIO = OFF    //VBUS Pin Control->VBUS pin is controlled by the USB module

    // FICD
    #pragma config JTAGEN = OFF     //JTAG Enable bit->JTAG is disabled
    #pragma config ICS = PGx1       //ICE/ICD Communication Channel Selection bits->Communicate on PGEC1/PGED1

    // FPOR
    #pragma config BOREN = BOR3     //Brown-out Reset Enable bits->Brown-out Reset enabled in hardware; SBOREN bit disabled
    #pragma config RETVR = OFF      //Retention Voltage Regulator Enable bit->Retention regulator is disabled
    #pragma config LPBOREN = ON     //Downside Voltage Protection Enable bit->Low power BOR is enabled, when main BOR is disabled

    // FWDT
    #pragma config SWDTPS = PS1048576    //Sleep Mode Watchdog Timer Postscale Selection bits->1:1048576
    #pragma config FWDTWINSZ = PS25_0    //Watchdog Timer Window Size bits->Watchdog timer window size is 25%
    #pragma config WINDIS = OFF     //Windowed Watchdog Timer Disable bit->Watchdog timer is in non-window mode
    #pragma config RWDTPS = PS2048  //Run Mode Watchdog Timer Postscale Selection bits->1:2048
    #pragma config RCLKSEL = LPRC   //Run Mode Watchdog Timer Clock Source Selection bits->Clock source is LPRC (same as for sleep mode)
    #pragma config FWDTEN = OFF     //Watchdog Timer Enable bit->WDT is disabled

    // FOSCSEL
    #pragma config FNOSC = FRCDIV   //Oscillator Selection bits->Fast RC oscillator (FRC) with divide-by-N
    #pragma config PLLSRC = FRC     //System PLL Input Clock Selection bit->FRC oscillator is selected as PLL reference input on device reset
    #pragma config SOSCEN = OFF     //Secondary Oscillator Enable bit->Secondary oscillator is disabled
    #pragma config IESO = ON        //Two Speed Startup Enable bit->Two speed startup is enabled
    #pragma config POSCMOD = OFF    //Primary Oscillator Selection bit->Primary oscillator is disabled
    #pragma config OSCIOFNC = OFF   //System Clock on CLKO Pin Enable bit->OSCO pin operates as a normal I/O
    #pragma config SOSCSEL = ON     //Secondary Oscillator External Clock Enable bit->SCLKI pin configured for Digital mode
    #pragma config FCKSM = CSDCMD   //Clock Switching and Fail-Safe Clock Monitor Enable bits->Clock switching is disabled; Fail-safe clock monitor is disabled

    #include <xc.h>
    #ifndef _XTAL_FREQ
    #define _XTAL_FREQ  8000000UL
    #endif

    #define GetSystemClock()        (_XTAL_FREQ)

    /* Initialize this PIC */
    void __attribute__ ((nomips16)) PIC_Init(void)
    {
        /* RegUnlock */
        SYSKEY = 0x0, SYSKEY = 0xAA996655, SYSKEY = 0x556699AA; // Make sure these assignements occur in this order

        // ORPOL disabled; SIDL disabled; SRC SOSC; TUN Center frequency; POL disabled; ON disabled;
        OSCTUN = 0x00;
        // SBOREN disabled; VREGS disabled; RETEN disabled;
        PWRCON = 0x00;
        //CF No Clock Failure has been detected;; FRCDIV FRC/1; SLPEN Device will enter Idle mode when a WAIT instruction is issued; NOSC FRCDIV; SOSCEN disabled; CLKLOCK Clock and PLL selections are not locked and may be modified; OSWEN Switch is Complete;
        OSCCON = (0x00);
        
        /* RegLock */
        SYSKEY = 0x0;
        
        // ON disabled; DIVSWEN disabled; RSLP disabled; ROSEL SYSCLK; OE disabled; SIDL disabled; RODIV 0;
        REFO1CON = 0x00;
        // ROTRIM 0;
        REFO1TRIM = 0x00;
        
        // Enable Multi Vector Configuration
        INTCONbits.MVEC = 1;
    }
    /*
     *
     */
    void DelayMS( unsigned long Delay )
    {
    #define TICKS_IN_ONE_MILLISECOND (GetSystemClock() / 2000ul)
        unsigned long Time0, Time1;

        Time0 = _CP0_GET_COUNT(); /* 2 system clocks per count */

        if (Delay < (unsigned long)(0xFFFFFFFFul) / TICKS_IN_ONE_MILLISECOND)
            Delay = Delay * TICKS_IN_ONE_MILLISECOND;
        else
            Delay = (unsigned long)(0xFFFFFFFFul);

        for(;;)
        {
            Time1 = _CP0_GET_COUNT();
            Time1 = Time1 - Time0;      /* Get cycle from start of spin */
            if (Time1 >= Delay)
                break;
        }
    }

    volatile uint32_t PORTB_data;

    void main(void)
    {
        PIC_Init();

        ANSELBbits.ANSB15 = 0;   // Set (Pin : RB15) as digital input
        TRISBbits.TRISB15 = 1;   // Set (Pin : RB15) as input
        CNPDBbits.CNPDB15 = 1;   // Set (Pin : RB15) pull-down enabled
        CNPUBbits.CNPUB15 = 0;   // Set (Pin : RB15) pull-up disabled

        /****************************************************************************
         * Interrupt On Change: any
         ***************************************************************************/
        CNEN0Bbits.CNIE0B15 = 1;    // (Pin : RB15)
        CNEN1Bbits.CNIE1B15 = 1;    // (Pin : RB15)
        /****************************************************************************
         * Interrupt On Change: flag
         ***************************************************************************/
        CNFBbits.CNFB15 = 0;    // (Pin : RB15)
        /****************************************************************************
         * Interrupt On Change: config
         ***************************************************************************/
        CNCONBbits.CNSTYLE = 1;
        CNCONBbits.ON = 1;
        
        /****************************************************************************
         * CNBI: PORT B Change Notification
         ***************************************************************************/
        IPC2bits.CNBIP = 1; //    Priority: 1
        IPC2bits.CNBIS = 0; //    Sub Priority: 0

        /****************************************************************************
         * Interrupt On Change: Clear Interrupt Flag
         ***************************************************************************/
        IFS0CLR = 1 << _IFS0_CNBIF_POSITION;
        IEC0bits.CNBIE = 1; //Enable CNBI interrupt
        
        DelayMS(5);
        
        /* Enables global interrupts of the PIC32MM0256GPM064 */
        __builtin_enable_interrupts();
        
        for(;;)
        {
            Nop();
        }
    }

    void __attribute__ ((vector(_CHANGE_NOTICE_B_VECTOR), interrupt(IPL1SOFT))) ISR_CHANGE_NOTICE_B( void )
    {
        if(IFS0bits.CNBIF)
        {
            if(CNFBbits.CNFB15) // (Pin : RB15))
            {
                Nop();
                
                CNFBCLR = (1 << _CNFB_CNFB15_POSITION); //Clear CNFBbits.CNFB15 (Pin : RB15)
            }
            
            IFS0CLR = (1 << _IFS0_CNBIF_POSITION); // Clear IFS0bits.CNBIF
        }
    }

    I am mostly sure that the interrupts are configured correctly but as the simulation fails I cannot be certain.
    post edited by dan1138 - 2020/08/07 10:12:40
    #14
    Bruno_Bellini
    Junior Member
    • Total Posts : 103
    • Reward points : 0
    • Joined: 2009/06/09 12:24:10
    • Location: Montevideo, Uruguay
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/23 17:06:22 (permalink)
    0
    Dan, how are you?

    Could you wait me for a couple of days?
    Today my second daughter was born, and I will be at hospital until Saturday.
    After that I have no problem to test your code on my hardware of course.
     
     

    Bruno
    #15
    dan1138
    Super Member
    • Total Posts : 3843
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/04/23 19:04:12 (permalink)
    +2 (2)
    IUMO
    Could you wait me for a couple of days?

    I am just fine.
     
    Take as long as you want. I have no urgent need at all.
     
    Congratulations on your new arrival. Hope all is well.
    #16
    Bruno_Bellini
    Junior Member
    • Total Posts : 103
    • Reward points : 0
    • Joined: 2009/06/09 12:24:10
    • Location: Montevideo, Uruguay
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/05/12 09:23:26 (permalink)
    0
    Dan, how are you?
     
    After a couple of weeks, I could manage to have some free time.
     
    I've tested your code today. It was almost correct.
    To make interrupts work on my dev board I made the following changes/additions:
    1. Add the line:
      IEC0bits.CNBIE=1; //Enable CNBI interrupt
      After your line:
      IFS0CLR= 1 << _IFS0_CNBIF_POSITION;

      In order to enable Change Notification interrupts.

    2. Inside your ISR, you were clearing CN A flag instead of B. So change:
      IFS0CLR = (1 << _IFS0_CNAIF_POSITION); // Clear IFS0bits.CNBIF
      for:
      IFS0CLR = (1 << _IFS0_CNBIF_POSITION); // Clear IFS0bits.CNBIF
    After those little changes the interrupt worked fine.
    Just to comments:
    • I changed RB0 to RB15 to test, as I have a tactile switch connected to it on my board
    • For better behaviour of the button, I needed to add the Pull-Down configuration:
      CNPDB=0x8000;
      CNPUB=0x0000;
    Also tried the same code with Simulator tool, but interrupts didn't work

    Bruno
    #17
    jvourv
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2010/03/07 08:44:57
    • Location: 0
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/08/06 02:43:06 (permalink)
    0
    Hi,
     
    It seems that the IOC issue also appears in PIC18F57Q43 devices.
    I attach the code for IOC (RB0 and RB1) and for INT0 and INT1.
    INT0 and INT1 interrupts are working correctly in the simulator.
    IOC interrupt seems that does not work.
    IOCxF bits seem that are not set at all.
    Is there any issue in the simulator or I miss something in the code?
    I use MPLAB X IDE v5.40.
     
    Thank you in advance.
    Best Regards,
    John

    // <editor-fold defaultstate="collapsed" desc="Configuration bits">

    // CONFIG1
    // External Oscillator Selection (Oscillator not enabled)
    #pragma config FEXTOSC = OFF    

    // Reset Oscillator Selection (HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1)
    #pragma config RSTOSC = HFINTOSC_64MHZ

    // CONFIG2
    // Clock out Enable bit (CLKOUT function is disabled)
    #pragma config CLKOUTEN = OFF
    // PRLOCKED One-Way Set Enable bit (PRLOCKED bit can be cleared and
    // set only once)
    #pragma config PR1WAY = ON
    // Clock Switch Enable bit (The NOSC and NDIV bits cannot be changed
    // by user software)
    #pragma config CSWEN = OFF
    // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
    #pragma config FCMEN = OFF

    // CONFIG3
    // MCLR Enable bit
    // (If LVP = 0, MCLR pin is MCLR;
    // If LVP = 1, RE3 pin function is MCLR)
    #pragma config MCLRE = EXTMCLR
    // Power-up timer selection bits (PWRT is disabled)
    #pragma config PWRTS = PWRT_OFF
    // Multi-vector enable bit (Multi-vector enabled,
    // Vector table used for interrupts)
    #pragma config MVECEN = ON
    // IVTLOCK bit One-way set enable bit (IVTLOCKED bit can be cleared
    // and set only once)
    #pragma config IVT1WAY = ON
    // Low Power BOR Enable bit (Low-Power BOR disabled)
    #pragma config LPBOREN = OFF
    // Brown-out Reset Enable bits (Brown-out Reset disabled)
    #pragma config BOREN = OFF

    // CONFIG4
    // Brown-out Reset Voltage Selection bits (Brown-out Reset Voltage (VBOR)
    // set to 1.9V)
    #pragma config BORV = VBOR_1P9
    // ZCD Disable bit (ZCD module is disabled.
    // ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
    #pragma config ZCD = OFF
    // PPSLOCK bit One-Way Set Enable bit (PPSLOCKED bit can be cleared
    // and set only once; PPS registers remain locked after one clear/set cycle)
    #pragma config PPS1WAY = ON
    // Stack Full/Underflow Reset Enable bit (Stack full/underflow
    // will cause Reset)
    #pragma config STVREN = ON
    // Low Voltage Programming Enable bit (HV on MCLR/VPP must be used
    // for programming)
    #pragma config LVP = OFF
    // Extended Instruction Set Enable bit (Extended Instruction Set and
    // Indexed Addressing Mode disabled)
    #pragma config XINST = OFF

    // CONFIG5
    // WDT Period selection bits (Divider ratio 1:65536;
    // software control of WDTPS)
    #pragma config WDTCPS = WDTCPS_31
    // WDT operating mode (WDT Disabled; SWDTEN is ignored)
    #pragma config WDTE = OFF

    // CONFIG6
    // WDT Window Select bits (window always open (100%);
    // software control; keyed access not required)
    #pragma config WDTCWS = WDTCWS_7
    // WDT input clock selector (Software Control)
    #pragma config WDTCCS = SC

    // CONFIG7
    // Boot Block Size selection bits (Boot Block size is 512 words)
    #pragma config BBSIZE = BBSIZE_512
    // Boot Block enable bit (Boot block disabled)
    #pragma config BBEN = OFF
    // Storage Area Flash enable bit (SAF disabled)
    #pragma config SAFEN = OFF
    // Background Debugger (Background Debugger disabled)
    #pragma config DEBUG = OFF

    // CONFIG8
    // Boot Block Write Protection bit (Boot Block not Write protected)
    #pragma config WRTB = OFF
    // Configuration Register Write Protection bit (Configuration registers
    // not Write protected)
    #pragma config WRTC = OFF
    // Data EEPROM Write Protection bit (Data EEPROM not Write protected)
    #pragma config WRTD = OFF
    // SAF Write protection bit (SAF not Write Protected)
    #pragma config WRTSAF = OFF
    // Application Block write protection bit (Application Block not write
    // protected)
    #pragma config WRTAPP = OFF

    // CONFIG10
    // PFM and Data EEPROM Code Protection bit (PFM and Data EEPROM code
    // protection disabled)
    #pragma config CP = OFF

    // </editor-fold>

    #include <xc.h>

    #define IVT                     0x00008

    void main(void)
    {
        asm("nop");
        ANSELBbits.ANSELB0 = 0;
        ANSELBbits.ANSELB1 = 0;
        ANSELBbits.ANSELB2 = 0;
        ANSELBbits.ANSELB3 = 0;
        
        TRISBbits.TRISB0 = 1;
        TRISBbits.TRISB1 = 1;
        TRISBbits.TRISB2 = 1;
        TRISBbits.TRISB3 = 1;
        
        WPUBbits.WPUB0 = 1;
        WPUBbits.WPUB1 = 1;
        WPUBbits.WPUB2 = 1;
        WPUBbits.WPUB3 = 1;
        
        //IOCBF = IOCBF & 0xF8;
        IOCBFbits.IOCBF0 = 0;
        IOCBFbits.IOCBF1 = 0;
        IOCBNbits.IOCBN0 = 1;
        IOCBNbits.IOCBN1 = 1;
        IPR0bits.IOCIP = 1;
        PIR0bits.IOCIF = 0; // Probably not applicable
        PIE0bits.IOCIE = 1;
        
        INTCON0bits.INT0EDG = 0;
        INTCON0bits.INT1EDG = 0;
        INT0PPS = 0b00001010;
        INT1PPS = 0b00001011;
        
        IPR1bits.INT0IP = 1;
        PIR1bits.INT0IF = 0;
        PIE1bits.INT0IE = 1;
        IPR6bits.INT1IP = 0;
        PIR6bits.INT1IF = 0;
        PIE6bits.INT1IE = 1;
        
        // Global interrupts
        INTCON0bits.IPEN = 1;
        INTCON0bits.GIEL = 1;
        INTCON0bits.GIEH = 1;
        
        for(;;)
        {
            asm("nop");
            asm("nop");
        }
        return;
    }

    void __interrupt(irq(INT0), base(IVT), high_priority) INT0_ISR()
    {
        asm("nop");
        PIR1bits.INT0IF = 0;
        //LATDbits.LATD0 = 0;
    }

    void __interrupt(irq(INT1), base(IVT), low_priority) INT1_ISR()
    {
        asm("nop");
        PIR6bits.INT1IF = 0;
        //LATDbits.LATD0 = 1;
    }

    void __interrupt(irq(IOC), base(IVT), high_priority) IOC_ISR()
    {
        asm("nop");
        if (IOCBFbits.IOCBF2 == 1)
        {
            IOCBFbits.IOCBF2 = 0;
            //LATDbits.LATD1 = 0;
        }
        else if (IOCBFbits.IOCBF3 == 1)
        {
            IOCBFbits.IOCBF3 = 0;
            //LATDbits.LATD1 = 1;
        }
    }

    void __interrupt(irq(default), base(IVT), high_priority) DEFAULT_ISR()
    {
        asm("nop");
    }


    #18
    GeorgePauley
    Moderator
    • Total Posts : 1268
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/08/06 09:25:22 (permalink)
    +2 (2)
    OK there are two problems.
     
    First the simulator code, incorrectly, will not set the PIR0.IOCIF flag if the PIE0.IOCIE flag is not set to 1.  Rookie mistake by a new simulator team member.  (At least he was new 5 years ago when the code was written mr green: mr green)  We will fix that.

    Now you might be thinking, but this shouldn't matter as I'm setting PIE0.IOCIE to 1.  Which leads to the second problem.  The simulator works off of device data files provided by the silicon teams.  For some reason the device data file for PIC18F57Q43 has PIE0.IOCIE marked as read-only.  So the simulator is disallowing your attempt to set IOCIE to 1.  I will ask the silicon team to update the device data file.

    Until both of these issues are fixed, I'm afraid you're not going to trigger this interrupt in the simulator.  sad: sad
    #19
    jvourv
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2010/03/07 08:44:57
    • Location: 0
    • Status: offline
    Re: Input Interrupt not working with MPLAB X Simulator 2020/08/06 22:45:14 (permalink)
    0
    Thank you very much George for your reply.
    In fact, I hadn't noticed that PIE0.IOCIE was not set, I was too confident that it was set.
    I monitored only individual flags in the registers IOCxF and PIR0.IOCIF which were not set.
    I will wait a next MPLAB X IDE version for the fix.
    Thanks again.
    Best Regards,
    John
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5