Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Look-up Table

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    274

    Resolved [RESOLVED] [2005] Look-up Table

    I need to do manipulation with my incoming data fr serial port n need to have a look-up table for this purpose, starting from 0.0dB and 30H data. For every increment of hex value, the level increases by 0.5dB.

    My data has been converted to hex format, then i need to convert it to dB value based on the look-up table. How can this be done?


    This is what i mean:
    LEVEL DATA
    0.0dB 30H "0"
    0.5dB 31H "1"
    1.0dB 32H "2"
    .
    .
    .
    15.0dB 4FH
    .
    .
    49.5dB 93H
    50.0dB 94H

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Look-up Table

    You don't need a lookup table for this... All you need to do is some function that do this:
    dB = ConvertToDec(currentHexValue) - 48 * 0.5
    Here is a little function that I did for you. Just pass in the current hex value and it'll spit out the dB
    VB Code:
    1. Private Function Translate2dB(ByVal strHexInput As String) As String
    2.         Dim retval As String = "0.0 dB"
    3.         Dim inputVal As Integer = 48
    4.         Dim diff As Integer = 0
    5.         Try
    6.             'Convert Hex to Dec
    7.             inputVal = Val("&H" & strHexInput)
    8.             'Find the different
    9.             diff = inputVal - 48
    10.             'Then multiply the diff by 0.5
    11.             If diff > 0 Then
    12.                 retval = (diff * 0.5).ToString("0.0") & " dB"
    13.             End If
    14.         Catch ex As Exception
    15.             Return "Error"
    16.         End Try
    17.         Return retval
    18.     End Function
    You can use it like this:
    VB Code:
    1. Dim myCurrentHexValue As String = "4F"
    2. TextBox1.Text = Translate2dB(myCurrentHexValue)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    274

    Re: [RESOLVED] [2005] Look-up Table

    thanks stanav for your great help...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width