Searching \ for '[PIC]:Optimising assembly code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Optimising assembly code'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Optimising assembly code'
2000\10\04@152358 by Tobie Horswill

flavicon
face
Hi, I posted a few weeks ago regarding a Vector 2XG electronic compass which
is now working fine, thanks all. I'm now working on parsing some NMEA
sentences from a GPS receiver and comparing the results with the heading
from the compass. I want the PIC to decide if it has to turn left or right
to match the GPS's waypoint data and the compass data. I came up with the
following logical tests to determine the shortest path to the desired
heading :

A = current angle (compass heading)
B = desired angle (GPS waypoint heading)

if A < B then
   if ABS(A-B) > 180 then TURN COUNTER CLOCK-WISE else TURN CLOCK-WISE
else
if A > B then
   if ABS(A-B) < 180 then TURN COUNTER CLOCK-WISE else TURN CLOCK-WISE
else
   NO CORRECTION;

This works fine in a little Windows App I made and I think I could port it
to PIC assembly fairly easily or program it directly in C. However, I feel
it will take a lot of program memory to directly translate every conditional
and math operator (the values are 16 bits wide since there are 360 degrees)
to the PIC. Any suggestions on how to simplify this procedure in PIC
assembly? There must be a simple combination of binary operations that will
give the same result ?!?!?


Thanks,


---------------------------------------------------------------
Tobie Horswill
Ex Machina
103, rue Dalhousie
Quibec (Quibec) CAN
G1K 4B9
spam_OUTthorswilTakeThisOuTspamexmachina.qc.ca

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
"[PIC]:" PIC only "[EE]:" engineering "[OT]:" off topic "[AD]:" ad's


2000\10\04@155444 by Don Hyde

flavicon
face
One way is to scale your headings and bearings into a binary angular
notation in which 256 units = a full circle rather than 360.  Then all the
angular arithmetic will fit into a single byte.

It seems so obvious to me to change from the ancient Sumerian 360 degrees to
a circle to a binary "degree" that I'm sure it's been done zillions of times
in navigation systems.  So much so that I suspect that such a unit has even
been given a name.  Does anybody know what it might be?

Of course "NSEW" and "North by Northwest" and such are really a cumbersome
sort of binary angular notation...

> {Original Message removed}

2000\10\04@171924 by Andrew Warren

flavicon
face
Tobie Horswill <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU> wrote:

> A = current angle (compass heading)
> B = desired angle (GPS waypoint heading)
>
> if A < B then
>     if ABS(A-B) > 180 then TURN COUNTER CLOCK-WISE else TURN
>     CLOCK-WISE
> else
> if A > B then
>     if ABS(A-B) < 180 then TURN COUNTER CLOCK-WISE else TURN
>     CLOCK-WISE
> else
>     NO CORRECTION;
>
> This works fine in a little Windows App I made and I think I could
> port it to PIC assembly fairly easily or program it directly in C.
> However, I feel it will take a lot of program memory to directly
> translate every conditional and math operator (the values are 16
> bits wide since there are 360 degrees) to the PIC. Any suggestions
> on how to simplify this procedure in PIC assembly?

Tobie:

First, you can divide all your angular measurements by 2 to get the
numbers into the range [0-179]; that'll remove the need to do 16-bit
math without really affecting performance.

Next, you could rewrite it as:

   W = A-B

   if W = 0 then NO CORRECTION
   if W < 0 then W = W + 180
   if W < 90 then TURN CCW else TURN CW

In PIC code, this works out to something like:

       MOVF    B,W     ;W = A-B [A and B are in the range 0-179].
       SUBWF   A,W     ;

       BZ      DONE    ;If W = 0 then NO CORRECTION.

       SKPC            ;If W >= 0 then skip ahead.
       ADDLW   180     ;Otherwise, W = 180 + W.

       SUBLW   89      ;W = 89 - W.
       BC      TURNCCW ;If W >= 0 (in other words, if the old W was
                       ;less than 90), go TURN CCW.

   TURNCW:

       ....            ;Otherwise, TURN CW.

       GOTO    DONE

   TURNCCW:

       ....

   DONE:

-Andy


=== Andrew Warren --- aiwspamKILLspamcypress.com
=== Cypress Semiconductor Corporation
=== Interface Products Division, S.D.
===
=== The opinions expressed above do
=== not necessarily represent those of
=== Cypress Semiconductor Corporation.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
"[PIC]:" PIC only "[EE]:" engineering "[OT]:" off topic "[AD]:" ad's


2000\10\04@230907 by Bob Ammerman

picon face
Here is some optimization at the source level:

> if A < B then
>     if B-A > 180 then TURN COUNTER CLOCK-WISE else TURN CLOCK-WISE
> else
> if A > B then
>     if A-B < 180 then TURN COUNTER CLOCK-WISE else TURN CLOCK-WISE
> else
>     NO CORRECTION;

Since you already know the sign of the difference between A and B you don't
need the ABS() functions.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
"[PIC]:" PIC only "[EE]:" engineering "[OT]:" off topic "[AD]:" ad's


More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...