## Calculate the Right Ascension of Polaris

14 posts / 0 new
Author
Message

In order to correctly polar align a telescope (so that it can accurately track the movement of the stars) a popular method is to use a 'polarscope' which requires knowledge of the current position of polaris, which moves around the true north pole in a small circle.

I had assumed that all one needed to know was its right ascension, which is added to the sidereal time MOD 24 hours. This is correct, but I did not know that Polaris' RA is changing rapidly, by 21 minutes since New Year 2000, and about 4 1/2 hours by 2100. Obviously this is a large enough drift that it needs to be taken into account - the polarscope reticule is marked in 1-hour divisions and can be estimated to about 10 minutes.

A plot of RA against year shows that it can be closely approximated by the equation (using just the last two year digits):

RA = 0.0092 * year^2 + 1.0998 * Year + 150.57

But, an accuracy of just 3-4 minutes is plenty for good polar alignment with a polarscope. This means we can approximate it easily using simple integer multiplication and right-shift division. Here's my solution, there are probably better ones but this is good enough. Note the use of the carry for rounding and that the final big division (by 128) is left to the end to retain accuracy.

```;Calculate RA of Polaris given year in minutes

;RA = 150 +(year/8 + year) * (year+128)/128 give an accuracy of no worse than 3 minutes

POLARIS_RA:
lds		temp,DATE+2	;Put current year in temp1
mov		temp1,temp

lsr		temp1
lsr		temp1
lsr		temp1			;year/8
mov		temp2,temp1
brcc	SKIP55
inc		temp2			;round
SKIP55:

ldi		temp1,128
mul		temp1,temp2
lsr		R1
ror		R0
lsr		R1
ror		R0
lsr		R1
ror		R0
lsr		R1
ror		R0
lsr		R1
ror		R0
lsr		R1
ror		R0
lsr		R1
ror		R0
brcc	SKIP56
inc		R0			;round
SKIP56:
clr		temp2

add		temp1,R0		;Ra in minutes in Temp1:temp2

ret```

It's me again...

And in C that would be 1 line so you can then move on to thinking about the more important stuff! ;-)

I guess you are proposing that this code could be included in a telescope controller, is that right?  It occurs to me that you could also store a byte array of minutes_offset[], beginning with 2016 as offset 0.  You mentioned about 4.5 hours until 2100, so a single byte would cover most of that (and you know that in 2090 nobody would be using your device - in fact, it doesn't make sense to program for much beyond when your flash is likely to fail anyway).  Anyway, your code and approach take me back about 40 years to my own youth, programming a 2 MHz 8080 (but _I_ didn't have a MUL instruction!) and burning the programs onto 256x8 EPROMS.

256x8 eproms! Luxury!

I just get a kick out of hard coding a function, complex or simple.

Finding a solution is like solving  a cryptic crossword clue.

Wasted some time yesterday on calculating sine using integers and only right-shift division, but a look up and interpolate will be more than enough for my needs.

Neil

It's me again...

There's always CORDIC for such things.

Neil don't listen to the fun police an enjoy your assembler.

As always, in my bottomless pit of ASM stuff, I have sine and cosine routines. Never used them myself but they are supposedly able to run with AS4 end therefore the Atmel assembler.

The author is  João D´Artagnan A. Oliveira from Brasília, Brazil.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

js wrote:
The author is João D´Artagnan A. Oliveira from Brasília, Brazil.

I'm just trying to get my head around the difference between using sin/cos written by another Asm programmer and the sin/cos provided in a C library (which, surprise, surprise, was also written by an Asm programmer).

Because one is written in ASM (which the OP understands) and the other is written in C which the OP may or may not understand or even want to understand.

Anyway you must admit that something written by a D´Artagnan would be very sharp and to the point.....

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

I would be pretty certain that the ASM routines that are written for the GCC libraries will have clear documentation on input conditions, registers used, outputs, ...
And should be understood by anyone.
The only "connection" to C is that register use will follow some form of convention. Anathema to the diehard ASM enthusiast.
.
Yes, there is satisfaction to be gained from a short or fast solution. Especially if it has a noticeable effect on the program size or efficiency.
.
For a one-off calculation, I doubt if the Stars will ever notice.
.
David.

Cordic is good but where extreme accuracy isn't important but a straightforward approach is, I'm surprised Bhaskara I's formula isn't more well known.

It's me again...

Depends if you consider multiply and division expensive.

Fewer multiplications than Cordic, so it's just the one division, but my point was more about simplicity than efficiency.

It's me again...