speeding up SHIFT

Questions about the BASICtools and MakeItC
Post Reply
YahooArchive
Posts: 1463
Joined: Fri Oct 19, 2012 5:11 am

speeding up SHIFT

Post by YahooArchive » Thu Oct 25, 2012 6:24 pm

>question from the info line

Is it possible to speed up SHIFTOUT and SHIFTIN operations? Now
SHIFTOUT give me ~30uS@8bit packet size. I need as fast as it can be.

-------------------

Now with version 7, you have the source in BASIC for these routines.
There are a number of things that can be done to speed up these routines.

First they are all parameterized, in other words can accept any pin
group as an input. This takes time.

Also the loops can be unwound, meaning the sending of bits is in a
while loop. It can be changed to 8 serial operations.

For instance to remove the parameterization. Referring to the
schematic and the user manual for the 2103. IO(0) and IO(1)
correspond to bits 9 and 8 in the GPIO register of the 2103. These
bits can be set by writing 1 to $E0028004 and cleared at $E002800C.

So the inner loop of SHIFTOUT can become

#define GPIO_SET *$E0028004
#define GPIO_CLR *$E002800C

... initialization

if value and 1 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit
if value and 2 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit
if value and 4 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit
if value and 8 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit
if value and 16 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit
if value and 32 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit
if value and 64 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit
if value and 128 then GPIO_SET = $80 else GPIO_CLR = $80
GPIO_SET = $100
GPIO_CLR = $100 ' clock bit


I have not timed this code, but it probably will double the speed of
SHIFTOUT

As you can see nothing is free as the code becomes dedicated for the
operation and larger, but does maximize speed. Beyond that C might
improve it a little, or you could switch to assembly language in C
which might get another factor of 2.



Post Reply