# Long Table Read - Code Optimize

Status
Not open for further replies.

#### Suraj143

##### Active Member
I'm doing a neo pixel project & need to call a long table but it has to read from less cycles.Because I'm reading this table between data transfer in LEDs so time is critical. Is there any method to reduce some cycles? I use modern PIC16F1508 with CLC module. It has some enhanced instructions like "MOVLP Move literal to PCLATH" etc...

I use 16Mhz clock so instruction cycle will be 250nS.

Code:
;Table located in above 2K limit upto 4K
Pat_Table        movlw        High(Table)        ;1
movwf        PCLATH            ;3
movlw        Low(Table)        ;4
btfsc       STATUS,C        ;6
incf        PCLATH,f        ;7
MOVWF       PCL                ;8
dt            00,.1,.2,.3.....;10 cycles

#### Pommie

##### Well-Known Member
As you're only reading 8 bits you can do it via FSR and use MOVIW to access it with autoincrement. See section 3.2.1.2 in datasheet.

Mike.

#### Suraj143

##### Active Member
Hi thanks I'll look into that as well.

Can I minimize my table read like this? Because the higher byte "offsetH" is located above 2K...

Code:
;Table located in above 2K limit upto 4K
Pat_Table        movf        offsetH, W        ;1
movwf        PCLATH            ;2
movf        offsetL,W        ;3
MOVWF       PCL                ;4
dt            00,.1,.2,.3.....;6 cycles/[CODE]

#### Pommie

##### Well-Known Member
If you setup FSRL/H once then reading is a single instruction with autoincrement. So, each read will be 1 cycle. Much quicker.

Mike.
Note, in the above (your) code you still need to increment the pointer.

#### Nigel Goodwin

##### Super Moderator
I'm doing a neo pixel project & need to call a long table but it has to read from less cycles.Because I'm reading this table between data transfer in LEDs so time is critical. Is there any method to reduce some cycles? I use modern PIC16F1508 with CLC module. It has some enhanced instructions like "MOVLP Move literal to PCLATH" etc...

I use 16Mhz clock so instruction cycle will be 250nS.
There are a number of different NeoPixel examples on the MicroChip Xpress Examples site, using the CLC means that's most of it is processor independent, so you have plenty of time (relatively) to deal with table reads.

There's even an 18F example that uses DMA as well as CLC.

#### Suraj143

##### Active Member
If you setup FSRL/H once then reading is a single instruction with autoincrement. So, each read will be 1 cycle. Much quicker.

Mike.
Note, in the above (your) code you still need to increment the pointer.
Hi Mike

I'm going to use FSRL/H to index my table.
Is there anyway to write my table pattern in programing memory?

Below won't work.I need to place constants from the below address location so I can directly read from FSR...!!!
Code:
               org        0x800   ;2049 location starts pattern table
Pattern_Table
DW        00h
DW        .1         ;represent colour Red
DW        .2         ;represent colour Green
DW        .3          ;represent colour Blue
DW        .4          ;represent colour Orange