Author Topic: dsPic erasing array faster  (Read 1770 times)

0 Members and 1 Guest are viewing this topic.

Offline @rt

  • Frequent Contributor
  • **
  • Posts: 766
Re: dsPic erasing array faster
« Reply #50 on: April 23, 2018, 03:29:02 am »
It does seem reliable if I use a function with no arguments or return value
Code: [Select]
void invertframe() {
asm volatile ("MOV #_framebuffer,W1");
asm volatile ("MOV #_imagebuffer,W0");
asm volatile ("MOV.B #255,W2");
asm volatile ("REPEAT #1023");
asm volatile ("XOR.B W2,[w0++],[w1++]");
}
That sort of thing has never broken yet. This function can be called from inside a C loop as well.

EDIT,,,
let’s not do that...

Code: [Select]
void invertframe() {
asm volatile ("MOV #_framebuffer,W1");
asm volatile ("MOV #_imagebuffer,W0");
asm volatile ("MOV #0xFFFF,W2");
asm volatile ("REPEAT #511");
asm volatile ("XOR W2,[W0++],[W1++]");
}



« Last Edit: April 23, 2018, 03:43:47 am by @rt »
 

Offline NorthGuy

  • Frequent Contributor
  • **
  • Posts: 860
  • Country: ca
Re: dsPic erasing array faster
« Reply #51 on: April 23, 2018, 03:47:52 am »
It does seem reliable if I use a function with no arguments or return value
Code: [Select]
void invertframe() {
asm volatile ("MOV #_framebuffer,W1");
asm volatile ("MOV #_imagebuffer,W0");
asm volatile ("MOV.B #255,W2");
asm volatile ("REPEAT #1023");
asm volatile ("XOR.B W2,[w0++],[w1++]");
}

If you align your buffers at word boundary then using words will be almost twice as fast:

Code: [Select]
asm volatile ("MOV #_framebuffer,W1");
asm volatile ("MOV #_imagebuffer,W0");
asm volatile ("MOV #0xffff,W2");
asm volatile ("REPEAT #511");
asm volatile ("XOR W2,[w0++],[w1++]");

There's a special command for inverting, although it doesn't make much difference:

Code: [Select]
asm volatile ("MOV #_framebuffer,W1");
asm volatile ("MOV #_imagebuffer,W0");
asm volatile ("REPEAT #511");
asm volatile ("COM [w0++],[w1++]");

 

Offline @rt

  • Frequent Contributor
  • **
  • Posts: 766
Re: dsPic erasing array faster
« Reply #52 on: April 23, 2018, 04:00:14 am »
I should have known that, it was comf.
Probably compliment file register.
 

Offline @rt

  • Frequent Contributor
  • **
  • Posts: 766
Re: dsPic erasing array faster
« Reply #53 on: April 24, 2018, 02:34:47 pm »
My first DO loop worked, which is a software bit bang for SPI write. MSB goes out first.
The device select pin has already been pulled low before calling this to send a byte.

I remembered no way to copy a bit directly, so I don’t like that with the use of BTSS/BTSC,
the data pin would be set faster than it is cleared, so a serial waveform would look odd, despite working.
That is why the input byte is rotated where it is (for an extra instruction delay after the data pin possibly being sent low).

I’m wondering if I should AND the portb latch pin with the data bit for even timing?
So it would take the same time to set or clear the data pin before the latch pin is set?

Code: [Select]
void WriteSPIFast(unsigned char data_out) {
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 7; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 6; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 5; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 4; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 3; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 2; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 1; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = 0;
}

void WriteSPIFaster(unsigned char data_out) {
srbyte = data_out;
asm volatile ("BITBANG: DO #7, ENDBANG");
asm volatile ("BCLR LATB,#8");
asm volatile ("BTSC.b _srbyte,#7");
asm volatile ("BSET LATB,#7");
asm volatile ("BTSS.b _srbyte,#7");
asm volatile ("BCLR LATB,#7");
asm volatile ("RLNC.b _srbyte");
asm volatile ("ENDBANG: BSET LATB,#8");
asm volatile ("BCLR LATB,#8");
asm volatile ("BCLR LATB,#7");
}
 

Offline NorthGuy

  • Frequent Contributor
  • **
  • Posts: 860
  • Country: ca
Re: dsPic erasing array faster
« Reply #54 on: April 25, 2018, 01:22:43 am »
My first DO loop worked, which is a software bit bang for SPI write. MSB goes out first.
The device select pin has already been pulled low before calling this to send a byte.

I remembered no way to copy a bit directly, so I don’t like that with the use of BTSS/BTSC,
the data pin would be set faster than it is cleared, so a serial waveform would look odd, despite working.
That is why the input byte is rotated where it is (for an extra instruction delay after the data pin possibly being sent low).

I’m wondering if I should AND the portb latch pin with the data bit for even timing?
So it would take the same time to set or clear the data pin before the latch pin is set?

You can do even timing and a little bit faster:

Code: [Select]
// This assumes that LATB.7/8 are cleared at the entry
asm volatile ("LSR.B  _srbyte,WREG");
asm volatile ("XOR.B _srbyte,WREG"); // W0 holds differences between consecutive bits
asm volatile ("BITBANG: DO #7, ENDBANG");
asm volatile ("BTSC w0,#7");
asm volatile ("BTG LATB,#7");
asm volatile ("SL w0,w0");
asm volatile ("BSET LATB,#8");
asm volatile ("ENDBANG: BCLR LATB,#8");
asm volatile ("BCLR LATB,#7");

However, the best way is to use an SPI module.
 

Offline @rt

  • Frequent Contributor
  • **
  • Posts: 766
Re: dsPic erasing array faster
« Reply #55 on: April 25, 2018, 03:13:53 pm »
Thanks :)
Some instructions there I’m unfamiliar with. It will give me something to chew on.
I am using the hardware SPI for an SD card, and a few different software routines to match variable clock speed of another device.

I didn’t think I’d be as interested, but every time something comes back to me, significant program memory is saved.



 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf