95 posts / 0 new

## Pages

Author
Message

Consider a scenario in which I have indicate time for sunset and sunrise.
For 365 days ..some days may have same time
But variation is more...I have info about timings
But to include all days it's a huge problem

Salman

Last Edited: Sat. Mar 25, 2017 - 02:26 PM

Why is it a "huge problem" ? There are only 1,440 minutes in a day so you could easily hold a sunset or sunrise time in a precalculated lookup table using 2 bytes per entry. Each day has a sunset and a sunrise time. So 4 bytes per day. There are 365 days in the year so a table of 1,460 bytes could hold all you need. You can fit that into all but the smallest of AVRs.

For example if I know the sun rises at 07:38 and sets at 09:23 then sunrise is at the 458th minute of the day and sunset is at the 1,283rd minute of the day. So:

```typedef {
uint16_t rise_time;
uint16_t set_time;
} day_info_t;

day_info_t times[] = {
...
{ 458, 1283 ), // this particular example day
...
};

if ((time_in_mins > times[N].rise_time) && (time_in_mins < times[N].set_time)) {
// the sun is shining!!
}```

For a given day of the year, official sunrise and sunset depends on quite a few things. One really big factor is latitude (where you are north or south of the equator). Another factor is longitude but more precisely, where you are within the time zone. If you are in a standard 15 degree time zone (which most of US and Canada use), then there is an hour difference in sunrise and sunset times at the east edge of the time zone vs the west edge. I believe that some of the time.h libraries include sunrise and sunset computation but I don't know the details.

By the way, it IS possible to compute sunrise and sunset times at a given latitude and longitude. It is messy but it is computable.  Simply Google: compute sunrise sunset times

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

ka7ehk wrote:
.  Simply Google: compute sunrise sunset times

See #3.

But, for some reason, the OP doesn't seem to do Google.

Lesse -- figure out what time noon is.  Easy, right?  Then add/subtract half of the day length.  ;)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Lol

Salman

Not so easy. "Noon" is defined by civil authorities (witness "Daylight Savings Time"); it may not be half-way between sunrise and sunset. Ditto standard 15 degree time zones - it is only approximately true at the center of the time zone; there can be up to 30 minute error at the edges of the time zone.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Now, do you want Nautical, Civil, or Astronomical?  Or actual?  And if "Actual" won't it vary in a particular spot depending on terrain?

Civil Twilight
Civil twilight is defined when the sun is 6 degrees below the horizon. In the morning this is known as dawn, in the evening it is called dusk. This is the limit at which twilight illumination is sufficient, under good weather conditions, for terrestrial objects to be clearly distinguished; at the beginning of morning civil twilight, or end of evening civil twilight, the horizon is clearly defined and the brightest stars are visible under good atmospheric conditions in the absence of moonlight or other illumination. In the morning before the beginning of civil twilight and in the evening after the end of civil twilight, artificial illumination is normally required to carry on ordinary outdoor activities.

Nautical Twilight
Nautical twilight is defined when the sun is 12 degrees below the horizon. At the beginning or end of nautical twilight, under good atmospheric conditions and in the absence of other illumination, general outlines of ground objects may be distinguishable, but detailed outdoor operations are not possible, and the horizon is indistinct.

Astronomical Twilight
Astronomical twilight is defined when the sun is 18 degrees below the horizon. Before the beginning of astronomical twilight in the morning and after the end of astronomical twilight in the evening the sun does not contribute to sky illumination; for a considerable interval after the beginning of morning twilight and before the end of evening twilight, sky illumination is so faint that it is practically imperceptible.

http://www.sunrisesunset.com/faq...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Mar 16, 2017 - 05:50 PM

theusch wrote:
Now, do you want Nautical, Civil, or Astronomical?  Or actual?

I suspect "religious" (liturgical/ritual) may be another option ...

awneil wrote:
I suspect "religious" (liturgical/ritual) may be another option ...

I thought that also.  Thus, OP might have to adjust a "perfect" e.g. Astronomical solution to the needs.

