Digits to ULong number conversion problem

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
sysprofessional
Posts: 54
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 28 times
Been thanked: 4 times
Contact:

Digits to ULong number conversion problem

Post by sysprofessional »

Hi,
I want a value from 5 separate digits,that are feed bye user on 7 segment display.I am using this method

Total = (digit[0] * 10000) + (digit[1] * 1000) + (digit[2] * 100) + (digit[3] * 10) + digit[4]

Total is a ULong (number in the range 0 to 4294967295) 32 bit variable .

This method works fine in Flowcode ,but when i move on proteus Total variabale work like UInt 16 bit variable.when value reached to 65536 Totale variable overflow and start from 0.

I am using 18f14k22 with internal 16MHz oscilator in my application .i have confused,please suggest me wright way.

Best Regards

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Digits to ULong number conversion problem

Post by kersing »

Post your flowchart so we can check it for issues.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Digits to ULong number conversion problem

Post by LeighM »

On your target, any intermediate/temporary calculations will be 16 bit, so you will need to ensure that any sub-totals are Ulongs too

User avatar
sysprofessional
Posts: 54
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 28 times
Been thanked: 4 times
Contact:

Re: Digits to ULong number conversion problem

Post by sysprofessional »

kersing wrote:Post your flowchart so we can check it for issues.
Hello kersing,
Basically i am using 11 digit in my application using dual MAX7219 and many other features so my flowchart is little lengthy. Here i have design new flowchart for your observation .That is small and easy to understand.
My flowchart, hex, cof, and proteus simulation files attached below in compressed rar format.

Best Regards:
Attachments
Flowchart+Simulation.rar
(43.35 KiB) Downloaded 337 times

User avatar
sysprofessional
Posts: 54
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 28 times
Been thanked: 4 times
Contact:

Re: Digits to ULong number conversion problem

Post by sysprofessional »

LeighM wrote:On your target, any intermediate/temporary calculations will be 16 bit, so you will need to ensure that any sub-totals are Ulongs too
I have already ensured that there is no temp or any other variable between calculation,i am using only one 32 bit variable ,and all calculations moves directly into that variable.i have also attached flowchart now ,please see that ,

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Digits to ULong number conversion problem

Post by LeighM »

On your target, any intermediate/temporary calculations will be 16 bit, so you will need to ensure that any sub-totals are Ulongs too
sorry, I did not explain that too well

Code: Select all

Total = (digit[0] * 10000) + (digit[1] * 1000) + (digit[2] * 100) + (digit[3] * 10) + digit[4]
The compiler will produce code to calculate "(digit[0] * 10000)" using a temporary variable, which will only be 16 bits on this target processor, hence the 65536 limit.
So you will need to create a Ulong SubTotal variable to force this calculation into 32 bits

Code: Select all

SubTotal = 10000
SubTotal = SubTotal * digit[0] 
Total = SubTotal + (digit[1] * 1000) + (digit[2] * 100) + (digit[3] * 10) + digit[4]
Hope that helps,
Leigh

User avatar
sysprofessional
Posts: 54
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 28 times
Been thanked: 4 times
Contact:

Re: Digits to ULong number conversion problem

Post by sysprofessional »

Thank you very much LeighM ,

I have well understand now,This method working fine in my application.Good luck to you.

Post Reply