to string not working on hardware

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times

to string not working on hardware

Post by brandonb »

trying to print on display unsigned integer numbers using to string function, works in simulation, on hardware it displays signed negative representations of the unsigned number, is there a quick code fix for this or am i doing something wrong, thanks
Attachments
freq gen.fcf
(20.14 KiB) Downloaded 271 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: to string not working on hardware

Post by medelec35 »

Hi Brandon,
I believe its a bug (if not a bug then I belive FC5 should be able to show correct UINT on LCD without any additional code) .

I have used an UINT variable and got it to increment every 50ms
Then LCD would show UINT and UINT converted to string simultaneously.
In the Flowcode simulator string is shown correct but the UINT variable is showing singed INT on the LCD
In variable manager they are both shown as correct values.
On hardware both UINT variable and string are displaying signed INT and not UNIT.
So it's my guess it's the LCD routine that is printing wrong characters( its assuming variables are signed integers)?
UNIT.png
(248.64 KiB) Downloaded 2399 times
Martin.
Attachments
UINT test.fcf
(8.5 KiB) Downloaded 264 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times

Re: to string not working on hardware

Post by brandonb »

weird, ....on a side note i noticed on a ccp pwm frequency i need to hit that on a 16f1938 the 4Mhz internal osc is osccon=0x68 and 0x60 is the 2Mhz

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: to string not working on hardware

Post by medelec35 »

Has not displaying UNIT values on LCD been resolved yet please?

Martin
Martin

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: to string not working on hardware

Post by JonnyW »

Hi Martin. I am not the most knowledgeable about the components but I don't think it has.

It will be an issue with type-casting in C and may not be too straightforward to fix. By the time the LCD routine decides to convert the value to a string to print it, the value is a signed 16 bit value. The most immediate solution is to change this to pass a long value in (32-bit), but I think this may have memory and/or speed implications.

From the looks of the LCD components PrintNumber() C code, this will need a decent sized mod to make it work for 32-bit numbers, which at present is the only option. I doubt this will be fixed in the near future.

Jonny

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: to string not working on hardware

Post by medelec35 »

Thanks Jonny.
JonnyW wrote: It will be an issue with type-casting in C and may not be too straightforward to fix. By the time the LCD routine decides to convert the value to a string to print it, the value is a signed 16 bit value.
That's interesting.
Just brain storming from a non expert (so please don't laugh too much :P ) Could a solution be to always use unsigned integer for the print routine?
Then perhaps use a int to string routine and display the string value?
Since if int used was signed, the -ve sign will be printed
I guess for that to happen the int to string routine should also use unsigned.
I'm just waking up so maybe talking rubbish anyway :roll: :lol:

Martin
Martin

User avatar
Steve
Matrix Staff
Posts: 3434
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: to string not working on hardware

Post by Steve »

The PrintNumber macro for the LCD component expects an "INT" type (i.e. MX_SINT16), which in Flowcode is a signed integer between -32768 and +32767. Passing a value beyond these bounds is not defined.

In a similar way, the "ToString" function expects a signed long (MX_SLONG), but passing a large unsigned long to it (e.g. 4000000000) causes problems - it is converted to a negative value, despite the number supposedly being unsigned.

This is something we will look into and try to address in a future update.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: to string not working on hardware

Post by medelec35 »

Thanks Steve,
I was only guessing some ideas and since Jonny said about fix not being easy, tried to look at it in a different way and hoping I could suggest a temporary fix.
How wrong was I :lol:
Not doubting either of you, as you two + Ben would know how it all works far more than I ever would.
From the sounds of it the solution is way out of my league, So will leave anymore thoughts to the experts :D
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: to string not working on hardware

Post by Benj »

Hello,

Adding this definition to the supplementary code window may help solve the issue for unsigned 16-bit values.

#define MX_STRF_LONG

Post Reply