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


    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?

  2. #2
    Join Date
    Oct 2006
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I don't think I can use that approach since the ADCIN command only lets you store the result in a VAR not a CON. How would I tell it what values from 0-1023 to pull out from memory?

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


    Did you find this post helpful? Yes | No

    Default

    The reading from the POT should be put in a variable.

    The CON is the address of the Data Table that gets stored in program memory.

    Then the A/D reading would be used as an offset into the data table in order to find the correct value.
    <br>
    DT

  4. #4
    Join Date
    Oct 2006
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,

    I works GREAT! I just hope now there isn't a limit to the number of values I can put in the Datatable. If there is, then i'm praying that its 1024!!!!!

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


    Did you find this post helpful? Yes | No

    Default

    Nope,

    You are only limited by the amount of available memory in Program Space.

    Cheers,
    DT

  6. #6
    Join Date
    Oct 2006
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Well I got a 125KB, I think I should be fine!

    Thanks,
    Nikhil

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


    Did you find this post helpful? Yes | No

    Default

    The chip might have 128k, but keep in mind that PicBasic Pro can only address the first 64K of it directly.

    Since the table will only use 2K, you should be fine for now.

    If the program gets "A LOT" bigger, it's possible to place the table in the upper 64k area, but the readcode would need to be changed to ASM.

    But you can worry about that later.
    <br>
    DT

  8. #8
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    Ahhh... the LOOKUP and LOOKUP2 statements impliment the RETLW method for you. Lots cleaner.

    Several problems: LOOKUP2 will return words, but has a limit of 85 values (and wastes 50% more room then LOOKUP). LOOKUP1 will fit 255 values, but they are only a byte each (but 1 byte takes 1 program location).

    255 is usefull, but 256 would be lots nicer. Using 255 locations just need a work-around for the 256th value, simple in a SELECT-CASE form.

    SO... not the worst, each value gets looked up for it's exact value. You would expect 1024 word lookups to fit in 2K of program memory.

    Ready for it?

    BUT !!!

    The LOOKUP statement needs to start on a even 256 address boundary (don't ask why, it's an assembler issue). To do this, PBP seems to just waste code space till it gets to the next boundary.

    I tried a sample program compiled for a PIC16F88, which has a 4K word codespace. The program did not fit. I looked at the disassembly I saw the problem was with this wasted codespace.

    Since you have 125K it will fit, and hopefully you can accept the wasted space (basically, you'll need 2:1 to fit the lookups).

    Sample code:

    Code:
        D2A_Result      var word    ' raw data from D2A conversion
        D2A_Conversion  var word    ' converted result
        ' read the D2A, place Result in D2A_result
        
        select case  D2A_result 
            case is <256
                lookup D2A_result.byte0,                     _
                    [$00, $00, $00, $00, $00, $00, $00, $00, _  ' 0-7 lo bytes
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 8-15 lo bytes
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 16
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 24
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 32
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 40
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 48
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 56
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 64
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 72
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 80
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 88
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 96
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 104
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 112
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 120
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 128
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 136
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 144
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 152
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 160
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 168
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 176
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 184
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 192
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 200
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 208
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 216
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 224
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 232 
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 240
                     $00, $00, $00, $00, $00, $00, $00],     _  ' 248 - 255
                    D2A_Conversion.byte0
                lookup D2A_result.byte0,                     _
                    [$00, $00, $00, $00, $00, $00, $00, $00, _  ' 0-7 hi bytes
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 8
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 16
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 24
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 32
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 40
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 48
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 56
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 64
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 72
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 80
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 88
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 96
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 104
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 112
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 120
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 128
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 136
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 144
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 152
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 160
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 168
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 176
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 184
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 192
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 200
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 208
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 216
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 224
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 232 
                     $00, $00, $00, $00, $00, $00, $00, $00, _  ' 240
                     $00, $00, $00, $00, $00, $00, $00],     _  ' 248 - 255
                    D2A_Conversion.byte1
            case 256
                D2A_Conversion.byte0 = $00
                D2A_Conversion.byte1 = $00
            case is < 512
                ' same as before, 2 LOOKUP tables
            case 512
                D2A_Conversion.byte0 = $00
                D2A_Conversion.byte1 = $00
            case is < 768
                ' same as before, 2 LOOKUP tables
            case 768
                D2A_Conversion.byte0 = $00
                D2A_Conversion.byte1 = $00
            case else
                ' this case handles 769 to 1023
                ' same as before, 2 LOOKUP tables
        end select
    If you do run out of codespace, let me know and I'll help with some asm code for this.

Similar Threads

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

Members who have read this thread : 2

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