Page 1 of 1
Digits to ULong number conversion problem
Posted: Sun Jul 31, 2016 5:15 pm
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
Re: Digits to ULong number conversion problem
Posted: Sun Jul 31, 2016 5:31 pm
by kersing
Post your flowchart so we can check it for issues.
Re: Digits to ULong number conversion problem
Posted: Mon Aug 01, 2016 8:44 am
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
Re: Digits to ULong number conversion problem
Posted: Mon Aug 01, 2016 12:47 pm
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:
Re: Digits to ULong number conversion problem
Posted: Mon Aug 01, 2016 12:57 pm
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 ,
Re: Digits to ULong number conversion problem
Posted: Mon Aug 01, 2016 3:26 pm
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
Re: Digits to ULong number conversion problem
Posted: Mon Aug 01, 2016 10:37 pm
by sysprofessional
Thank you very much LeighM ,
I have well understand now,This method working fine in my application.Good luck to you.