PIC32MZ2048EFH144 - compiler problem

General discussion on mikroBasic PRO for PIC32.
Author
Message
loojade
Posts: 35
Joined: 04 Oct 2008 03:03

PIC32MZ2048EFH144 - compiler problem

#1 Post by loojade » 23 Dec 2021 11:49

Hello,

I would ask some help/suggestion because I am new with PIC32MZ. I am developping a custom board with some inertial MEMS sensors. I am moving to MZ from DSPIC33EP. Now I am debugging the board but I am blocked for some inexpicable reason. The code is quite long but basically the program (after the initialization) jumps into a loop to let a led blinking. into the loop I have some procedures. In one of them I use a GOTO to jump to the end of procedure and see where the program do strange things.

Code that is working:

Code: Select all

    'X
    word_appo = accelerometer_x_word 'and %1000000000000000
    goto fine_get_data_da_gyro 'jump to the end of procedure
    if word_appo <= 32767 then
       accelerometer_x = accelerometer_x_word / 1024.0
    else
       word_appo = not accelerometer_x_word
       word_appo = word_appo + 1
       accelerometer_x =  word_appo / (-1024.0)
    end if

Code that doesn't work

Code: Select all

    'X
    word_appo = accelerometer_x_word 'and %1000000000000000
    if word_appo <= 32767 then
	goto fine_get_data_da_gyro 'jump to the end of procedure
       accelerometer_x = accelerometer_x_word / 1024.0
    else
       word_appo = not accelerometer_x_word
       word_appo = word_appo + 1
       accelerometer_x =  word_appo / (-1024.0)
    end if



basically when I force to execute the "IF", the program stop and the led stop to blink. I got the same problem if I introduce a floating point operation (example: accelerometer_x = accelerometer_x_word / 1024.0).
Any idea about why this line block the program? thanks very much

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: PIC32MZ2048EFH144 - compiler problem

#2 Post by darko.ilijevski » 24 Dec 2021 11:21

Hello,
First of all, - welcome to the world of PIC32MZ :)

Could you create a minimal code that demonstrates this behavior and pack the entire project (all files included) in a .zip archive?
Maybe the problem is someplace else (initialization, config settings, etc)

Best regards,
Darko
BR,
Darko

loojade
Posts: 35
Joined: 04 Oct 2008 03:03

Re: PIC32MZ2048EFH144 - compiler problem

#3 Post by loojade » 24 Dec 2021 12:22

Hello Darko,

Thanks for your help. I attach two project: one works (led blink) and the other one it doesn't work. I attach also the difference in the code that change the behaviour of the program.
Attachments
does not working.jpg
does not working.jpg (134.42 KiB) Viewed 2644 times
working.zip
(445.53 KiB) Downloaded 44 times
does not working.zip
(446.71 KiB) Downloaded 51 times

loojade
Posts: 35
Joined: 04 Oct 2008 03:03

Re: PIC32MZ2048EFH144 - compiler problem

#4 Post by loojade » 24 Dec 2021 12:23

this is the variation of the code that let the led blink.
Attachments
working.jpg
working.jpg (167.75 KiB) Viewed 2644 times

loojade
Posts: 35
Joined: 04 Oct 2008 03:03

Re: PIC32MZ2048EFH144 - compiler problem

#5 Post by loojade » 24 Dec 2021 12:28

I checked all the code I execute before the problem and basically I set I/O port, peripherical and I set value to variables. Until the point where I get the error I do not execute any mathematical operation. May be it is something related to the FPU?

I attach also the code of PIC32
Attachments
Immagine 2021-12-24 122731.jpg
Immagine 2021-12-24 122731.jpg (217.34 KiB) Viewed 2644 times

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

Re: PIC32MZ2048EFH144 - compiler problem

#6 Post by yo2lio » 29 Dec 2021 18:59

Hi,

The problem is related with the FPU.

Try to compile the same code with ECH144 instead of EFH144. In this mode, the compiler will not use the FPU.

I had this problem, two years ago, with PIC32MZ2048EFH064.

To solve the problem, I do a lot's of workaround and I wrote a part of the code in ASM (the part with FPU)

I can help ME team to solve this problem, but they must be fast responsive.
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
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: PIC32MZ2048EFH144 - compiler problem

#7 Post by darko.ilijevski » 29 Dec 2021 20:01

Hello to both,
We have been using this particular MCU (064, 100, and 144 pin versions) and I do not recall having too many issues with it. Then again, I haven't been active on the forum for a while so I might have missed the reports.

