Problem with conversion FloatToString

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
michaF
Posts: 4
Joined: 01 Dec 2019 19:08

Problem with conversion FloatToString

#1 Post by michaF » 06 May 2020 18:54

Hi Guys,
I have problem converting a real number to string with the conversion lib.
'FloatToStr(temperatur, temp_text);'
Temperatur is REAL and temp_text is array[23] of char;
In the debugger, the value in the variable before execute FloatToStr is: 2.364854E + 001.
After conversion the value in the variable is: 2.595782E-006.
That can't be right. What am I doing wrong.
Can someone help me.
Greetings micha

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

Re: Problem with conversion FloatToString

#2 Post by filip » 07 May 2020 14:30

Hi,

Can you please attach the code snippet that demonstrates this issue ?

Regards,
Filip.

michaF
Posts: 4
Joined: 01 Dec 2019 19:08

Re: Problem with conversion FloatToString

#3 Post by michaF » 07 May 2020 20:28

Hi filip,
I have minimized the program so far that the problem can be reproduced.
If the variable temperature and temperature_text are declared global, the problems arise.
You can see that in the debugger (the variables in the watch list).
However, if the variables are declared in the function and not global, the problem does not occur.

Regards,
micha

Code: Select all

program MyProject;
//Test configuration:
//     MCU:             STM32F401RE
//     Dev.Board:       NUCLEO-F401RE

{ Declarations section }
var
 x : byte;
 //
 temperatur : real;
 temperatur_text : array[15] of char;

 //-----------------------------------------------------------
Function werte():byte;
//var
//   temperatur : real;
//   temperatur_text : array[15] of char;
begin
  temperatur :=0;
  temperatur:= 23.64854;
  FloatToStr(temperatur, temperatur_text);
  result := 0;
end;
//=============================================================
begin
  { Main program }
  while true do
  begin
   x := werte();
   //
   Delay_ms(1000);
  end;
end.

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

Re: Problem with conversion FloatToString

#4 Post by filip » 08 May 2020 09:16

Hi,

I have tried your code but it was working OK, please see the screenshot below :
test.JPG
test.JPG (172.1 KiB) Viewed 2808 times
Which version of the compiler are you using ?

Regards,
Filip.

michaF
Posts: 4
Joined: 01 Dec 2019 19:08

Re: Problem with conversion FloatToString

#5 Post by michaF » 08 May 2020 16:13

Hi filip,
I am using the latest version (6.2).
I think I found the problem:
Optimization level was set to ZERO under the Option -> 'OUTPUT SETTING'.
If I put something else here but 'Zero', everything works under soft simulator or hardware debuger.
Can you check this ?

Regards,
micha

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

Re: Problem with conversion FloatToString

#6 Post by filip » 11 May 2020 14:51

Hi,

I apologize for the inconvenience, I have reproduced this issue.

Please find the updated __Lib_Conversions.emcl in the attachment, place it in the \mikroPascal PRO for ARM\Uses\ST M4\ folder instead of the existing one.

This should solve your issue.

Regards,
Filip.
Attachments
__Lib_Conversions.rar
(18.51 KiB) Downloaded 85 times

michaF
Posts: 4
Joined: 01 Dec 2019 19:08

Re: Problem with conversion FloatToString

#7 Post by michaF » 12 May 2020 22:13

Hi filip,
thanks . I will test it in the next few days.

Another question: is there a description of each optimization level?

Regards
micha

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

Re: Problem with conversion FloatToString

#8 Post by filip » 13 May 2020 08:13

Hi,

Not at the moment, but we are planning to add the description in the help file

Regards,
Filip.

Marniftarr
Posts: 3
Joined: 12 May 2021 10:41

Re: Problem with conversion FloatToString

#9 Post by Marniftarr » 12 May 2021 11:51

Hi all. I have same issue.

I replaced "__Lib_Conversions.emcl" file. The problem is not solved.

I have Mikroe M4 with STM32F415RG controller.

Any solutions ?

Post Reply

Return to “mikroPascal PRO for ARM General”