Compiler error when using P24FJ64GA002

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
dhfp77
Posts: 3
Joined: 30 Jun 2019 22:11

Compiler error when using P24FJ64GA002

#1 Post by dhfp77 » 18 Jul 2019 21:14

Hi all,

I have run into a problem on a P24FJ64GA002 MCU when trying to use a for loop to run through a constant array, e.g.

Code: Select all

dim name as char[16]
i as byte

const given_name as char[16] = ("J", "O", "H", "N", "S", "M", "I", "T", "H")

''' Doesn't work
for i = 0 to 8
    name[i] = given_name[i] ''result: name[i] = ÿ, or ò, or â, etc...
next i

''' Does work
name[0] = given_name[0]
name[1] = given_name[1]
''' ...
name[8] = given_name[8]
For whatever reason, the for loop will not give me the correct values from the constant array. It will instead spit out and assign random garbage characters to the non-const array locations (sometimes the same character, sometimes incrementing).

Notes:
  • Assigning non-constant arrays to non-constant arrays does work.
  • Manually assigning const array to non-const array does work.
  • If the const to non-const assignment for loop is high up enough in the code, the optimizer will automatically assign the correct values -- but if it is far enough down in the code it will not and will produce garbage assignments again.
  • I have tried using a loop using pointers and their values, but there is a bevy of errors associated with that too (the IDE shows the correct 'value' that is being pointed to, but the address is pointing to ~0x8000 above where the correct address is at and I am unable to access the correct value).
I believe this is a compiler bug.

If there are any workarounds that will allow me to assign const array values to non-const arrays without having to manually type out hundreds of assignment lines please let me know. I have tried just about everything to make this work and I am not finding any success.

Thank you for your time.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Compiler error when using P24FJ64GA002

#2 Post by stefan.filipovic » 22 Jul 2019 10:25

Hi,

Welcome to the mikroE forum.

Unfortunately, I have not managed to reproduce the same behavior.
Could you please zip and attach a minimal project which reproduces this issue?

Are you using the latest version (v.7.1.0) of mikroBasic PRO for dsPIC?

Kind regards,
Stefan Filipović

dhfp77
Posts: 3
Joined: 30 Jun 2019 22:11

Re: Compiler error when using P24FJ64GA002

#3 Post by dhfp77 » 22 Jul 2019 23:58

Hi Stefan,

I have reduced the project to a single file which includes the 'for loop' which is giving me trouble, and I have attached it to this post as a ZIP file (in the folder 'Minimal Code'). I have included in the ZIP file a text file detailing the steps to reproduce the error, and images that show the MCU configuration and output settings that I am using.

I am also using the latest version of mikroBasic PRO for dsPIC (v.7.1.0).

Please let me know whether or not you are able to reproduce the error, and if there are any fixes or workarounds you discover.

Thank you again.

[edited to remove file after solution was given]
Last edited by dhfp77 on 24 Jul 2019 20:58, edited 2 times in total.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Compiler error when using P24FJ64GA002

#4 Post by stefan.filipovic » 24 Jul 2019 11:38

Hi,

You need to set Program Space Visibility in Data Space Enable bit (PSV_bit) to 1, to be able to read constants from program memory.
You can read more about PSV usage here:
https://www.microchip.com/forums/m299445.aspx

Kind regards,
Stefan Filipović

dhfp77
Posts: 3
Joined: 30 Jun 2019 22:11

Re: Compiler error when using P24FJ64GA002

#5 Post by dhfp77 » 24 Jul 2019 20:58

stefan.filipovic wrote:Hi,

You need to set Program Space Visibility in Data Space Enable bit (PSV_bit) to 1, to be able to read constants from program memory.
You can read more about PSV usage here:
https://www.microchip.com/forums/m299445.aspx

Kind regards,
Oh gosh, that was the problem? That's embarrassing for me :lol:

Thank you for your help, Stefan. I greatly appreciate it.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Compiler error when using P24FJ64GA002

#6 Post by stefan.filipovic » 25 Jul 2019 14:26

Hi,

You're welcome.

Kind regards,
Stefan Filipović

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”