12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct value


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Henrik-
    Sorry for the late reply, been out with a respiratory illness - geeesh.
    In your example :
    ADValue = 3272
    Temp = ADValue ** 35809 ' Multiply by ~0.5464
    Result = ADValue + Temp ' Result now 5059

    Why are you using 'Top 16 bits' for multiplying? and how did you arrive at '35809' as the multiplier?

    I really want to learn from this, Thanks.
    -Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Hi,
    We want a "raw" display value of 5060 when the ADC returns 3272. That's a factor of 1.5464, right?
    The ** operator does a 16*16bit multiplication and then returns the 16 top bits of the intermediate 32bit result which is the same as dividing that intermediate result by 65536.

    So, on a calculator, 3272 * 35809 / 65536 = 1787 (truncated). Add in the "original" 3272 and we get 5059 which is pretty close to 5060.

    Just think of the ** operators as multiplying by units of 1/65536.
    65536*0.5464 = 35809...
    35809 * (1/65536) = 0.5464...
    And so on.

    /Henrik.

  3. #3
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Henrik-
    So, I kinda get the top 16 bits thing, but I still don't know where you got the number 35809?
    65536 * 0.5464 ----> shouldn't this be 65535 * 1.5464?
    -Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Hi,
    65536 * 0.5464 ----> shouldn't this be 65535 * 1.5464?
    Idealy, yes. But that would result in a value larger than 65535 which won't work without resorting to LONGs. So I treat what's on the right hand side of the decimal point separately from what's on the left hand side which is why I first multiply ADValue by 0.5464 and then ADD the ADValue to that result to get the 1.5464. See if this makes more sense:
    Code:
    Result = ADValue + (ADValue ** 35809)   ' ~Same as ADValue * 1.5464
    Since you're using an 18F part you atleast have the option to use LONGs so if you ARE then by all means go ahead and try Result = ADValue ** 101345, it should work.

    Hope I don't make it more confusing....

    /Henrik.

  5. #5
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Is a bit more confusing........ BUT I will try what you had said. I just can't quite wrap my head about using sections of numbers....... I'll draw it out on paper and see if that helps....
    I'll get it though, may take me a bit.
    This forum is an amazing central clearing for knowledge and the fact that others are not only willing but patient is refreshing...
    Thanks,
    Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Hi Steve,

    On paper, Result = X * 3 is the same as Result = X+X+X, right?
    If the above is correct then Result = X * 1.5 is the same as Result = X + (X/2), right?
    And if we agree that the above is correct then I think we'll agree that Result = X + (X*0.5) is the same as Result = X * 1.5 too?

    Same thing with the formula in the previous message but the number is 1.5464 instead of 1.5.

    Again, ideally, we would want to do Result = ADValue ** 101345 (where 101345 is 65536*1.5464) but that will result in a compile time error if LONGs aren't enabled (because 101345 is larger than 65536 so there's a risk of overflowing the 32bit intermediate result thus returning the wrong value) so we resort to first calculating what 0.5464 is and then add that to the original value, exactly as we did in the example above.

    Don't worry, I'm sure you'll get it!

    /Henrik.
    Last edited by HenrikOlsson; - 22nd May 2014 at 19:47.

  7. #7
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: 12 bit A2D on 18F46K80, need a bit of help for figuring TAD and getting correct v

    Henrik-
    Its probably a good thing you are not in Texas cuz your ears would be ringing over the loud 'Aha!' that I just said - Now I need to check my bathwater -(bad reference to Archimedes <grin>).
    I think I can now see the light, just needed help with the switch......
    Thanks Bud,
    Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

Similar Threads

  1. How do I use 10 bit A/D on 8 bit Pic? 12F675
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st April 2020, 20:10
  2. Replies: 1
    Last Post: - 12th March 2012, 23:34
  3. Averaging 16 bit values without using 32 bit math
    By sirvo in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th October 2007, 22:18
  4. LCDOUT 4-bit data on 8-bit setting
    By breesy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th June 2006, 18:39
  5. Help 14-bit and 16-bit Core
    By jetpr in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th September 2005, 03:29

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