Quantcast
Channel: Learn with BlocklyProp — Parallax Forums
Viewing all articles
Browse latest Browse all 293

Question about speed of code generated with PropellorIDE

$
0
0
I have been fiddling with MAX7219 recently. I found I could not write a string of 8x8 modules quickly enough in spin and had to go to PASM to get decent looking text scrolling. In large part it comes down to how long it takes to do a 16-bit SPI. In PASM, it is less than 10 uSec, in spin, it is about 600 uSec. Fair enough.

Then I thought, how about C? It is a lot faster than spin. But the results make it clear I am doing something wrong. Here is the nub of what I did:
  while(1)
{
   low(MX7219CS);
   shift_out(MX7219D, MX7219Clk, MSBFIRST, 16, 0x55aa);
   high(MX7219CS);
}

shiftout.jpg is a logic analyzer capture. It can be seen it takes nearly a mSec from CS active to CS inactive. Shiftout.zip is the actual program. Clearly I am missing something. That is not the sort of speed one would expect from compiled code.

I thought perhaps the shift_out function is artificially slowed down to avoid overrunning slow peripherals, so I wrote my own little shifter.
void MyShift16(int ShiftVal) {
  for (int i = 0; 1 < 16; i++)  {
     if ((ShiftVal & 0x8000) == 0)
         low(MX7219D);
     else
         high(MX7219D);
     ShiftVal = ShiftVal << 1;
     pulse_out(MX7219Clk, 1);
   }
}

function.jpg is a capture, functionshift.zip is the actual program. It is even worse, almost 2 mSec to do a 16-bit SPI.

So I am hoping some kind soul can set me straight. What am I doing wrong?

Viewing all articles
Browse latest Browse all 293

Trending Articles