Yo2lio, as you say you've seen this behavior before, would you be so kind to post a minimal project (without using sensors) showing this erratic behavior? It would help us a lot. Also, I would test it in our new mikroAI compilers (Necto Studio) and see if I can replicate the same behavior there.

I just hope it is not in the MCU's errata; we can do little in that case if you have a misfortune of having the affected silicon revision.

BR,
Darko
Last edited by darko.ilijevski on 29 Dec 2021 23:36, edited 1 time in total.
BR,
Darko

loojade
Posts: 35
Joined: 04 Oct 2008 03:03

Re: PIC32MZ2048EFH144 - compiler problem

#8 Post by loojade » 29 Dec 2021 23:07

Hello Darko

Thanks I will try to compile as you suggested with another pic32 to avoid the use of FPU. Then in this project I use a lot of other libraries like CAN, I2C so I hope that the rest of the code will work properly 😅
yo2lio wrote:
29 Dec 2021 18:59
Hi,

The problem is related with the FPU.

Try to compile the same code with ECH144 instead of EFH144. In this mode, the compiler will not use the FPU.

I had this problem, two years ago, with PIC32MZ2048EFH064.

To solve the problem, I do a lot's of workaround and I wrote a part of the code in ASM (the part with FPU)

I can help ME team to solve this problem, but they must be fast responsive.

loojade
Posts: 35
Joined: 04 Oct 2008 03:03

Re: PIC32MZ2048EFH144 - compiler problem

#9 Post by loojade » 03 Jan 2022 11:40

Hello and happy new year,

I tried to compile the project with ECH144 instead of EFH144 but it doesn't work. The compiler give some error with the USB library (that is used into the project). So I am still in trouble.... any help?

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

Re: PIC32MZ2048EFH144 - compiler problem

#10 Post by yo2lio » 03 Jan 2022 12:21

Hi,

A Happy New Year!

1. Try to move all local variables to global variables, specially the float type.

If still not work:

2. Try to do not use float math in interrupt.

You have there in CAN interrupt:

can_vfr = word_can / 100.0
can_vrr = word_can / 100.0

Find an workaround for this.
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

loojade
Posts: 35
Joined: 04 Oct 2008 03:03

Re: PIC32MZ2048EFH144 - compiler problem

#11 Post by loojade » 03 Jan 2022 12:32

Thanks,

Exactly what I have done just 3 minutes ago!!! the problem was into the interrupt routine of CAN. Doing a float math there is not possible with this micro. I did it with dsPIC33 without any problems but with the PIC32 MZ you can't do it.
Problem fixed! thanks

yo2lio wrote:
03 Jan 2022 12:21
Hi,

A Happy New Year!

1. Try to move all local variables to global variables, specially the float type.

If still not work:

2. Try to do not use float math in interrupt.

You have there in CAN interrupt:

can_vfr = word_can / 100.0
can_vrr = word_can / 100.0

Find an workaround for this.

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

Re: PIC32MZ2048EFH144 - compiler problem

#12 Post by yo2lio » 03 Jan 2022 12:43

MZ MCU, it's a very very good MCU.

Probably something in the compiler with shadows registers, stack, etc...

I'm sure that ME team will solve this.

So, ME team, PIC32MZ with FPU, can't do any float math in interrupt.

I'm glad that you solve the problem. :D
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
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: PIC32MZ2048EFH144 - compiler problem

#13 Post by darko.ilijevski » 04 Jan 2022 12:34

Hello,

So, if I understood you correctly, the problem is using float numbers while in ISR, correct?
I will make a test - a Timer will trigger an interrupt, and I will try dividing some numbers in several different ways (as global/volatile variables, as literals, etc).
I will let you know what I have found out.

Best regards,
Darko
BR,
Darko

loojade
Posts: 35
Joined: 04 Oct 2008 03:03

Re: PIC32MZ2048EFH144 - compiler problem

#14 Post by loojade » 04 Jan 2022 13:27

Yes you’re right. My floating maths were in the CAN interrupt procedure

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

Re: PIC32MZ2048EFH144 - compiler problem

#15 Post by yo2lio » 04 Jan 2022 16:25

Hi,

Mileta, solve one year ago, the 64 bit division problem.

If you solve the math float in interrupt problem, I can test in the big software, that now are compiled with ECH...

Thank you very much.

PS: I use MP...
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

Post Reply

Return to “mikroBasic PRO for PIC32 General”