Hi,
After browsing thru this for 30 minutes or so I would say you've done a pretty damn good job. I was going to suggest running the SPI clock faster but it's already at 8MHz with the MCP2515 maxing out at 10.
There are a lot of WHILE ! SSP1IF :WEND statements waiting for the SPI peripheral. At 8MHz there's not THAT many instructions wasted but I suppose you could possibly pull the part of the display update routine where you're sending the VideoBuffer out of the mainloop, make a subroutine out of that and GOSUB that before entering the WHILE ! SSP1IF :WEND. Checking if a screen update is in progress, if the TXREG is free and, if so, put a byte there is perhaps something it can do while the SPI peripheral clocks out 8 bits. It MIGHT slow down the SPI thruput slightly but I think it should increase the overall speed - you'll have to try it. At least it'll DO something other than twiddling its thumbs waiting for the SPI peripheral.
How often is the screen updated?
It looks like you're updating the full VideoBuffer array every time it's time for a screen update. I'm not sure but I can imagine that massive ARRAYWRITE might take some time.
Perhaps you can have one VideoBuffer for Screen 0 and one for Screen 1 and update the entries when the values are received or changed instead of making that full snapshot every time?
BTW, what sort of display is this?
The checksum routine...
Code:
CheckSum = (CAN0RXBUF[CAN0RXPOINT + 5] >> 4) + (CAN0RXBUF[CAN0RXPOINT + 5] & %00001111) + (CAN0RXBUF[CAN0RXPOINT + 6] >> 4) + (CAN0RXBUF[CAN0RXPOINT + 6] & %00001111)_
+ (CAN0RXBUF[CAN0RXPOINT + 7] >> 4) + (CAN0RXBUF[CAN0RXPOINT + 7]& %00001111) + (CAN0RXBUF[CAN0RXPOINT + 8] >> 4) + (CAN0RXBUF[CAN0RXPOINT + 8] & %00001111) + (CAN0RXBUF[CAN0RXPOINT + 9] >> 4) + (CAN0RXBUF[CAN0RXPOINT + 9] & %00001111)_
+ (CAN0RXBUF[CAN0RXPOINT + 10] >> 4) + (CAN0RXBUF[CAN0RXPOINT + 10] & %00001111) + (CAN0RXBUF[CAN0RXPOINT + 11] >> 4) + (CAN0RXBUF[CAN0RXPOINT + 11] & %00001111) 'Add packet bytes 0-6 inclusive
I don't know if it'll be faster but I think the following will do the same thing:
Code:
Checksum = 0
For i = (CAN0RXPOINT + 5) to (CAN0RXPOINT + 11)
Checksum = Checksum + ( (CAN0RXBUF[i] >> 4) + (CAN0RXBUF[i] & %00001111) )
NEXT
And you can make that loop faster by precalculating the start and end values, like
Code:
StartValue = CAN0RXPOINT + 5
EndValue = CAN0RXPOINT + 11
FOR i = StartValue TO EndValue
Checksum = Checksum + ( (CAN0RXBUF[i] >> 4) + (CAN0RXBUF[i] & %00001111) )
NEXT
I don't know if something happened with the format of the file when you uploaded but as I was going thru it I had to indent a lot of code in IF/ELSE/ENDIF blocks in order to figure out what belonged to what.
Anyway, I think you've done an excellent job. If you really want to know where the possible bottlenecks are you'll have to start measure it.
/Henrik.
Bookmarks