Cliff suggested earlier storing all the info.  For whatever need, I'd think the tables of acceptable values for each year would be published and could be updates -- if the user remains in place.  If for e.g. a traveling salesman then you are into a "real" device with a GPS for location and more sophisticated calculation.  (I seem to recall such in lists of cell phone apps)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

salmanma6 wrote:
Consider a scenario in which I have indicate time for sunset and sunrise. For 365 days ..some days may have same time But variation is more...I have info about timings But to include all days it's a huge problem

How many years do you want/need this to be valid for ?

What errors can you tolerate ?

What precision do you need ?

How do you indicate the result ? (Given there is already a visual indicator provided to this problem...)

That will determine the size of table you need, and if you need to pull in daylight savings and timezones etc....

You will, at the very least, need a clock (aka Real Time Clock, RTC, and such) with modest accuracy. A watch crystal should be able to give you 30 ppm, more or less, depending on the temperature range and initial "calibration". 30ppm is equivalent to 2.5 seconds per day. That does not sound like much, but over a year, it can accumulate up to about 15 minutes of error, usually lagging (that is, RTC clock time is about 15 minutes behind a precision clock).  An ordinary "microprocessor crystal" can be several hundred parts per million off (say, 25 seconds per day, in round numbers).

So, an important question is: how much error can you tolerate?

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

ka7ehk wrote:
You will, at the very least, need a clock

Or a connection to some "time reference"; eg,

• Internet
• GPS

Go on.   I am sure that most of us have managed our lives fairly well with occasional timechecks from a clock, radio, TV, ...

Our forefathers managed pretty well by just looking at the sky.

I would just calculate the sunrise, sunset from the geographic location and day of the year.

Surely 15 minute resolution is accurate enough for real life.    You can calculate it to 1 minute accuracy if it gives you extra nerd points.

Worrying about long term accuracy of your RTC is only necessary if you are away from all civilisation for months or years at a time.

David.

david.prentice wrote:
Our forefathers managed pretty well by just looking at the sky.

But the "chips" were bigger in the old days...

EDIT: A short documentary on the construction: https://www.youtube.com/watch?v=... (1st 3 minutes)

Last Edited: Thu. Mar 16, 2017 - 10:51 PM

Our forefathers tended to stay in the same geographic location.    Imagine carrying Stonehenge in your backpack when you go on holiday.

David.

It was the railways the forced the standardisation of time across the country

Imagine carrying Stonehenge in your backpack

As the man said, "A calendar? That's  going to look pretty silly on your desk!"

Likewise in the US, the railroads drove time standardization. Often, there would be many local times, even within a state. There were loud howls, just as there often are when we change to/from Daylight Saving Time, about how the milk cows get all upset with the time changes (!).

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

I have a feeling it's a simple sine function, but I expect I'm wrong.

Quebracho seems to be the hardest wood.

Milking cows don't mind too much.   Especially if you do 30 minutes one day and 30 minutes the next day.

Oh,  and that only works if it does not interfere with Milk Tanker collection times.

David.

John_A_Brown wrote:

I have a feeling it's a simple sine function, but I expect I'm wrong.

Sines will be in there somewhere, but the final solar result is a little more complex.

Here is the effect of 12 months on a fixed (noon) snapshot of the sun :

https://en.wikipedia.org/wiki/An...

awneil wrote:

ka7ehk wrote:
You will, at the very least, need a clock

Or a connection to some "time reference"; eg,

• Internet
• GPS

I'm impressed by the falling prices (GPS volumes driven?) of the TCXOs in the 0.5ppm region.

Now well under \$1 in modest volumes.

eg TG2016SBN 16.3840M-TCGNBM3  lists at \$1.23 1+ and 81c/250,  runs on just 1.4mA and specs 500ppb, and all this in a 2.00mm x 1.60mm package

Who-me wrote:

John_A_Brown wrote:

I have a feeling it's a simple sine function, but I expect I'm wrong.

Sines will be in there somewhere, but the final solar result is a little more complex.

Here is the effect of 12 months on a fixed (noon) snapshot of the sun :

https://en.wikipedia.org/wiki/An...

