--_003_4223639051298857752246fastmobilecom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Floor is the lowest a value can go ----- Sent from my Cell phone --_003_4223639051298857752246fastmobilecom_ Content-Type: message/rfc822 Received: (qmail 27001 invoked from network); 28 Feb 2011 01:35:16 -0000 Received: from unknown (HELO p3pismtp01-029.prod.phx3.secureserver.net) ([10.6.12.39]) (envelope-sender ) by p3plsmtp01-05.prod.phx3.secureserver.net (qmail-1.03) with SMTP for ; 28 Feb 2011 01:35:16 -0000 Received: from pch.mit.edu ([18.7.21.90]) by p3pismtp01-029.prod.phx3.secureserver.net with ESMTP; 27 Feb 2011 18:35:16 -0700 Received: from pch.mit.edu (pch.mit.edu [127.0.0.1]) by pch.mit.edu (8.13.6/8.12.8) with ESMTP id p1S1VVmR019569; Sun, 27 Feb 2011 20:31:47 -0500 Received: from mailhub-dmz-4.mit.edu (MAILHUB-DMZ-4.MIT.EDU [18.7.62.38]) by pch.mit.edu (8.13.6/8.12.8) with ESMTP id p1S1VUct019566 for ; Sun, 27 Feb 2011 20:31:30 -0500 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by mailhub-dmz-4.mit.edu (8.13.8/8.9.2) with ESMTP id p1S1VQ0n028285 for ; Sun, 27 Feb 2011 20:31:30 -0500 Received: from smtp5.clear.net.nz ( [203.97.33.68]) by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with SMTP id B6.79.02603.1FAFA6D4; Sun, 27 Feb 2011 20:31:29 -0500 (EST) Received: from ivp1 (218-101-79-132.dialup.clear.net.nz [218.101.79.132]) by smtp5.clear.net.nz (CLEAR Net Mail) with SMTP id <0LHB00EDZ07ZGM50@smtp5.clear.net.nz> for piclist@mit.edu; Mon, 28 Feb 2011 14:31:13 +1300 (NZDT) From: IVP To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Sun, 27 Feb 2011 17:29:54 -0800 Subject: [PIC] Sunrise/sunset calculation Thread-Topic: [PIC] Sunrise/sunset calculation Thread-Index: AcvW6kcHMXlolFEwQ46+M4U2MauDeg== Message-ID: <5091877.840.1298857752245.JavaMail.fastmobile@pmfsync02.priv.mfluent.net> List-Help: List-Subscribe: , List-Unsubscribe: , Reply-To: Microcontroller discussion list - Public. Accept-Language: en-US X-MS-Has-Attach: X-Auto-Response-Suppress: All X-MS-TNEF-Correlator: errors-to: piclist-bounces@mit.edu list-post: list-id: "Microcontroller discussion list - Public." x-brightmail-tracker: AAAAAReAgWI= x-auditid: 1209190f-b7c1dae000000a2b-98-4d6afaf04311 x-ironport-anti-spam-result: AlkAAIeHak0SBxVakWdsb2JhbACJdI9jjG0VAQEBAQkLCgcRBSC6HYVhBJgu x-beenthere: piclist@mit.edu x-mailman-version: 2.1.6 x-topics: [PIC] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Hi all, I'm working on a solar tracker and would like to calculate the sunrise/sunset position. The aim is to use a PIC controlling a pair of steppers and gear trains One algorithm frequently cited is this one http://williams.best.vwh.net/sunrise_sunset_algorithm.htm That page is reproduced below Now, the first problem has arisen. Do I assume correctly that the C function "floor" is similar to INT ? ie, the decimal part of a result is discarded ? http://en.wikipedia.org/wiki/Floor_and_ceiling_functions 15th November 2010, day of year (by addition) 319 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 15 =3D 319 day =3D 15, month =3D 11, year =3D 10 N1 =3D floor(275 * 11 / 9) N1 =3D 336 N2 =3D floor((month + 9) / 12) N2 =3D 1 N3 =3D 5 [ by way of (1 + INT(10 - (4 * (INT(10/4) + 2)/3))) ] N =3D 336 - (1 * 5) + 15 - 30 N =3D 316 Where did the other 3 days go ? Or what did I miss ? Working today's date, 28th February 2011, day of year 59 N1 =3D floor(275 * 2 / 9) N1 =3D 61 N2 =3D floor((2 + 9) /12) N2 =3D 0 N3 =3D 6 [ by way of (1 + INT(11 - (4 * (INT(11/4) + 2)/3))) ] N =3D 61 - (0 * 6) + 28 - 30 N =3D 59 Coincidentally correct ? Joe For your interest, timeanddate do solar tables (show all columns) eg, this month in Auckland http://www.timeanddate.com/worldclock/astronomy.html?n=3D22&month=3D2&year= =3D2011&obj=3Dsun&afl=3D-1&day=3D1 Compare Quito (equator) and Nome (way north) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Source: Almanac for Computers, 1990 published by Nautical Almanac Office United States Naval Observatory Washington, DC 20392 Inputs: day, month, year: date of sunrise/sunset latitude, longitude: location for sunrise/sunset zenith: Sun's zenith for sunrise/sunset offical =3D 90 degrees 50' civil =3D 96 degrees nautical =3D 102 degrees astronomical =3D 108 degrees NOTE: longitude is positive for East and negative for West NOTE: the algorithm assumes the use of a calculator with the trig functions in "degree" (rather than "radian") mode. Most programming languages assume radian arguments, requiring back and forth convertions. The factor is 180/pi. So, for instance, the equation RA =3D atan(0.91764 * tan(L)) would be coded as RA =3D (180/pi)*atan(0.91764 * tan((pi/180)*L)) to give a degree answer with a degree input for L. 1. first calculate the day of the year N1 =3D floor(275 * month / 9) N2 =3D floor((month + 9) / 12) N3 =3D (1 + floor((year - 4 * floor(year / 4) + 2) / 3)) N =3D N1 - (N2 * N3) + day - 30 2. convert the longitude to hour value and calculate an approximate time lngHour =3D longitude / 15 if rising time is desired: t =3D N + ((6 - lngHour) / 24) if setting time is desired: t =3D N + ((18 - lngHour) / 24) 3. calculate the Sun's mean anomaly M =3D (0.9856 * t) - 3.289 4. calculate the Sun's true longitude L =3D M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634 NOTE: L potentially needs to be adjusted into the range [0,360) by adding/subtracting 360 5a. calculate the Sun's right ascension RA =3D atan(0.91764 * tan(L)) NOTE: RA potentially needs to be adjusted into the range [0,360) by adding/subtracting 360 5b. right ascension value needs to be in the same quadrant as L Lquadrant =3D (floor( L/90)) * 90 RAquadrant =3D (floor(RA/90)) * 90 RA =3D RA + (Lquadrant - RAquadrant) 5c. right ascension value needs to be converted into hours RA =3D RA / 15 6. calculate the Sun's declination sinDec =3D 0.39782 * sin(L) cosDec =3D cos(asin(sinDec)) 7a. calculate the Sun's local hour angle cosH =3D (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude= )) if (cosH > 1) the sun never rises on this location (on the specified date) if (cosH < -1) the sun never sets on this location (on the specified date) 7b. finish calculating H and convert into hours if if rising time is desired: H =3D 360 - acos(cosH) if setting time is desired: H =3D acos(cosH) H =3D H / 15 8. calculate local mean time of rising/setting T =3D H + RA - (0.06571 * t) - 6.622 9. adjust back to UTC UT =3D T - lngHour NOTE: UT potentially needs to be adjusted into the range [0,24) by adding/subtracting 24 10. convert UT value to local time zone of latitude/longitude localT =3D UT + localOffset --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --_003_4223639051298857752246fastmobilecom_ Content-Type: text/plain; name="ATT00001.txt" Content-Description: ATT00001.txt Content-Disposition: attachment; filename="ATT00001.txt"; size=208; creation-date="Sun, 27 Feb 2011 17:53:21 GMT"; modification-date="Sun, 27 Feb 2011 17:53:21 GMT" Content-Transfer-Encoding: base64 LS0gDQpodHRwOi8vd3d3LnBpY2xpc3QuY29tIFBJQy9TWCBGQVEgJiBsaXN0IGFyY2hpdmUNClZp ZXcvY2hhbmdlIHlvdXIgbWVtYmVyc2hpcCBvcHRpb25zIGF0DQpodHRwOi8vbWFpbG1hbi5taXQu ZWR1L21haWxtYW4vbGlzdGluZm8vcGljbGlzdA0K --_003_4223639051298857752246fastmobilecom_-- .