Shop OBEX P1 Docs P2 Docs Learn Events
Instruction Timing — Parallax Forums

Instruction Timing

gemeyergemeyer Posts: 7
edited 2004-11-23 01:25 in BASIC Stamp
I am using a BS2P40 to control some LEDs and am getting a lot of flicker which I didn't expect with this fast processor. So I carefully timed many of the instructions that I use to turn the LED on or off ( OutBit(j) = ShadesBit(i) ) and found that it takes about .01 sec to execute that one command one time! That seems excessive.

Anybody have experience with timing instructions and making code run as fast as possible?

Thanks!

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-21 21:38
    Tracy Allen has done a lot of research on this and has the information on his web site: www.emesystems.com

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-11-21 21:47
    I have results of timing experiments posted at this URL:
    http://www.emesystems.com/BS2speed.htm
    The page is mostly on the original BS2 and BS2sx timing. In general, multiply the BS2 time per command by 0.3 to estimate the time the same command would take on the BS2p.

    On the BS2p, I found that a plain HIGH xpin command takes ~42 microseconds and outPin = state takes ~70 microseconds. I know the array access, like your OutBit(j) = ShadesBit(i) takes longer, but the figure you found, 10 milliseconds, seems way too much. I would have predicted less than 1 millisecond.

    The Stamp is an interpreter and it has to read each token out of the serial eeprom, and that is the bottleneck. The processor in the BS2p is running at 20mhz, but the interpreted commands are executed on a time frame of 0.1 or 1 millisecond.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-23 01:25
    Yup. While the PIC cycles at 20 Mhz / 4 == 5 MIPS, the PBasic interpreter slows that down a lot, so my rule of thumb for each PBasic instruction is 100 uSec, or 10,000 IPS. Note SEROUT, SERIN, SHIFTOUT, SHIFTIN, PULSOUT, PAUSE, etc take longer because you have to finish output of the byte at the baud rate before your program can continue executing.

    Also, the BS2 is a single tasking module. This means you can only do a SEROUT on one pin at a time. You can SEROUT on more than one pin, but each pin must finish its SEROUT before you can go on to the next.

    Note you can turn on and off multiple LED's at a time by using the OutA, OutB, OutC, or OutD instructions.
Sign In or Register to comment.