The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 28, 2024, 06:54:38 18:54


Login with username, password and session length


Pages: [1]
Print
Author Topic: astronomical clock request  (Read 5442 times)
0 Members and 1 Guest are viewing this topic.
koky
Active Member
***
Offline Offline

Posts: 181

Thank You
-Given: 154
-Receive: 157


WWW
« on: August 03, 2010, 04:01:40 16:01 »

who know the mode or algoritm for make an digital clock that regonize the time clock in function of the sunset and sunrise ? In internet i have found many commercial products, but any information or table of sunset sunrise in function of latitude

regards

koky
Logged
DarkClover
Active Member
***
Offline Offline

Posts: 167

Thank You
-Given: 37
-Receive: 60


Still alive...


« Reply #1 on: August 03, 2010, 04:35:52 16:35 »

Do you want to detect just sunrise and sunset to trigger your clock or calculate the
time out of the position of the sun ?
If it's the second one you need a very accurate sensor with a high resolution (many many photodiodes?)

Anyway you need a table of the sunrise and sunset times for this and the following years.
Here is a link: http://www.timeanddate.com/worldclock/sunrise.html

The digital part is easy, just use some real-time clock which will be set after the suns position or sunrise/sunset.

Logged

Not thinking means to believe what others say!
TRY & ERROR... the fundamental principle our existence is based on
koky
Active Member
***
Offline Offline

Posts: 181

Thank You
-Given: 154
-Receive: 157


WWW
« Reply #2 on: August 03, 2010, 05:44:42 17:44 »

my idea is a non precision clock for turn on or turn off a load at the  desidered hour, without need to program it or place a rtcc battery in bad climatic condition, thank for link, i think to work to a lenght of a day with simple photoresistor and try to make a table (for a relative zone) for syncronize the clock with sunrise
Logged
DarkClover
Active Member
***
Offline Offline

Posts: 167

Thank You
-Given: 37
-Receive: 60


Still alive...


« Reply #3 on: August 04, 2010, 01:38:48 13:38 »

Therefore you just need to detect sunrise and/or sunset. Maybe a combination of a Photodiode and some
FlipFlop (bistable multivibrator) and a relais would to the job easily.
With the photodiode and a voltage divider before the (ON)transistor you can set the time for SUNRISE
and maybe the same construction for (OFF)transistor and you can set the time for SUNSET.
I'm sure it will be quite accurate.
Logged

Not thinking means to believe what others say!
TRY & ERROR... the fundamental principle our existence is based on
gan_canny
Junior Member
**
Offline Offline

Posts: 89

Thank You
-Given: 101
-Receive: 26


« Reply #4 on: December 02, 2010, 11:30:53 23:30 »

The goal if I understand is to determine the date and time using daylight duration.
The calculation of sunrise and sunset for a specific latitude and longitude is basic mathematics below is some pascal code
function sunsetrise(slat:string;slong:string):string;
  var

month,day,year,zenith,n1,n2,n3,n,lnghour,ts,tr,lat,lon,Mr,Ms,Lr,ls,RAs,RAr,
 Lquadrants,RAquadrants,Lquadrantr,RAquadrantr,
 sindecs,cosdecs,sindecr,cosdecr,cosHs,cosHr,Hs,Hr,MTs,MTr,UTs,UTr,
 localOffset,localTr,localTs,d_r,r_d,

 d_m_y,temp_date,ds_start_date,ds_end_date:Tdatetime;
 wYear,wDay,WMonth: word;
 localTr_hr,localTs_hr,localTr_min,localTs_min:integer;
 ds_start_day, ds_end_day:integer;
 daylight_savings:boolean;
 sunrise,sunset:TdateTime;
 mystring:string;
begin
 ///////////////////////////////////////////////////////////////////////////
 //////////////////date input /////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
  d_m_y:=Now;
  DecodeDate(d_m_y,wYear, wMonth, wDay);
  Year:=wYear;
  Day:=wDay;
  Month:=wMonth;



 //// for 2007 daylight savings  clocks  forward 2am 2nd Sunday in march
////                        clocks fallback     2am 1st Sunday in november

