News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Unexpected delay in serial output.

Started by david, Nov 29, 2023, 05:00 AM

Previous topic - Next topic

trastikata

As tumbleweed mentioned, if you don't need a signed division by 2, then use unsigned variable and shift it right by 1, this is the equivalent of division by 2^n, where n is the number of shifts.

david

Many thanks for your efforts and advice there guys.  I might just have to accept that that's the way it is with 32 bit numbers.
When I first came across the problem I had a more complex term for deriving "dist"

dist=turn/2-turn*turn/65536    (actually needed dist=turn*0.501-turn*turn/63662)

So while the magnitude of "turn" was limited to 5000 the maths required the SDWord.  I may be able to drop the signed values but with playing around I found no obvious difference in the serial timing whether I used signed or unsigned values or simple maths or the more complex term above.  I guess the delays were happening before the serial output rather than during it but that's acceptable.
So Example 3 looks to be the best option - it allows the complex maths conversion, has no delays in the serial output and is fairly concise.

Best regards,
David