parallaxinc / cyberbot

Firmware, library, and loader code for cyberbot hardware
MIT License
8 stars 0 forks source link

Reduce time overhead per command #4

Closed AndyLindsay closed 5 years ago

AndyLindsay commented 5 years ago

The code below tested on the 10/25 firmware and libraries repeated every 9.25 ms. With the 11/1 firmware, it takes 60 to 62 ms.

while True:
    bot(16).digital_write(0)
    bot(16).digital_write(1)
AndyLindsay commented 5 years ago

I meant to say, "...11/1 firmware and libraries..."

PropGit commented 5 years ago

Whoa, that's a huge change in speed. I hope it can be fixed.

MatzElectronics commented 5 years ago

Try now with the reset checking offloaded to its own cog. Should now go back to its pervious speed.

PropGit commented 5 years ago

With regards to potential slowdowns, the code that reads and clears args can take much less C overhead time by taking advantage of the fact that the args are defined contiguously and calling a single memcpy and memset. This is probably not the big slowdown we see, but there is a fair amount of extra overhead there.

so this...

    int arg1, arg2, arg3, arg4, arg5;
    int retVal = 0;

    memcpy(&arg1, &reg[ARG1], 4); memcpy(&reg[ARG1], &retVal, 4);
    memcpy(&arg2, &reg[ARG2], 4); memcpy(&reg[ARG2], &retVal, 4);
    memcpy(&arg3, &reg[ARG3], 4); memcpy(&reg[ARG3], &retVal, 4);
    memcpy(&arg4, &reg[ARG4], 4); memcpy(&reg[ARG4], &retVal, 4);
    memcpy(&arg5, &reg[ARG5], 4); memcpy(&reg[ARG5], &retVal, 4);

can be changed to this...

    int arg1, arg2, arg3, arg4, arg5;
    int retVal = 0;

    memcpy(&arg1, &reg[ARG1], 20);
    memset(&reg[ARG1], 0, 20);
AndyLindsay commented 5 years ago

@MatzElectronics @PropGit 30 ms delays between bot(pin).digital_write(state) are still there. The I2C bus rests for 25 ms between 5 ms communication packets.

AndyLindsay commented 5 years ago

Verified, fixed in 11/8/18 6:27 PM commit. digital_write(0/1) cycles at about 3.8 ms per command.