Interrupt help.

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
Ianr
3rd Party Developer
Posts: 120
Joined: Fri 2007-03-09 14:03

Interrupt help.

Post by Ianr »

Another for Ettore!!
Sorry, I'm back. I have never ( I know! right. ) used both low / high priority interrupts. I have the need now.

So using the below (I also tried the old way)

Code: Select all

void __interrupt(low_priority) ISR1()
and

Code: Select all

void __interrupt(high_priority) ISR2()
I set IPEN to 1 and enable the TMR1IE and the priority to high (TMR1IP = 1)
but it doesn't fire... BUT! using RC1IE = 1 and RC1IP = 0 the high interrupt fires not the low.
Its driving me nuts.. I haven't tried on the actual device yet, I thought I'd ask here first.

If I set IPEN to 0 and just use "void interrupt ISR()" both work.

Any pointers?
Ettore
Labcenter Staff
Posts: 2931
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Interrupt help.

Post by Ettore »

Maybe you didn't enable the low peripheral interrupts. Anyway, I attach a simple test showing the priority interrupts just in case of two coincident pulses. I alaso attach the source code in the post and schematic screen shot just in case you don't have the latest Proteus version.
test.pdsprj
(18.15 KiB) Downloaded 423 times

Code: Select all

/* Main.c file generated by New Project wizard
 *
 * Created:   lun ago 21 2023
 * Processor: PIC18F452
 * Compiler:  MPLAB XC8
 */

#include <xc.h>
#pragma config OSC=HS, WDT=OFF

void __interrupt(high_priority) ISR2()
 {  PORTAbits.RA2 = 1;
    __nop();
    __nop();
    PORTAbits.RA2 = 0;   
    INT0IF = 0;   
  }

void __interrupt(low_priority) ISR1()
 { 
   PORTAbits.RA3 = 1; 
   __nop();
   __nop();
   PORTAbits.RA3 = 0;
   INT1IF = 0;    
 }

void main(void)
 { 
   ADCON1 = 0x07;
   TRISA = 0;
   PORTE = 0;
   TRISE = 0;
   PORTB = 0;
   TRISB = 0xff;
   IPEN  = 1;    // Enable Priority levels on Interrupts. 
   INT0IE = 1;   // INT0 External Interrupt Enable.
   INT1IE = 1;   // INT1 External Interrupt Enable.
   INT1IP = 0;   // External Interrupt on INT1 is Low Priority.
   GIEL   = 1;   // Enable all low peripheral interrupts.
   GIEH   = 1;   // Enable all global interrupts.
    
   // Write your code here
   while (1)
    { __nop();
    }
 }

Immagine 2023-08-21 151936.jpg
Immagine 2023-08-21 151936.jpg (173.18 KiB) Viewed 838 times
Kind regards,
Ettore Arena - Labcenter Electronics.
Ianr
3rd Party Developer
Posts: 120
Joined: Fri 2007-03-09 14:03

Re: Interrupt help.

Post by Ianr »

Thanks Ettore.
I'll test it out tonight.
I'm using a PIC18F46K22 and using RC1IE and TMR1IE .. I will compare your Init to mine.

As yours is working I would imagine it'll be me that has a typo somewhere.

I'll let you know.. I will PM the code I'm using if it don't work..
Maybe its my age... Bit over the hill now..
Ianr
3rd Party Developer
Posts: 120
Joined: Fri 2007-03-09 14:03

Re: Interrupt help.

Post by Ianr »

Okay! I see the issue.

On the first run I forgot to set the timer running, but soon cleared that fault.
But the RC1IE only triggered the high interrupt even though it is set for low.

BUT! it wasn't.. If I had run it through I would have seen that it was working fully but the COFF was pointing incorrectly.
Well not incorrectly persé, the optimization kicks in and the breakpoint isn't shown although the code in the low interrupt is executed.

Sorry about that. XC8 not Labcenter..
Ettore
Labcenter Staff
Posts: 2931
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Interrupt help.

Post by Ettore »

I'm glad it works.
Kind regards,
Ettore Arena - Labcenter Electronics.
Post Reply