String Manipulation giving wrong result in hardware

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times

String Manipulation giving wrong result in hardware

Post by Dirk Bubley »

Hello Matrix Team,


i try to use the string manipulation to convert a string numerical number to a INT.

My string is "123456"

I cut out from left to right only the numericals"12345" with the mid$ function 0,5.

Then i convert the string to INT and sent the INT variable to the LCD Display.
It works fine in the simulation, i get the expected result 12345 in the LCD display.

If i sent this small program to the EB006 and run it in real hardware (Pic18F2420) i get -7616 in the display.

As a cross check. If i reduce my original string "123456" to "12345" the result ist OK.

Any ideas on that problem

BR

Dirk

PS: Flowcode Pic Ver. 4.2 Prof. Version
Flowcode File is attached
Attachments
String Tester2.fcf
(5.5 KiB) Downloaded 266 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: String Manipulation giving wrong result in hardware

Post by medelec35 »

Hi Dirk,
You using an int to string function. Max signed int value is 32767.
You are using an int vlaue of 123456, so the actual int value would have rolled over.
Solution is either use int less than 32768 or assign 123456 to a string, then use mid$ function on the string.

Martin
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times

Re: String Manipulation giving wrong result in hardware

Post by Spanish_dude »

You could also use a long int (4 bytes) variable type.

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times

Re: String Manipulation giving wrong result in hardware

Post by Dirk Bubley »

Hi guys,

you are right the six (123456) digit value is above the INT 32768.

But I use the mid$ funktion to use only the left five digits (12345)
Wich is below the level of 32768.

12345 should then pass without problems to a INT. It works in simulation bit nor in real live with the hardware.
Give it a try.

It seems that it is not related to the 18f2420. I habe the same problem with 18f6722.

There must be somthing happen during the compile process.

BR

Dirk

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: String Manipulation giving wrong result in hardware

Post by medelec35 »

Dirk Bubley wrote: But I use the mid$ funktion to use only the left five digits (12345)
Wich is below the level of 32768.

12345 should then pass without problems to a INT
But your passing 123456 int to be converted into a string first before the mids function. This conversion from int to sting is the problem

You will have the same negative number with every device, since as I stated has rolled over.

The simulator handles integers in a different way, so I'm afraid its wrong.
Martin
Martin

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times

Re: String Manipulation giving wrong result in hardware

Post by Dirk Bubley »

Hi Martin,


you are right i see the rollover and your explanation is logical but you get the same problem for example with a RS232 recieved STRING.
At this stage it was never a INT. It was defined direct as a string variable taking the incoming numerical.

The following string manipulation just taking out the first five digit should clear the situation before it will be converted to INT.

I think the compiler is never expecting a string bigger then 5 digits.
In this area is the problem.

Do you have any expierence with a differnt compiler?

BR

Dirk

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: String Manipulation giving wrong result in hardware

Post by medelec35 »

test_string = ToString$(123456).
Function: ToString$(integer value)
Converts an integer ( number within the brackets) to a string. So by ToString$(123456) you are assigning an integer first to a value of 123456. Hence the problem. So evn is using RS232 the result will still be the same.
I don't believe the result will be any different, no matter what compiler you use.

You could do

Code: Select all

test_string = "123456"
instead.
That will work, or if it must start off as an integer then you could try Spanish_dude's suggestion. Not tried that personally.
Martin

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times

Re: String Manipulation giving wrong result in hardware

Post by Dirk Bubley »

Hi Martin,

great help!! Simulation and Hardware is now working the same. Many thanks!!

In between i think i found a solution for the RS232 String recieve too. This was the original problem
In the Rs232 component you can setup the NumByte to 5. Limmiting the number of bytes wich are then placed into the String variable.
Since the incoming number is lower then 20000 i`m fine with the conversion later on to INT.



BR

Dirk

Post Reply