Hello
I agree with all you guys
Its the matter of, Do I really need floating point.
I have written a code to control PGA2311 and view the volume reading on LCD. At first place I was very sad, when I looked to the datasheets, the formula to calculate the decible value was a hell:
dB = 31.5 - ( 0.5 * ( 255- vol ) )
I thought the only solution was the floating point, any way, thanks to a friend who told me to use * 10 and * 100 approach :
dB_VALUE : ' Calculations for decible equivalent values
IF ( VOL_L >= 192 ) Then
DB_SIGN = 1
DB = 3150 - ( 5 * ( 2550 - ( vol_l * 10 ) ) )
DB10 = DB / 100
dB1 = DB // 100
DB1 = DB1 / 10
Else
DB_SIGN = 0
dB = ( 5 * ( 2550 - ( vol_l * 10 ) ) ) - 3150
DB10 = DB / 100
dB1 = DB // 100
DB1 = DB1 / 10
EndIF
Return
dB_LCD : ' Show volume on the LCD
FLAG = 1
if ( db10 == 0 ) AND ( DB1 == 0 ) THEN
LCDOut I, clr, " Volume ", DEC DB10, " dB"', DEC VOL_L
FLAG = 0
ENDIF
IF ( flag == 1 ) and ( DB_SIGN == 1 ) Then
LCDOut I, clr, " Volume ", DEC DB10, ".", DEC DB1, " dB"', DEC VOL_L
ENDIF
IF ( flag == 1 ) and ( DB_SIGN == 0 ) Then
LCDOut I, clr, " Volume -", DEC DB10, ".", DEC DB1, " dB"', DEC VOL_L
ENDIF
Return
The compiled code was 970.
When I used PICBasic Plus, and used floating pint stuff, the code was 1680 words. I now really know the Pros and Cons of floating point stuff, so, as an advice, don't ever use it, unless you badly need it
See ya





Bookmarks