to string not working on hardware
Moderator: Benj
-
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
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 270 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
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)? Martin.
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)? 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
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
Has not displaying UNIT values on LCD been resolved yet please?
Martin
Martin
Martin
- 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
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
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
Thanks Jonny.
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
That's interesting.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.
Just brain storming from a non expert (so please don't laugh too much
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
Martin
- 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
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.
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
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
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
Martin
- 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
Hello,
Adding this definition to the supplementary code window may help solve the issue for unsigned 16-bit values.
#define MX_STRF_LONG
Adding this definition to the supplementary code window may help solve the issue for unsigned 16-bit values.
#define MX_STRF_LONG
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel