Hi,
... Taking out the hserout instructions, so just getting range and step data, then sending them to scratchpad, took 14.61 seconds for 10 sweeps.
...... This brought the total time down to 20.89s, or 2.1s per sweep.
In principle, you should be able to get the overall time down to about 14.6 seconds even
with the HSEROUTs, because they should be performed by Hardware as a parallel (background) task. With a true "High Level" language (where the Hardware and Software are almost entirely separated by the Operating System), the User (Programmer) would simply "throw" characters at a buffer and the OS (Interrupts) would send out the characters when time is available. But AFAIK the PICaxe Basic Interpreter doesn't work that way, and a quick look at the X2 data suggests that Serial
Transmit Interrupts are not supported at all?
Basically, you need to divide the program into modules (sections) which execute in between about 4 and 8 ms. Simple instructions should execute in about 50 - 100us each (at 64 MHz) but subroutine calls take several times longer and some complex instructions may take very much longer, for example a SEROUT (one byte at 2400 baud) is about 4.5 ms or a DEBUG at ~120 ms ! That's why we (or at least I) need to see some actual code to estimate if it can be made faster.
In principle you then need to put a single HSEROUT instruction (one byte) between each section of the program. The bytes transmitted might correlate directly with the program execution, but if necessary you could emulate an interrupt-driven type of system. To do that, send each byte to a buffer (as you have tried) when it is created and advance an "input" pointer (variable) to the next (empty) byte. Then, between each section of the main program, compare an "output" pointer with the "input" pointer and, if different, read a byte, HSEROUT it, and advance the pointer. But if any of the sections of the main program may take less than about 4 ms (i.e. the HSEROUT character time) then first confirm that the hardware buffer is empty (which probably needs a PEEKSFR command), otherwise skip the HSEROUT on that occasion.
Another advantage of HSEROUT is that you can use a custom Baud Rate. In the Simulator, try
SERTXD(#B2400_64," ",#B4800_64) which should show the delay count for those two baud rates (6666 and 3333). Thus you can calculate the number for any intermediate baud rate, which can be inserted directly into the command, or by a custom:
symbol B4000_64 = 4000 (which is mainly a coincidence). Note that this does
not work with SEROUT.
Cheers, Alan.