• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Lookup table logarithmic.

Status
Not open for further replies.

dr pepper

Well-Known Member
Most Helpful Member
I'm having issues with pic16 lookup tables, I'm working in asm.

I have a pot wired to an analogue in on a pic16f88, its a linear pot.
I want to select either a linear function or log function as per the old fashioned log volume pots.
Linear is no problem I can just use the value direct from the atod module, to convert lin to log I was thinking of using a lookup table, my maths are a bit rusty, anyone know where I can find a 256 element lookup table for the purpose?

Also I found with the dt function if I have more than 1 line I get errors from the assembler, can I have a 256 element table that isnt all on one line, I'm sure I've done it before but I cant find that program.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Funnily enough that's near enough the exact same question I asked when I first joined here :D

I was programming a PIC to work like an LM3915/4, switch-able between log and linear.

No one was prepared to help, so I wrote a small Delphi program that generated a log table of the switching points for each LED - I then used that in the program, along with a linear table, selected by a switched pin.

Unfortunately, both the Delphi program and the PIC source have long since been lost :(

As for a table longer than 256 words, check my tutorials (specifically the 8x8 LED matrix one).
 

dr pepper

Well-Known Member
Most Helpful Member
This is my routine that contains a 255 byte lookup table, the table is assembled at 0x200 using the org directive (0x1fe).
The table is all on one line, can I put the table on several lines and use 'dt' on each line?
My code doesnt run properly, that might be an issue elsewhere.
Is crossing the page boundary a nono just after assing to pcl, as I understand it pclath is added to the high byte so this should work, it does on mpsim.
I could lose the last 2 elements in the table wouldnt make much difference.
The table is in decimal, I did use R=dec directive at the start of the code.

Code:
;
;-------------------------------lookup conversion to log table--------------------------
;
logcon    movlw    d'2'
        movwf    pclath
;
        org        0x1fe
;
        movf    adresh,w
        addwf    pcl,f
;
        dt    0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,8,9,9,10,10,11,12,12,13,14,14,15,16,17,17,18,19,20,21,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,40,41,42,43,44,45,47,48,49,50,52,53,54,55,57,58,59,61,62,63,65,66,67,69,70,72,73,74,76,77,79,80,82,83,85,86,88,89,90,92,93,95,97,98,100,101,103,104,106,107,109,110,112,113,115,117,118,120,121,123,124,126,128,129,131,132,134,135,137,138,140,142,143,145,146,148,149,151,152,154,155,157,158,160,162,163,165,166,167,169,170,172,173,175,176,178,179,181,182,183,185,186,188,189,190,192,193,194,196,197,198,200,201,202,203,205,206,207,208,210,211,212,213,214,215,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,234,235,236,237,238,238,239,240,241,241,242,243,243,244,245,245,246,246,247,248,248,249,249,250,250,250,251,251,252,252,252,253,253,253,253,254,254,254,254,254,255,255,255,255,255,255,255,255,255,255,255,255,255
;
        end
 
Last edited:

misterT

Well-Known Member
Most Helpful Member
Last edited:

dr pepper

Well-Known Member
Most Helpful Member
Can someone please explain how I search tutorials, I'm having a useless moment.
 

large_ghostman

Well-Known Member
Most Helpful Member

dr pepper

Well-Known Member
Most Helpful Member
This is more difficult than I thought.
I bodged it.
Reducing the table to 64 entries and dividing the atod result by 4 to suit means I can nick someone elses code which has a 64 byte long log lookup.
Heres my altered code, I still dont seem to be able to get dt to work for more than 1 line of data entries:
LG, your own world can be a good thing, mines nice and quiet.

Code:
;
;-------------------------------lookup conversion to log table--------------------------
;
logcon        org    0x200            ;shift assy to 0x200
;
        movlw    d'2'            ;setup pclath to correct page
        movwf    pclath
;
        movf    adresh,w        ;transfer atod result to temp and divide by 4
        movwf    temp
        bcf    status,c
        rrf    temp,f
        bcf    status,c
        rrf    temp,f
;
        movf    temp,w            ;jump to table
        addwf    pcl,f
;
        dt    0,  2,  3,  4,  4,  5,  6,  6,  7,  8     ;64 logarithmic table entries
               9, 10, 11, 12, 13, 15, 16, 17, 19, 20
               22, 24, 26, 28, 30, 32, 34, 37, 39, 42
               45, 48, 51, 54, 57, 61, 65, 68, 72, 77
               81, 86, 91, 96,101,107,112,118,125,131
             138,145,152,160,168,176,185,194,203,213
             223,234,244,256
;
        end
 

ChrisP58

Well-Known Member
Most Helpful Member
I used Excel to generate a sine wave lookup table. After doing all of the number crunching and scaling, I converted the output to Hex values and then formatted it into three columns that I just copied and pasted into MPLAB.

The three columns were:
1: empty space
2: The text "retlw"
3: The value of that line in Hex.

The result looked like:
Code:
    org        0x0200   
SineTable:
    movlw    high SineTable     ; get high order part of the beginning of the table
    movwf    PCLATH
    movf     pointer,w
    addwf    PCL,f
    nop     
    retlw    0x00    ; beginning of paste from excel
    retlw    0x03
    retlw    0x06
    retlw    0x09
    retlw    0x0C
    retlw    0x10
    retlw    0x13
    retlw    0x16
    retlw    0x19
    retlw    0x1C
    retlw    0x20

etc. for 250 lines
 
Last edited:

dr pepper

Well-Known Member
Most Helpful Member
Yes figured out the dt in each line, what confused me there was in the past I have use dt for text strings and a different string on each line, but this is data.

I'm not very good with excel, having to use it at work puts me off using it at home too.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top