This is a comparison of three different digit conversion methods to get the tens and ones digit which I use for two digit
seven segment displays (both led and lcd glass). I needed to determine the best method to use depending on my application.
Here are the results of my comparison tests which I thought I would share. The different conversion programs are attached.
Using IF less than to determine the digits
Pros:
good conversion speed, 21us to 62us (average is about 43us, the higher the number the longer it takes)
It simulates in Flowcode
Uses little ROM space
Cons:
Conversion time is not consistent
Takes up a lot of your screen real estate
Takes awhile to setup in your program
Using a ROM lookup table
Pros:
Does not not take up much screen real estate in you program
Somewhat easy to add to your program
Conversion time is the same for any value
Cons:
Slow conversion speed, 110us
Does not simulate in Flowcode (It might in V6 but I am not sure)
Uses a lot of ROM space
Using a RAM lookup table
Pros:
Excellent conversion speed, only 32us (as expected this is the fastest)
It simulates in Flowcode
Conversion time is the same for any value
Cons:
Takes up a lot of RAM (obviously)
Takes awhile to setup
Takes up a bit more of your screen real estate than the ROM LUT
Adds a whopping 207us to the power on reset time vs the others
Uses a lot of ROM Space
If anyone has a another method to convert a number (0 to 99) into tens and ones digits, and wouldn't mind sharing, I would
like to see it.
Converting a number to tens and ones comparison
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Converting a number to tens and ones comparison
- Attachments
-
- Two_Digit_RAM_LUT.fcf
- (16.64 KiB) Downloaded 248 times
-
- Two_Digit_ROM_LUT.fcf
- (7 KiB) Downloaded 242 times
-
- two_digit_using_if_less_than.fcf
- (11.58 KiB) Downloaded 247 times
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
Re: Converting a number to tens and ones comparison
There's another, easy and short, method you missed:
- Nicolas
Code: Select all
int number, ones, tens;
if (number >= 100)
number = 0;
else
{
ones = number % 10; // (MOD)
tens = number / 10;
number++;
}
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Re: Converting a number to tens and ones comparison
Thank you for your response Spanish_Dude. The method you posted is probably the simplest and easiest to use. It can also be put into a normal Flowcode calculation box for simulation within Flowcode. It's a great default method. However, a speed test shows it is dead last at 260us. Ouch!
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
Re: Converting a number to tens and ones comparison
Yes, multiplications and divisions are very slow.
- Nicolas
- Nicolas