Need help with lookup table or direct calculation


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Posts
    25

    Default Need help with lookup table or direct calculation

    Hi,

    I am trying to allocate my A-D value which goes from 0-1023 to precalculated values. I tried this approach first because the calculation is pretty complex. So once I had my precalculated values, I tried storing them into the EEPROM like this:

    DATA @1023,-782
    DATA @1022,-696
    DATA @1021,-633
    DATA @1020,-594
    .
    .
    .
    DATA @3,3797
    DATA @2,4126
    DATA @1,4725
    DATA @0,4730

    Read these values from EEPROM:

    FOR index0 = 0 to 1023
    read index0,tem0[index0]
    next index0

    Then allocated precalulated stored values to A-D value:

    ADCIN 2,pot_value
    temperature = tem0[pot_value]


    However, I think the EEPROM can only store bytes rather than words, thus I cannot store the value I wanted. I tried using lookup tables as well, but the maximum you can store in a lookup table are 256 values, I need 1023.
    So, I thought about actually doing the math in the PIC itself. The equation I need to calculate is:

    temperature = (80.8321*( (-1*LN( (2490*(Pot_value*(4096/1024)))/(40960-10000*(Pot_value*(4096/1024))))) + ( SQRT( (LN( (2490*pot_value)/(40960-10000*pot_value)) + 7.4063)^2 + 68.2415) -7.4063))) - 273.15

    I have got an algorithm for the Ln but I will need to do all this in floating point math. Can someone please suggest what I can do?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi nverma,

    If you're using an 18F this might work for you ...

    The EXT (external) modifier.
    http://www.picbasic.co.uk/forum/showthread.php?t=3891

    In particular, the section on Using EXT with Labels.

    HTH,
    DT

  3. #3
    Join Date
    Oct 2006
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,

    I'm not exactly sure what the DW command does. And if you look at the example of the EXT with label, could I write code as:

    POT_VALUE CON EXT

    POT_VALUE

    DW (basically enter my precalculated values in order from the one correposidng to 0 all the way to 1023 here)

    And then reading:

    READCODE(POT_VALUE + (OFFSET<<1)),Temperature

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    DW is "Declare Data of One Word" in assembly language.

    And, sounds like you've got the right idea for the rest of it.
    <br>
    DT

  5. #5
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    That's a rather involved calculation to be sure. Honestly, I gave up trying to follow it.

    You have just 1024 input values, I assume these lead to 1024 discrete output values else you wouldn't be looking for a look-up table solution.

    However, can you solve this by some other simpler method? Piecewize linear, interpolation polynomial, or such? Do you have say an excel spreadsheet with the results calculated?

    Also, you don't need EEPROM to save values, you can use RETLW (Return with literal in W) to get a byte look up table, that will take 2048 memory locations to get 1024 words (and yeah, its assembler, but not much).

  6. #6
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    What type of thermometer do you use ?

    I always make a table of maybe 30 points and make an interpolation between this points. It is good for me, but I don't know, what you need...
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  7. #7
    Join Date
    Oct 2006
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Ernie,

    Yes I do have an excel spreadsheet with the values calculated. And I could possibly linearize the curve but loose accuracy. But about this RETLW command, how does it work and where can I find the syntax etc etc for it?

Similar Threads

  1. Lookup table syntax.....
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th May 2009, 04:45
  2. Lookup table or Math?
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 2nd May 2008, 17:55
  3. Lookup Table
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th March 2008, 10:38
  4. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  5. Real Time Clock & Eeprom
    By smart_storm in forum General
    Replies: 8
    Last Post: - 17th February 2006, 19:03

Members who have read this thread : 1

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