AC measurements using CS5460A and PIC - Help on an022a


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    marcomilazzo's Avatar
    marcomilazzo Guest


    Did you find this post helpful? Yes | No

    Default Re: AC measurements using CS5460A and PIC - Help on an022a

    Hi
    what is the routine to convert the binary to floating?!!!
    11111111 11111111 11111111 = 0.99999994
    11111111 11111111 00000000 = 0.999984741
    00000000 00000000 11111111 = 0.000015199
    i tried all i know with no result
    thank's for any help
    marco

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: AC measurements using CS5460A and PIC - Help on an022a

    Quote Originally Posted by marcomilazzo View Post
    Hi
    what is the routine to convert the binary to floating?!!!
    11111111 11111111 11111111 = 0.99999994
    11111111 11111111 00000000 = 0.999984741
    00000000 00000000 11111111 = 0.000015199
    i tried all i know with no result
    thank's for any help
    marco
    Marco,
    I don’t know if you got an answer, or are even still around. It’s been a while since I’ve had my hands dirty with this, but here is a short answer: There is no ‘routine’ to convert binary to floating directly.

    The long answer is that those binary numbers represent some real value and you need to understand that to know how to manipulate the values in code.

    Also, keep in mind that the magnitude of those numbers are unreasonable for use in a PIC. An unsigned 24 bit variable gives a resolution of .12 parts per million. You are unlikely to build a device that can measure accurately at that resolution, and even more so to need that resolution. A 16 bit number is more reasonable, and 12 even more so.

    Now as for the values they represent:

    Let’s say you are measuring voltage with an unsigned 16 bit variable. The range of measurement is 0 to 5 volts. Each bit of that variable would represent 76.2939uV. This is derived as follows:
    Divide the range by number of bits: 5/65536 = 76.2939E-05 * 10^6 = 76.2939.

    Now you have a value you can work with in an integer environment (sort of). If you don’t mind the rounding error, then you can just take the value of the variable and multiply it by 76.
    For example:
    Variable = %10100101 00100101 = $A525 = 42277
    42277 * 76 = 3,213,052uV
    But, this has a rounding error of 12427 due to using integers. (The value using floating point is 3225749).

    We can improve the somewhat by using the value of 7629 for each bit. After that is multiplied by the variable, dividing by 100 gives us a much closer value for nV.
    42277 * 7629 = 322,531,233 / 100 = 3,225,312
    The rounding error is now only 167

    Of course, this example would require using LONG variable types in PBP (Compiler mode PBPL).

    Bottom line, you don’t need floating point if you assign those bits to mean whatever you want them to mean.

    HTH,
    Steve

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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