Page 1 of 1
to string not working on hardware
Posted: Sun May 27, 2012 8:35 am
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
Re: to string not working on hardware
Posted: Sun May 27, 2012 10:17 am
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.
Re: to string not working on hardware
Posted: Sun May 27, 2012 11:01 am
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
Re: to string not working on hardware
Posted: Mon Jun 11, 2012 11:04 pm
by medelec35
Has not displaying UNIT values on LCD been resolved yet please?
Martin
Re: to string not working on hardware
Posted: Mon Jun 11, 2012 11:30 pm
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
Re: to string not working on hardware
Posted: Tue Jun 12, 2012 7:58 am
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

) 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
Martin
Re: to string not working on hardware
Posted: Tue Jun 12, 2012 9:16 am
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.
Re: to string not working on hardware
Posted: Tue Jun 12, 2012 10:15 am
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
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

Re: to string not working on hardware
Posted: Wed May 15, 2013 9:25 am
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