Continue to Site

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.

  • 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.

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
                addwf        offsetH, W        ;2
                movwf        PCLATH            ;3
                movlw        Low(Table)        ;4
                addwf        offsetL,W        ;5
                btfsc       STATUS,C        ;6
                incf        PCLATH,f        ;7    
                MOVWF       PCL                ;8
                dt            00,.1,.2,.3.....;10 cycles
 
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.
 
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]
 
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.
 
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.
 
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
 
You just load FSRH with high(Pattern_Table)+$80 and FSRL with low(Pattern_Table). Note the table can be at any address.

Mike.
Edit, the pattern is in program memory by using dw.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top