/// find the dow of the 2nd Sun of March

   temp_date:=EncodeDate(wYear,3,1);
   ds_start_day:=DayofWeek(temp_date); /// dow of Ist of March
   /// calc the first sunday
   /// if dow of first of month is 1(Sun) we are done
   ///                             2(Mon) Ist sun is the 7th
   ///                             3(Tue)                6

   if ds_start_day>1 then ds_start_day:=9-ds_start_day;
   ds_start_day:=ds_start_day+7; /// 2nd sunday
   ds_start_date:=EncodeDate(wYear,3,ds_start_day);
   /// calc first Sunday
   temp_date:=EncodeDate(wYear,11,1);
   ds_end_day:=DayofWeek(temp_date); /// dow of Ist of March
   if ds_end_day>1 then ds_end_day:=9-ds_end_day;
   /// set daylight savings in effect flag
   ds_end_date:=EncodeDate(wYear,11,ds_end_day);
   if (d_m_y>=ds_start_date) and (d_m_y<ds_end_date)
         then daylight_savings:=true else  daylight_savings:=false;

  //////////////////////////////////////////////////////////////////////
  /////////////////////Lat lon input ///////////////////////
  lat:=strtofloat('26.90506' );
  lon:=strtofloat('-82.07817' ); ///// Punta Gorda

  lat:=strtofloat(slat );
  lon:=strtofloat(slong ); ///// Punta Gorda


 // lat:=40.9;
 // lon:=-74.3;
//  first calculate the day of the year

  n1:=floor(275*month/9);
  n2:=floor((month+9)/12);
  n3:=1+floor((year-4*Int(year/4)+2)/3);
  n:=n1-(n2*n3)+day-30;

//convert the longitude to hour value and calculate an approximate time

  d_r:=pi/180;  /// deg to radians
  r_d:=180/pi;  /// radians to degrees
  lngHour := lon / 15;

//   if rising time is desired:
      tr := N + ((6 - lngHour) / 24);
//   if setting time is desired:
      ts := N + ((18 - lngHour) / 24);
 //   calculate the Sun's mean anomaly

          Mr := (0.9856 * tr) - 3.289;
          Ms := (0.9856 * ts) - 3.289;
 //calculate the Sun's true longitude

   Lr := Mr + (1.916 * sin(Mr*d_r)) + (0.020 * sin(2 * Mr*d_r)) + 282.634 ;
        if Lr>360 then Lr:=Lr-360;
        if Lr<0 then Lr:=Lr+360;
        Ls := Ms + (1.916 * sin(Ms*d_r)) + (0.020 * sin(2 * Ms*d_r)) + 282.634 ;
        if Ls>360 then Ls:=Ls-360;
        if Ls<0 then Ls:=Ls+360;

//   NOTE: L potentially needs to be adjusted into the range [0,360)
//      by adding/subtracting 360

// calculate the Sun's right ascension

   RAs:= arctan(0.91764* tan(Ls*d_r))*r_d;
        RAr := arctan(0.91764* tan(Lr*d_r))*r_d;
//   NOTE: RA potentially needs to be adjusted into the range [0,360) by adding/subtracting

// right ascension value needs to be in the same quadrant as L

   Lquadrants  := (floor( Ls/90)) * 90 ;
   RAquadrants := (floor(RAs/90)) * 90 ;

   RAs := RAs + (Lquadrants - RAquadrants);

        Lquadrantr  := (floor( Lr/90)) * 90 ;
   RAquadrantr := (floor(RAr/90)) * 90 ;

   RAr := RAr + (Lquadrantr - RAquadrantr);
// right ascension value needs to be converted into hours

   RAs := RAs / 15;
        RAr := RAr / 15;
// calculate the Sun's declination

   sinDecr := 0.39782 * sin(Lr*d_r);
   cosDecr := cos(arcsin(sinDecr));
        sinDecs := 0.39782 * sin(Ls*d_r);
   cosDecs := cos(arcsin(sinDecs));

