Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help with PIC 18F Lookup Table Reading/Addresses

Status
Not open for further replies.

3BABY

Member level 5
Joined
Jan 14, 2011
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
New Zealand
Activity points
2,252
Hi All,

i have a bit of a problem, and cant seem to find an answer..

i have 4 tables in my program all consisting of 128 values..

say TABLE1, TABLE2, TABLE3, TABLE4.. in my ode they are setup like this:

Code:
TABLE1 	ORG d'512'

ADDWF PCL, F

RETLW b'00000100'
.
.
... to 128 RETLW's



TABLE2 	ORG d'1536'

ADDWF PCL, F

RETLW b'00000100'
.
.
... to 128 RETLW's



TABLE3 	ORG d'2048'

ADDWF PCL, F

RETLW b'00000100'
.
.
... to 128 RETLW's


TABLE4 	ORG d'2560'

ADDWF PCL, F

RETLW b'00000100'
.
.
... to 128 RETLW's



then i use

Code:
MOVLW d'252'  ;for testing

BCF PCLATH, 0
BSF PCLATH, 1
CALL TABLE2

the problem i have is if i call TABLE2 and add 252 to the program counter i dont get my desired value.. the PC jumps into TABLE1 and returns me the 128th value from there.. obviously its a problem with my ORG statements or the place where ive put the tables.. but i cant seem to work it out..

any help would definitely save me from going bald..
 

Why do not use the more effective TBLPTR-tblrd method?

However, try out this:
ORG d'1536'

TABLE2

ADDWF PCL, F
....
 

Why do not use the more effective TBLPTR-tblrd method?

However, try out this:
ORG d'1536'

TABLE2

ADDWF PCL, F
....

thanks for the reply.. changing the position or ORG had the same result .. ill checkout the TBLPTR method.. thanks for the advice :)
 

Hi 3BABY;

Sorry, but last night I was too sleepy : - )

TBLPTR: The method is always used, but it is also true that the retlw table is faster and simpler
(although it uses more flash memory).

This works for me (but only 127 item/table !):

Code:
;the call itself

  movlw 126     ;to get the item 126 (252/2) but max. 127

  addwf WREG, w ; duplicate it here (127 retlw item)
  call table2   ; automatically sets the PCLATH accordingly 
;....

;....
  org 0x100 ; (hex 256, for example) 
;can be placed anywhere but always to be the beginning of a page

table2:
  ;addwf WREG, w ; if it's here then only 126 retlw item can be used
  addwf PCL      ;therefore only be max. 127 retlw item
  retlw 1
  retlw 2
...
  retlw 127      ;last possible item, page boundary !!

;next table if needed
  org table2 + 0x100 ; 0x200  (hex 512) 
table3:
  addwf PCL
  retlw 1
  retlw 2
...
  retlw 127      ; last table3 item

  org table3 + 0x100 ; just checking the page boundary
  nop

Try out it
Welcome
zuisti
 
  • Like
Reactions: 3BABY

    3BABY

    Points: 2
    Helpful Answer Positive Rating
That's why TBLPTR was introduced!

W is an 8-bit wide register so its maximum value is 255 (Decimal)
You are using 8-bit data in your table but each address is 16 bits (two addresses) wide.
So your maximum offset is 255/2 = 127 (to the nearest integer).

Brian.
 
  • Like
Reactions: 3BABY

    3BABY

    Points: 2
    Helpful Answer Positive Rating
Hi 3BABY;

Sorry, but last night I was too sleepy : - )

TBLPTR: The method is always used, but it is also true that the retlw table is faster and simpler
(although it uses more flash memory).

This works for me (but only 127 item/table !):

Thanks for the info! i gave it a go using TBLPTR method... i had 8 pages worth of table so that used up a bit of program space but it works great!!

thanks guys!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top