Hmmm. That's way more complicated than I thought. I guess I forgot about the earth's eccentric orbit, for one thing.

How did anyone know this stuff before Wikipedia?

Quebracho seems to be the hardest wood.

What accuracy would you need?

Calculating precise values is quite a nuisanse but a small table (one entry for each month or week, or for each week) and then interpolate linearly (or some curve fitting) will get you pretty close.

When you make use of (almost) symmetry you can get away with a 3 month table.

Do you need corrections for "daylight saving time?"

https://duckduckgo.com/html?q=%2...

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

I have the timings of sunrise and sunset on sheet.for every day...I don't want calculation...
I just wanna display on to 7 segment displays
4 7 sgd for sunrise
4 7 sgd for sunset
Iam looking for solution for storing 365*2*2bytes
That's easy..but ..
Gathering data from table according to date,month
Big code..may occupy max of flash
Here I'm using mega16

Salman

I want best precision possible

Salman

Last Edited: Fri. Mar 17, 2017 - 11:26 AM

I want best precision...I need solution for this error lag

Salman

Can we do it?...
How?

Salman

Doesn't the internet time lag?
Yeah I know
It will use code
But code again has connection to chips or some crystals...
Just telling...I don't know whether its wrong or right

Salman

Salman,

The national governments of the world (well the developed ones) coordinate their clocks via facilities that use atomic clocks. They do this for scientific reasons as well as simple coordination of things like train timetables.

There are publicly available services that can synchronise your PC to these atomic clocks. As mentioned above, you can use GPS modules to do this in the privacy of your home.

Visit http://www.time.gov/

... as one example of internet time.

Ross

Ross McKenzie ValuSoft Melbourne Australia

Hmm cool...how do u drag that time from internet?

Salman

Well I have a little utility program that "reaches" out to one of the time sites, gets the correct time and then resets my PC's clock... within a fraction of a second. I don't do it often because there is nothing in my world that requires that accuracy... as long as I know what day it is and don't miss the evening news I am happy.

Ross McKenzie ValuSoft Melbourne Australia

Using avr

Salman

clawson wrote:
/////////////// code/////////////

Where do u get this time in minutes? In code u wrote

Salman

Last Edited: Sat. Mar 18, 2017 - 05:31 PM

Using an AVR, I  would use one of many simple, relatively cheap GPS modules and parse the NMEA serial string which includes location and time information to the second. No need for an internet connection. There are probably 100s of examples on the web.

http://www.ebay.com.au/itm/1Pcs-...

Ross McKenzie ValuSoft Melbourne Australia

GPS itself won't tell you timezone or daylight-saving ...

And surely the OP has to contribute something to the project... a location based offset.

Ross McKenzie ValuSoft Melbourne Australia

awneil wrote:
GPS itself won't tell you timezone or daylight-saving ...

My Garmin automotive GPS seems to know about such things.  But I certainly don't know the details.  Perhaps the software in the Garmin has tables and such like the OP needs.  My cheapo LaCrosse "atomic clock" seems to figure out summer time, but the time zone needs to be set.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Time zone is constant in case

Salman

I
What's the logic for getting time from module

Salman

awneil wrote:
GPS itself won't tell you timezone or daylight-saving ...
UK MSF does for a form of DST :

National Physical Laboratory

Science + Technology

Time & Frequency

Products & Services

Time

...

• British Summer Time (in effect or imminent)

...

One could hack a locally sourced clock for terrestrial radio time.

There are a few manufacturers of long wave radio time receiver IC.

Intermittent reception is acceptable because radio time sync can be used to correct MCU time.

I've forgotten when long wave radio time reception is reliable (night?  day?)

There may be a time signal within FM digital audio broadcasting (DAB)

For CONUS :

Quartex® Atomic Clock Movement

https://www.klockit.com/quartexr-atomic-clock-movement.html

"Dare to be naïve." - Buckminster Fuller

salmanma6 wrote:
I want best precision...

That is a nonsense and vague statement. Give an actual number.

'best precision' can be below 1us, but you lack the displays to show that, so clearly 'want best precision' is not valid.