// calculate the Sun's local hour angle
      zenith:=90.83;
   cosHs := (cos(zenith*d_r) - (sinDecs * sin(lat*d_r))) / (cosDecs * cos(lat*d_r));
   cosHr := (cos(zenith*d_r) - (sinDecr * sin(lat*d_r))) / (cosDecr * cos(lat*d_r));
     //   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)

     //  finish calculating H and convert into hours

   //    if rising time is desired:
        Hr:= 360 - arccos(cosHr)*r_d;
   //   if setting time is desired:
        Hs := arccos(cosHs)*r_d;

   Hr := Hr / 15 ;
        Hs := Hs / 15;
//   calculate local mean time of rising/setting

   MTr := Hr + RAr - (0.06571 * tr) - 6.622 ;
        MTs := Hs + RAs - (0.06571 * ts) - 6.622 ;
// adjust back to UTC

   UTr := MTr - lngHour ;
        if UTr<0 then UTr:=UTr+24;
        if UTr>24 then UTr:=UTr-24;

         UTs := MTs - lngHour ;
        if UTs<0 then UTs:=UTs+24;
        if UTs>24 then UTs:=UTs-24;

 //   NOTE: UT potentially needs to be adjusted into the range [0,24)
 //      by adding/subtracting 24

 //convert UT value to local time zone of latitude/longitude

         if daylight_savings then localOffset:=-4 else  localOffset:=-5;
   localTs := UTs + localOffset;
        if localTs <0 then localTs :=localTs +24;
        if localTs >24 then localTs :=localTs -24;
        localTs_hr:=Trunc(localTs);
        localTs_min:=Trunc((localTs-localTs_hr)*60 );
         localTs_hr:=localTs_hr-12;
        localTr := UTr + localOffset;
        if localTr <0 then localTr :=localTr +24;
        if localTr >24 then localTr :=localTr -24;
         localTr_hr:=Trunc(localTr);
        localTr_min:=Trunc((localTr-localTr_hr)*60 );
          if daylight_savings then mystring:='Daylight savings in effect GMT -4hr'
                              else  mystring:='Standard Time GMT -5hr';
        sunrise:=EncodeTime( localTr_hr, localTr_min,0,0);
        sunset:=EncodeTime( localTs_hr, localTs_min,0,0);

         mystring:=mystring+' Sunrise at '+ FormatDateTime('hh:nn "AM"',sunrise)+'   '+
                 'Sunset  at '+FormatDateTime('hh:nn "PM"',sunset);
     result:=mystring;
end;
I implemented this in a PIC that controls timed switches. Now the PIC is not good for high precision floating point so the the sunrise and sunset times for a set location were stored in a table . The PIC kept the  time via its xtal and a timer interrupt
that was converted to hours mins and seconds. The pic timer would drift from true UT time and was corrected via photo detection of night time duration. Night time is better since clouds don't effect the timing.
Oh by the way this won't work if there is no sunset or sunrise like in northern Alaska.
The position of the sun using sensors has issues since the earth's orbit is elliptical and the velocity of the earth varies throughout the year this affects the transit of the sun across the sky. Our time is based on the mean sun not the transit position.                    
« Last Edit: December 02, 2010, 11:42:45 23:42 by gan_canny » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #5 on: December 04, 2010, 10:50:57 10:50 »

I implemented this in a PIC that controls timed switches...

That is interesting, would you describe the achievable accuracy?

-ichan
Logged

There is Gray, not only Black or White.
gan_canny
Junior Member
**
Offline Offline

Posts: 89

Thank You
-Given: 101
-Receive: 26


« Reply #6 on: December 08, 2010, 08:06:28 20:06 »

It's not that accurate. The length of the day or night varies by small amounts from day to day. It can detect a drift of an internal clock should it drift 15 mins or more. A good xtal will  drift a few minutes over a year but an internal RC osc can drift much more or even a xtal if outdoors and subject to temperature swings will drift much more. Day length measurement can detect the  15min drift but can't reset the time that accurately. A cheap 32768 watch xtal works better than a drifting xtal with solar day correction.
The sunset sunrise table wasn't a total waste since it was used in another project to turn a switch on/off so many hrs min after sunset and off so many hrs and mins before dawn without the use of a photo cell but with the use of a 32768 xtal to get about a 3min drift per year.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC