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.

Copy Buffer Code Optimize

Status
Not open for further replies.

Suraj143

Active Member
In my LED matrix I implemented a display double buffer & need to copy the working buffer to display buffer.I wrote a code but it takes lots of time closer to 650uS :(

Note: The working buffer is in Bank0 & the Display buffer in Bank 1.

Code:
;physical placement of working buffer           
;D2 D4 D6 D8 D10 D12 D14 D16 D18 D20 D22 D24 D26 D28 D30 D32 D34 D36 D38 D40 D42 D44 D46 D48 D50 D52 D54 D56 D58 D60 D62 D64
;D1 D3 D5 D7 D9  D11 D13 D15 D17 D19 D21 D23 D25 D27 D29 D31 D33 D35 D37 D39 D41 D43 D45 D47 D49 D51 D53 D55 D57 D59 D61 D63           
           
            cblock    30h    ; Working buffer 64 bytes
            D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,D11,D12,D13,D14,D15,D16            ;30-3Fh
            D17,D18,D19,D20,D21,D22,D23,D24,D25,D26,D27,D28,D29,D30,D31,D32        ;32 40-4F
            D33,D34,D35,D36,D37,D38,D39,D40,D41,D42,D43,D44,D45,D46,D47,D48        ;48 50-5F
            D49,D50,D51,D52,D53,D54,D55,D56,D57,D58                        ;58 60-69h
            endc
           
            cblock    0D0h    ; Display buffer 64 bytes
            ; 64 bytes RAM
            endc
           
Copy_Buffer        movlw        30h
            movwf        FSR
            movlw        .32
            movwf        Counter
            ;
Copy_Loop        movf        INDF,W    ; B0 INDF    ;    ;1
            movwf        Temp                ;    ;2
            movlw        .48                ;    ;3
            addwf        FSR,F        ; B1 INDF    ;    ;4
            movf        Temp,W            ;    ;5
            movwf        INDF                ;    ;6
            ;
            movlw        .47                    ;7
            subwf        FSR,F        ; B0 INDF + 1    ;8
            movf        INDF,W                ;9
            movwf        Temp                    ;10
            movlw        .48                    ;11
            addwf        FSR,F        ; B1 INDF        ;12
            movf        Temp,W                ;13
            movwf        INDF                    ;14
            ;   
            movlw        .48                    ;15
            subwf        FSR,F        ; back to B0    ;16
            decfsz    Counter,F                ;17
            goto        Copy_Loop                ;19
            return
 
Why copy the buffer? When we double buffered something we updated one buffer whilst displaying the other.

Mike.
 
Hi,

I haven't double buffered yet. I currently have only one buffer "Working buffer". In the main loop I'm doing animating patterns to this buffer. In the ISR I have the same buffer for display part as well.

I'm going to implement a double buffer by assigning another 64 RAM named as display buffer in Bank 1.
 
If you use the 64 bytes located at 0x20 and 0x120 and use indirect addressing to access them then you will only need to flip one bit (status,irp) to switch between buffers.

A single flag can indicate which buffer is being displayed and which to work on.

Mike.
Edit, alternatively, use 0x30 and 0x130.
 
That's a great suggestion.I'll implement it.
Somehow at the end of the each frame (16mS) I have to update the display buffer.Did a small code to copy buffers & it takes now only 416 uS.

Code:
;copy working buffer to display buffer @ end of frame  
Copy_Buffer       movlw        30h
                movwf        FSR
                movlw        .32
                movwf        Counter
                ;
Copy_Loop            movf        INDF,W        ;1
                bsf        STATUS,IRP        ;2
                movwf        INDF            ;3
                bcf        STATUS,IRP        ;4
                incf        FSR,F            ;5
                movf        INDF,W        ;6
                bsf        STATUS,IRP        ;7
                movwf        INDF            ;8
                bcf        STATUS,IRP        ;9
                incf        FSR,F            ;10
                decfsz        Counter,F        ;11
                goto        Copy_Loop        ;13
                return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top