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

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(AB) > 180 then TURN COUNTER CLOCKWISE else TURN CLOCKWISE
else
if A > B then
if ABS(AB) < 180 then TURN COUNTER CLOCKWISE else TURN CLOCKWISE
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_OUTthorswilTakeThisOuTexmachina.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
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

Tobie Horswill <.....PICLISTKILLspam@spam@MITVMA.MIT.EDU> wrote:
> A = current angle (compass heading)
> B = desired angle (GPS waypoint heading)
>
> if A < B then
> if ABS(AB) > 180 then TURN COUNTER CLOCKWISE else TURN
> CLOCKWISE
> else
> if A > B then
> if ABS(AB) < 180 then TURN COUNTER CLOCKWISE else TURN
> CLOCKWISE
> 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 [0179]; that'll remove the need to do 16bit
math without really affecting performance.
Next, you could rewrite it as:
W = AB
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 = AB [A and B are in the range 0179].
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  aiwKILLspamcypress.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
Here is some optimization at the source level:
> if A < B then
> if BA > 180 then TURN COUNTER CLOCKWISE else TURN CLOCKWISE
> else
> if A > B then
> if AB < 180 then TURN COUNTER CLOCKWISE else TURN CLOCKWISE
> 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, lowlevel
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...