salmanma6 wrote:
...I need solution for this error lag

Another vague statement - what error lag??

salmanma6 wrote:
I have the timings of sunrise and sunset on sheet.for every day...I don't want calculation... I just wanna display on to 7 segment displays 4 7 sgd for sunrise 4 7 sgd for sunset Iam looking for solution for storing 365*2*2bytes That's easy..but .. Gathering data from table according to date,month Need to think about it... Big code..may occupy max of flash Here I'm using mega16

Yes, you do need to think about it, as there is no need for 'Big code..may occupy max of flash'

Do you want to display hh:mm ? in that case 1 minute precision is all you show.

The TCXO info I gave above, is good enough for that level, once sync'd.

With 1 minute LSB, you can store +/- 127 minutes in one byte, so most table entries can be one byte

You could even store +/-12.7 minutes, and fully delta,  to have a 0.1 minute LSB, and this link shows the day to day change

Most places on earth can display in 4 digit LED as H:mm.f  with an am/pm led.

https://maas.museum/observations...

That's 1 min quantized, the curve just gets smoother with 0.1 min quantized.

With a delta-store approach, you simply sum over the length of the table, up to the current day from base.

Code is very simple, and the sum time is not an issue for something that changes once a day :)

You might even want to deliberately slow it down, so the user can watch a departure-sign like update, get some cute points.

If you are ok with 1 min, (eg a 24 hr HH:mm clock) then a nibble can store +/-8 mins allowing the table to shrink to 365 bytes.

The maths can run clock-BCD, for even more code-simplicity.

If I was marking this homework, I might give an A+ for a design that came in under (say) 1K bytes.

If this is for lifetime, then you must take leap years into account. You should not have to deal with the skipping of a leap year  in year 2200. You need to understand that leap years are needed to correct for the fact that one solar year is off from 365 days. That means the there will be an accumulating error every year until it is compensated for every 4 years. You can certainly correct your table for this - its not hard - but you need to understand why and how to do it.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Fri. Mar 17, 2017 - 09:31 PM

