Searching \ for 'Look up tables' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/mems.htm?key=table
Search entire site for: 'Look up tables'.

Truncated match.
PICList Thread
'Look up tables'
1998\11\07@142730 by aureo

flavicon
face
Another beginner question:

What is the theory behind a look up table.  How does the program know
when it has the data it wants?

TIA

--
Seth Fischer
Auckland, New Zealand

1998\11\09@095910 by lilel

flavicon
face
Seth Wrote:

> Another beginner question:
>
> What is the theory behind a look up table.  How does the program
> know when it has the data it wants?

I'm going to assume you are a real beginner, don't be insulted if I
am not addressing your question on the right level.

Lookup tables work like this:

Say you want a simple lookup table to calculate squares of numbers.
Your program calculates the number it wants squared, places that
number in the W register, then calls a subroutine.  The subroutine
adds W to the Program counter.  This is the key to a lookup table and
the answer to your question.  The position in the table calculated by
this operation is the  location of the answer answer.  An example:

  CLBOCK  0x0a
         x                               ; number to be squared
         y                              ; result
  ENDC

Squares                            ; subroutine
  ADDWF PCL,F           ; add w to program counter
        RETLW 0               ; 0^2 = 0   return
        RETLW 1               ; 1^2 = 1  return
        RETLW 4               ; 2^2 = 4  return
        RETLW 9              ; 3^2 = 9   return
        RETLW 10            ; 4^2 = .d16  return
ETC. ETC. ETC.

Bootup:
   ORG 0
   CLRF x

Main:
    MOVF x, w                     ; recall x
    CALL Squares                   ; call subroutine to lookup
                                               ;  squares
    MOVWF y                 ; y  now contains X^2
    incf x, f                         ;  add 1 to x
   goto Main                      ; do it forever

Does that help?

-- Lawrence Lile

"Nyquist was an optimist."

=> Median Filter Source Code
=> AutoCad blocks for electrical drafting

at:  http://home1.gte.net/llile/index.htm

1998\11\10@181943 by Mark Crosbie

flavicon
face
In message <spam_OUT14584634121425TakeThisOuTspamtoastmaster.com>, Lawrence Lile writes:
>Seth Wrote:
>> What is the theory behind a look up table.  How does the program
>> know when it has the data it wants?

Just one additional pointer on lookup tables. On a PIC16C84/16F84 beware if
they span a 256 byte boundary! I learned this the hard way on a project
recently.

For example, if we use the example from Lawrence below, and put addresses in
place:

Squares                            ; subroutine
0x0fc         ADDWF PCL,F           ; add w to program counter
0x0fd         RETLW 0               ; 0^2 = 0   return
0x0fe         RETLW 1               ; 1^2 = 1  return
0x0ff         RETLW 4               ; 2^2 = 4  return
0x100         RETLW 9              ; 3^2 = 9   return
0x101         RETLW 10            ; 4^2 = .d16  return

This code will work fine until W is set to 3, in which case it will branch to
address 0x100. However, the PCLATH bits aren't set correctly so the RETLW will
cause the PIC to go haywire (at least I think it is the PCLATH that is set
wrong).

See Myke Predo's book on PIC programming for more information on how to have
lookup tables longer than 256 bytes.

To ensure that your lookup tables are in the correct page, just place them on
the first page of your program (say, right after the Int handler vector).

Regards,
Mark
--
Mark Crosbie                    http://www.best.com/~mcrosbie
Hewlett-Packard MS 47 LA        .....mcrosbieKILLspamspam@spam@cup.hp.com
19447 Pruneridge Avenue         (408) 447-2308
Cupertino, CA 95014             (408) 447-6766 FAX

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...