Speeding up a "for" loop (8051)

Thanks everyone, it's working well, got it down to 70uS, still waiting for the driver chips to arrive, so I can't actually test it

martin

Reply to
Martin Griffith
Loading thread data ...

I am not sure about the syntax your Compiler But for Keil C using bits if would be:

void Led7(char time) { unsigned char buff,i; // Use unsigned where possible on an 8052

buff = seg7[time];

for(i=8; i!=0;i--) // A check for zero may be faster { if(buff&0x01) { P1^5 = 1; // Use a single Bit set instruction } else { P1^5 = 0; } buff=buff>>1;

P1^7 = 1; //clock High P1^7 = 0; //clock Low } }

Reply to
Neil

That did work, (in the simulator), but I've gone over to the unrolled version, from Niklas etc I'm just soldering the ic's and display LEDs at the moment. Oh happy times!

martin

Reply to
Martin Griffith

Mini update Just wired up a couple of STP16CP05 to 2*2 7 segment display (HDSP521) on stripboard, (a bit of a mess^2)

Works very well, had to spend a couple of hours getting the grounding for the display supply, lot of ground bounce, from a 10mm bit of wirewrap wire instead of real copper

martin

Reply to
Martin Griffith

Interesting. Purely from c-point I would try:

// Putting the shift elsewhere results in more symmetric clock. void Led7(char time) { unsigned int buff;

buff = 0x0100 || seg7[time]; while ( 1 != buff ) { P1^5 = buff&0x01; P1^7 = 1; //clock High buff >>= 1; P1^7 = 0; //clock Low } }

All this may buy you nothing on the 51.

--

--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
Reply to
Albert van der Horst

[snip]

I think this should be bitwise-or, not logical-or:

buff = 0x0100 | seg7[time]

With bitwise-or, and the parameter changed to "unsigned char", this function compiled by SDCC has a WCET of some 154 machine cycles on a vanilla 8051, which means about 167 us with Martin's clock frequency. Not too bad for a loop controlled by a 16-bit variable, but nearly three times the fastest function we have seen so far.

--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .
Reply to
Niklas Holsti

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.