Exact match. Not showing close matches.
PICList
Thread
'[SX] Changing a value from base2 to base10?'
2006\07\25@114426
by
Steeln/a
|
|
I have an ADC that gives me a base2 value (0-FF) and I want to convert it to Base10 (0-9). Is there a more code-efficient way of doing so than what is below?
If ADC_VALUE < 25 Then
ADC_VALUE = 0
ELSEIF ADC_VALUE <50 THEN
ADC_VALUE = 1
ELSEIF ADC_VALUE <75 THen
ADC_VALUE = 2
ELSEIF ADC_VALUE < 100 THEN
ADC_VALUE = 3
ELSEIF ADC_VALUE < 125 THEN
ADC_VALUE = 4
ELSEIF ADC_VALUE < 150 THEN
ADC_VALUE = 5
ELSEIF ADC_VALUE < 175 THEN
ADC_VALUE = 6
ELSEIF ADC_VALUE < 200 THEN
ADC_VALUE = 7
ELSEIF ADC_VALUE < 225 THEN
ADC_VALUE = 8
ELSEIF ADC_VALUE < 255 THEN
ADC_VALUE = 9
ENDIF
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\25@120721 by Beau Schwaben/a
|
|
Steel,
base 2 would be 0 or 1
base 16 would be 0 through F
What you are doing with the IF/THEN can be accomplished with simple division.
ADC_VALUE = ADC_VALUE / 28
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137061
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
|
|
umm...oh yeah...thanks Beau...
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137064
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\27@112815 by SSteven/a
|
|
[Quoting: "Beau Schwabe (Parallax)"]What you are doing with the IF/THEN can be accomplished with simple division.
ADC_VALUE = ADC_VALUE / 28
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137395
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\27@124303 by chipheadn/a
|
|
Beau used 28 in order to get the same values as the original code.
I think you could also use 25, but then subtract 1
ADC_VALUE = ADC_VALUE / 25
25 = 1
50 = 2
...
255 = 10
ADC_VALUE = ADC_VALUE - 1
While Buau uses the magic of integer math to get
ADC_VALUE = ADC_VALUE / 28
25 = 0
50 = 1
...
255 = 9
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137404
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\27@133323 by SSteven/a
|
|
[Quoting: "John R."]
ADC_VALUE = ADC_VALUE / 25 Yields the following:
25 = 1
50 = 2
...
255 = 10
[Quoting: "John R."]While Buau uses the magic of integer math to get
ADC_VALUE = ADC_VALUE / 28 Yields the following:
25 = 0
50 = 1
...
255 = 9
' {$STAMP BS2sx}
' {$PBASIC 2.5}
ADC_VALUE VAR BYTE
FOR ADC_VALUE = 0 TO 255
DEBUG "ADC_VALUE = ", DEC3 ADC_VALUE, ": /25 = "
DEBUG DEC1 (ADC_VALUE / 25) MAX 9 '<-- here's the conversion forumla
DEBUG " /28 = ", DEC1 ADC_VALUE / 28, CR
NEXT2006\07\27@142947 by chipheadn/a
|
|
My bad - I "saw" the lines:
ADC_VALUE < 25 Then as
ADC_VALUE <= 25 Then
Hence my thougths on the 28 and also the using 25 then subtracting 1.
Call me an idiot today, and ignore my post. 25 is the correct devisor and I will concurr that Beau had a typo.
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137419
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\27@143031 by Beau Schwaben/a
|
|
Since Steel essentially had a range of 0 to 255 (FF) that needed to be scaled to give an output from 0 to 9...
255 / 9 = 28.33333333333333333
...I just used '28'
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137420
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\27@143328 by chipheadn/a
|
|
Can you say "over thinking a solution"?
Beau, Thanks for pointing out the obvious to us.
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137421
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\27@144419 by SSteven/a
|
|
OK. The way I read the original post, he wanted the value to change at every multiple of 25.
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137423
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
2006\07\27@145919 by Beau Schwaben/a
|
|
See edit above
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=137056#m137428
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)
More... (looser matching)
- Last day of these posts
- In 2006
, 2007 only
- Today
- New search...