PIC32MZ Interrupt bug

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
ermok
Posts: 25
Joined: 19 Sep 2013 11:36

PIC32MZ Interrupt bug

#1 Post by ermok » 17 Jan 2019 09:42

Hey, ME Team

We had a big problem with interrupt priorities, they actually never worked. But we found reason and solution

there is asm code

Code: Select all

RDPGPR	SP, SP
ADDIU	SP, SP, -16
SW	R30, 12(SP)
MFC0	R30, 12, 2
SW	R30, 8(SP)
MFC0	R30, 14, 0
SW	R30, 4(SP)
MFC0	R30, 12, 0   
SW	R30, 0(SP)
INS	R30, R0, 1, 15  
ORI	R30, R0,5120 // bug; must be: ORI	R30, R30,5120  
MTC0	R30, 12, 0   
Reason why interrupt priorities not work is that every time when interrupt is called, code switches interrupts off so there is on way
that higher priority interrupt will call the handler. After finishing interrupt routine, asm enables interrupts.

We fixed it in asm and proved that priorities work after fix.

ORI R30, R0,5120 // bug; must be: ORI R30, R30,5120


Also, please consider changing help and example files where you sugested to use IRQ priority 7 is not the best idea.
We prefer irq priority 4 as base priority. It gives us a way to use higher or lower priorities than base priority.
Using Priority 7 as base priority gives you no easy way to add something that is higher. Only changing all the code
and facing lot's of code flow logic bugs that are hard to find. Etc you receive something from uart, decided to answer,
but uart tx code uses tx irq with higher priority, it not happens, and code enters deadlock. We had that situation actually

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: PIC32MZ Interrupt bug

#2 Post by yo2lio » 28 Jan 2020 06:00

Hello,

I have the same problems with PIC32MZ and priority interrupts.

Mikroe team, can you help us? With some compiler updates?

Thank you very much.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

chimimic
Posts: 178
Joined: 29 Sep 2007 14:35
Location: France
Contact:

Re: PIC32MZ Interrupt bug

#3 Post by chimimic » 28 Jan 2020 08:32

Hello,

I think I have the same problem with PIC32MX.
Since last month I searched reason why PIC enter in "deadlock" (1) in some interrupts circonstances...
(ints on UART4, INT0, INT1, INT4, INT3/CN15, TIMER1)

Code: Select all

_Interrupt_INT4:
RDPGPR	SP, SP
ADDIU	SP, SP, -16
SW	R30, 12(SP)
MFC0	R30, 12, 2
SW	R30, 8(SP)
MFC0	R30, 14, 0
SW	R30, 4(SP)
MFC0	R30, 12, 0
SW	R30, 0(SP)
INS	R30, R0, 1, 15
ORI	R30, R0, 7168
MTC0	R30, 12, 0
Could this be the same scenario?

Thanks,
Remy

(1) Curiously, the INT0 code can be executed 1 time (and no more after) during this "deadlock"...

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PIC32MZ Interrupt bug

#4 Post by filip » 29 Jan 2020 13:01

Hi,

Can you please attach the minimal project that reproduces this issue ?

Regards,
Filip.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: PIC32MZ Interrupt bug

#5 Post by yo2lio » 29 Jan 2020 19:21

Hello Filip,

Here is the code:

Code: Select all

{
 * Project name:
     Timer1_interrupt (Timer1 interrupt test)
 * Copyright:
     (c) Mikroelektronika, 2017.
 * Revision History:
     20170718:
       - Initial release;
 * Description:
     This code demonstrates how to use Timer1 and it's interrupt.
     Program toggles LEDs on PORTB.
 * Test configuration:
     MCU:             P32MZ2048EFH144
                      http://ww1.microchip.com/downloads/en/DeviceDoc/60001320D.pdf
     Dev.Board:       EasyPIC Fusion v7
                      http://www.mikroe.com/easypic-fusion/
     Oscillator:      FRC PLL, 200.000MHz
     Ext. Modules:    None.
     SW:              mikroPascal PRO for PIC32
                      http://www.mikroe.com/mikropascal/pic32/
 * NOTES:
     - Turn on LEDs on PORTB/H and PORTB/L at SW15
     - Use the ORG directive to declare your procedure as an interrupt service routine.
       The address after the ORG statement indicates which interrupt you will assign to
       your procedure.
       Please consult the datasheet for your MCU for interrupt vector table
       details and available addresses.
     - Also, consult mikroC PRO for PIC32 help on how to use interrupts.
 }
 
program Timer1_interrupt;

procedure Timer1Int(); iv IVT_TIMER_1; ilevel 7; ics ICS_SRS;
begin
  T1IF_bit := 0;             // Clear T1IF
  LATB := not PORTB;         // Invert PORTB
end;

procedure Timer2_3Interrupt(); iv IVT_TIMER_3; ilevel 2; ics ICS_SRS;
begin
  T3IF_bit	 := 0;
  delay_ms(999);
  TMR1		 := 0;
  T1IF_bit := 0;
end;

//Timer2/3
//Prescaler 1:1; PR3 Preload = 1525; PR2 Preload = 59125; Actual Interrupt Time = 1
procedure InitTimer2_3();
begin
  T2CON	 := 0x8008;
  T3CON	 := 0x0;
  TMR2		 := 0;
  TMR3		 := 1520;
  T3IP0_bit	 := 1;
  T3IP1_bit	 := 0;
  T3IP2_bit	 := 0;
  T3IF_bit	 := 0;
  T3IE_bit	 := 1;
  PR2		 := 57600;
  PR3		 := 1525;
end;

//Timer1
//Prescaler 1:256; PR1 Preload = 39063; Actual Interrupt Time = 100.00128 ms
procedure InitTimer1();
begin
  T1CON	 := 0x8030;
  T1IP0_bit	 := 1;
  T1IP1_bit	 := 1;
  T1IP2_bit	 := 1;
  T1IF_bit	 := 0;
  T1IE_bit	 := 1;
  PR1		 := 39063;
  TMR1		 := 0;
end;

begin
  ANSELB := 0;               // Initialize AN pins as digital
  TRISB  := 0;               // initialize PORTB as output
  LATB   := 0xAAAA;          // Initialize PORTB value

  InitTimer2_3();
  
  InitTimer1();
  
  EnableInterrupts();        // Enable all interrupts
end.
Timer2/3 priority 2, 1 sec interrupt, wait 999ms in interrupt.

Timer1 priority 7, 100ms, flash leds.

The leds will not flash.

Thank you.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PIC32MZ Interrupt bug

#6 Post by filip » 30 Jan 2020 15:10

Hi,

As a workaround, can you add asm EI at the beginning of the interrupt routines and see if this helps ?

Regards,
Filip.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: PIC32MZ Interrupt bug

#7 Post by yo2lio » 05 Feb 2020 13:41

Thank you Filip, I will try and let you know the result.

I have another issue: I run in simulator a part of the code, where the time was critical.
The simulator say 4uS but in reality was around 6.2uS.
Seems that the simulator not count correctly, or count but round the decimals... or so...

Thank you very much.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PIC32MZ Interrupt bug

#8 Post by filip » 07 Feb 2020 16:01

Hi,

Which part of the code have you run through the simulator ?

Regards,
Filip.

Post Reply

Return to “mikroPascal PRO for PIC32 General”