Time has always been one of my favorite subjects.  Years ago I got a book titled Celestial Basic by Eric Burgess 1982 ISBN 0-89588-087-3.  Somewhere I recently found a PDF copy as this is an older textbook written for Apple ][ basic.

Program 15 is called RISES and presents the time of Rising Transit and setting of Planets, Sun and moon for any date.

The program uses sidereal time, which Astronomers use as it traces one complete revolution of the earth against a star appearing in the same place.  (these are called clock stars and why a meridian such as Greenwich or Paris is used for time 0. )

Sidereal time is different by 3 minutes 56.55 seconds as the earth is moving in the annual orbit of the sun while turning on it's axis.

The 1980s program uses the formula SiderialRiseTime = RA-(1/15)*arccos(tan(lat)*tan(dec)  and SiderialSetTime = RA+(1/15)*arccos(tan(lat)*tan(dec).  .   Objects in the sky are represented by two numbers Right Ascension and Declination that represent the spherical coordinates of the object in question (such as the sun on a given date.)

It still amazes me that  these 6502 computers ran at 1 Mhz and used software floating point could do this and generate software NTSC video too.

Note that all of the common use measurements reflect mean time.  The mean year is actually closer to 365.2425  which is why some years leap and some centuries do not.  2000 leaped because it divided by 400.  2100 will not leap and 1900 did not leap. 2400 will be the next leap century.  Some optimistic clockmakers also created clocks that leap 4000 years.

If one could find a 4.205788 crystal (supposedly off the shelf, but Mouser and Digikey do not stock and a crystal maker did not have either) then the crystal in a quartz wall clock could be swapped to create a sidereal clock.   Supposedly there are astronomical clock suppliers that sell this, but I have never found such crystals on the open market.  All the search hits refer back to the same paper by Alan A. Mills.  His Leicester clock is quite interesting as it emulates the old medieval mechanical clocks using windshield wiper motors.   By gearing together the sun and sidereal times one can predict the rising and setting times for a given latitude.  It is quite impressive.  From the wikipedia page:

What is interesting about this is the same display is used on the 2000+ year old Greek  Antikeythera device.   and uses an identical moon phase mechanism.  These devices evolved into the portable sundial called an astrolabe.  I once wrote a postscript program to plot an astrolabe dial for any latitude.

To do what the OP wanted the old clockmakers worked out a cam which is shaped like a Kidney.  Modern expensive astronomical watches also have this cam.  It maps the difference between the local time on a sundial and the time on a mechanical clock dial.  There is a clock in the pump house in bath that has this hand, and a sundial outside a window, so skeptics could see how accurate it is.  This clock has been running over 200 years.

Time, distance and probably gravity are the same thing.   Time is measured by the vibrations of hydrogen atoms (Hydrogen mazer)  Used to be Cesium.  These are called atomic clocks.  The meter was back projected to represent the distance light travels over a given number of atomic vibrations.  Atomic clocks in GPS satellites keep different time than clocks on the ground.  Even time in a valley is different that time on a high mountain.   All these relativistic effects have to be programmed into modern devices.

I think it was Einstein, who said  "Time is the quantity easiest to measure and hardest to define,  Temperature is easy to define and hard to measure."

Last Edited: Sat. Mar 18, 2017 - 05:30 AM

I did something similar over 25 years ago - in HC11 assembler. If my memory serves me correctly, I precomputed the tables and added an offset for the timezone.

Who-me wrote:

salmanma6 wrote:
I want best precision...

i

Who-me wrote:
That is a nonsense and vague statement. Give an actual number.

i dont know the maximum precision that one can achieve...so i said best precision

who-me wrote:
but you lack the displays to show that,

didnt get you...

salmanma6 wrote:
...I need solution for this error lag

who-me wrote:
Another vague statement - what error lag??

gain or loss in sec or min?

salmanma6 wrote:
I have the timings of sunrise and sunset on sheet.for every day...I don't want calculation... I just wanna display on to 7 segment displays 4 7 sgd for sunrise 4 7 sgd for sunset Iam looking for solution for storing 365*2*2bytes That's easy..but .. Gathering data from table according to date,month Need to think about it... Big code..may occupy max of flash Here I'm using mega16

who-me wrote:
Yes, you do need to think about it, as there is no need for 'Big code..may occupy max of flash'

Do you want to display hh:mm ? in that case 1 minute precision is all you show.

The TCXO info I gave above, is good enough for that level, once sync'd.

Didnt get this too

Salman

Last Edited: Sat. Mar 18, 2017 - 05:19 PM

So you all recommend me to use gps module?//Since derived from atomic clocks

another thing ...do this atomic clocks have some errors..>?i.e...gain or loss time?

Salman

awneil wrote:

GPS itself won't tell you timezone or daylight-saving ...

gps will give string which has longitude and latitude of area where the module is present ..am i right?

secondly does it provide time according to longitude and latitude ...or just derive it from atomic clocks

......?

Salman

valusoft wrote:

And surely the OP has to contribute something to the project... a location based offset.

how do i do it?

Salman

You need to learn that numbers matter, and how to ask a better question.

salmanma6 wrote:
i dont know the maximum precision that one can achieve...so i said best precision

Then you should ask that you desire to know 'the maximum precision that one can achieve', which has already been mentioned above, in the microsecond, or sub microsecond region.

who-me wrote:

but you lack the displays to show that,

didnt get you...

Given the best possible is HH:MM:SS:ffffff, have you thought how you will display that on your 4 digit LED

This is why the displays you will use matter, there is no point in worrying about, or chasing, digits no one can see.

salmanma6 wrote:

gain or loss in sec or min?

Still vague, your display is going to be in what units ? HH:MM ?

A TXCO precision was mentioned of +/- 500 parts per billion. (0.5 e-6) Did you calculate how long before that is visible on the display LSB.

Keep in mind that GPS can only give precise times, when they are locked.

Where will this be used ?   Who is the end customer - just yourself ?

Will it be inside a building ? - you may not be able to ensure GPS lock.

What is your parts budget ?