Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1] 2 3 ... 6

Author Topic: New project, A Clock  (Read 6346 times)

sevenlayermuddle

  • Helpful
  • Addicted Kitizen
  • *
  • Posts: 5369
New project, A Clock
« on: November 17, 2020, 08:33:42 AM »

I am interested in any encouragement or otherwise, relating to a device I’m thinking of actually constructing.

It would consist of a photocell, a microcontroller, and an LCD  character display.   All of these are conveniently to hand, residing in a drawer labelled “bits & bobs”

Placed on a window ledge, the photocell would monitor sunrise and sunset events.  Based on the assumption that midday is halfway between these events the LCD would show a self-calibrating clock, tailored to my own personal time zone.   My gut feeling is that, by taking a long term rolling average, it might become reasonably consistent.

Longer term, it would eventually notice the shortest/longest days of the year, and so make a guess at date as well as time.  Averaged over enough years, this too might become increasingly accurate.

If I can figure out the maths it might even be able to tell my latitude, based on crunching the data from longest/shortest days.   In that case I might even enhance it to have access to GMT, as the offset would allow full location.

Questions:

Is there any obvious reason why it would not work?

Even after settling to a long term average, would it always show a constant offset from GMT, or would that vary with the date (gut feeling says so)?

Am I reinventing the wheel, are such devices already cheap and easily available?

« Last Edit: November 17, 2020, 08:36:47 AM by sevenlayermuddle »
Logged

Chunkers

  • Reg Member
  • ***
  • Posts: 525
  • Brick Wall head-banger
Re: New project, A Clock
« Reply #1 on: November 17, 2020, 02:27:58 PM »

Cool idea, personally I always wanted to make a nixie clock, they are super cool

C
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: New project, A Clock
« Reply #2 on: November 17, 2020, 02:56:19 PM »

An excellent idea. `the longitude time zone offset would vary sinusoidally throughout the year, as the earth’s inclined rotational axis ‘rotates’ through the year from the viewpoint of the plane of the earth’s orbit compared with the position vector pointing to the sun. What ever processor you use, make sure that is has floating point and maths libraries for sin/cos/sqrt etc. You’ll need to do some trig possibly. The sunrise sunset thing is a really good idea. The clock won’t know it’s longitude and so it won’t know what the offset from GMT is, you’d have to configure it with the longitude somehow; could hardcode it in but you might not want to do that in case you ever move the clock or make additional ones.

I’m at latitude/longitude: 57.470456, -5.401124 according to https://www.doogal.co.uk/LatLong.php which seems a nice tool. So 5.4 degrees west is what time difference now? Will have to do the trig based on the time of year.

Here’s yet another unsolicited and irrelevant plug for my personal love affair: https://dlang.org which might help you on your journey (or delay you as you dive in). Anyway might be found very stimulating.

Will the interface to your photocell be an ADC? Or will it be a two-state on/off affair? I’m wondering about heavy clouds at sunset and dawn injecting noise into your calculations by delaying the times of sunset/sunrise, but the noise should level out to a constant positive error for both ?

I and others could try and help with the maths, although 40 years is a long time.
« Last Edit: November 17, 2020, 03:08:36 PM by Weaver »
Logged

jelv

  • Helpful
  • Kitizen
  • *
  • Posts: 2054
Re: New project, A Clock
« Reply #3 on: November 17, 2020, 04:11:46 PM »

the photocell would monitor sunrise and sunset events.  Based on the assumption that midday is halfway between these events

Your idea fails at the first hurdle!

London today: Sunrise 07:22, sunset 16:07 (see https://www.timeanddate.com/sun/)

If you could persuade all the relevant authorities to make the earths orbit around the sun circular would be a start to your project.
« Last Edit: November 17, 2020, 04:15:32 PM by jelv »
Logged
Broadband and Line rental: Zen Unlimited Fibre 2, Mobile: Vodaphone
Router: Fritz!Box 7530

sevenlayermuddle

  • Helpful
  • Addicted Kitizen
  • *
  • Posts: 5369
Re: New project, A Clock
« Reply #4 on: November 17, 2020, 04:15:48 PM »

Thanks for the encouragement guys, I'm on the case. 

What ever processor you use, make sure that is has floating point and maths libraries for sin/cos/sqrt etc.

Damn, I thought somebody might say that.  I'm using a Microchip PIC, because I am familiar with them and have the dev tools, but I'd hoped to do it all in assembly simply because I enjoy it and the software is free.  Microchip do offer a C Compiler, but there's licensed version and a (crippled) free version, not sure what exactly gets crippled.  I'll need to find out if the free C compiler is up to the job....

Another problem with heavy maths libraries and high level languages might be the limited memory, the PIC I am playing with right now has just 512 bytes of RAM, and 7k bytes of program memory (Harvard architecture).  I suppose as a last resort I could use a Pi or something, but I'd rather not.

Alternatively, I wonder if I could write a desktop App that provides the necessary maths, in the form of machine-written assembly lookup tables?

Re the sensor, I plan t use an LED as a photodiode simply because I haven't got any actual sensors to hand, but  I have bags and bags of LEDs, looking for a purpose in life.   Some PICs have on-chip operational amplifiers which offer a nice way, of interfacing to a photodiode(/LED), converting the photo current into a useful voltage scale.  They also have ADCs, so you end up with a numeric representation of ambience.   I can then play around with finding the right thresholds, add software filtering to ignore the odd cloud, etc.    I've made all that work before, sensing ambience with LED and PIC, different project.

I also been thinking that, as an alternative to waiting for shortest/longest day, I ought to be able to make deductions about latitude based on rate of change of lighting levels combined with current hours of sunshine?  Can't get my head around that - maybe I never will get my head around it, maybe I'm talking drivel, but it's on the "ideas" list.  :D

Cool idea, personally I always wanted to make a nixie clock, they are super cool

That would be cool indeed.  But for convenience of being portable to different window cills, I want my clock to self-contained and battery operated.  It'll probably be about somewhere between cigarette box and paperback book in size.  Getting a battery to drive Nixie tubes in such a portable device, to run uninterrupted for years or more, would be a whole different challenge.  Next project, maybe? :-\

Your idea fails at the first hurdle!

London today: Sunrise 07:22, sunset 16:07 (see https://www.timeanddate.com/sun/)

If you could persuade all the relevant authorities to make the earths orbit around the sun circular would be a start to your project.

Thanks for the tip.  If it simplifies the maths, I'll start writing the letters requesting the changes.   :D


I'll keep the thread up to date.   This all came about after I purchased the LCD displays, simply because they looked cute and were cheap. Having wired up an LCD to a PIC and got it to display "Hello World", my next challenge was to justify the cost and time I'd spent, by thinking of a problem that they might solve.   Combined with my previous application of a PIC involving an ambient lighting sensor, the clock sprang to mind. ::)
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: New project, A Clock
« Reply #5 on: November 17, 2020, 04:28:25 PM »

I really wouldn’t use a PIC; you really need floating point and multiplication and division, although sin/cos/tan could be done with lookup tables they would eat up your ROM. And writing a ton of maths in asm isn’t very stimulating - it’s what C or D is meant for.

Thankfully someone has done all the maths for us: https://en.wikipedia.org/wiki/Sunrise_equation
Logged

sevenlayermuddle

  • Helpful
  • Addicted Kitizen
  • *
  • Posts: 5369
Re: New project, A Clock
« Reply #6 on: November 17, 2020, 05:09:26 PM »

You’ll have a job talking me out of the PIC, simply because I know them reasonably well.  I also have drawers bursting with them, in various shapes and sizes.

Last PIC project required 32 bit multiply and divide that I wrote myself, which was fun, but I’d not expect any awards for it.  There’s also a few more advanced maths sources floating around written by people orders of magnitude smarter than I am.   Microchip even publish some of it in their application notes.  But whether it has the required resolutions might be a big question...

A plus side of using a PIC is they can be configured to run on the tiniest of currents, yielding a sensible battery life.  A good few years on two ‘C’ cells might be achievable, according to some earlier scribblings I composed.   Running on a slow clock (say, 32kHz) is part of the trick for low power but for this device, it doesn’t have to be fast - it can spend all day doing the maths if it wants, as long as it’s done by the time it needs done again, next morning.

Of course, if I can get power consumption low enough there is also the option of being solar powered, maybe even on cloudy days, topping up batteries by day enough to see it through the night.  The solar cell itself would then double as the light sensor, which makes that an appealing option.
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: New project, A Clock
« Reply #7 on: November 17, 2020, 05:14:39 PM »

If you know it well, then stick to it; I just meant that the code will be a bit boring, just a load of subroutine calls to maths library routines. I love writing assembler myself, but have to accept that nowadays on modern machine it has its place only in limited niches and it can’t be automatically optimised according to call site as modern C and D compilers can do.

I would have a problem here; I would need to correct for my altitude for very high precision results and can’t correct for the height of the mainland mountains to the east and the mountain Beinn nan Càrn to the west above the house; both delay sunrise and sunset by unpredictable amounts depending on how far south the angle to the rising sun is because of the changing height following the profile of the mountain(s).
« Last Edit: November 17, 2020, 05:17:50 PM by Weaver »
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: New project, A Clock
« Reply #8 on: November 17, 2020, 05:26:13 PM »

Why a slow clock; doesn’t it have a sleep state? If it’s static internally then it can just do the work and then go to sleep until a timer or other event wakes it up. That’s how the Psion Organiser worked, which I worked on, had an 8 bit CMOS static Hitachi 6301 microcontroller (an enhanced 6801) with a clock that went to DC when it had no work to do and 0.92 MHz otherwise; it had a battery life of months. It had two sleep states, d.c. clock sleep and an ‘off’ which was waiting for a timer interrupt (or the ‘on’ button) to start the processor up.
Logged

sevenlayermuddle

  • Helpful
  • Addicted Kitizen
  • *
  • Posts: 5369
Re: New project, A Clock
« Reply #9 on: November 17, 2020, 06:56:49 PM »

The trouble with sleeping is, you have to wake up again and that may involve extra hardware, to raise the wakeup event.    I’ve found that dynamically changing the oscillator frequency, slowing it right down instead of actually sleeping, is nearly as effective.

That said, you are probably right.    I probably want extra hardware anyway in the form of a crystal-based external oscillator.    These PICs have the option of internal oscillators which are factory calibrated, but still miles away from a proper crystal for accurate timekeeping.   I think - need to confirm - there’s options that would then allow me to sleep for exact  periods, leaving one of the internal clocks running with whilst asleep.

It won’t be sleeping for long periods as it’ll need to wake up once a second to update the hh:mm:ss on the display, but if it can sleep for 990mS out of every 1000mS, that is still obviously worthwhile.

I’m sulking right now because my “Hello World” has stopped working, and I’m darned if I can see what I did to break it.  Reverting to yesterday’s source code works, but today’s does not, the screen just stays blank, yielding no clues.   Yet  single stepping with debugger seems to show all the expected register transitions. It’s a bug and I’ll find it but I do concede that, at times like this my ‘bug’, whatever it is, would probably be a lot easier to spot if I were working in C.  >:(
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: New project, A Clock
« Reply #10 on: November 17, 2020, 07:15:05 PM »

That HD6301 had all the necessary hardware inside it to go to sleep and get woken up regularly; there was an (external iirc) counter that kept time while the machine was in a light sleep with clock at d.c., and when this overflowed then it would wake the processor and software would add n secs to a time variable in static RAM. In fact when that machine was off it woke up every so many seconds, and on the early models you could hear a faint click and maybe even see the display flicker when it came on, updated the time in software and then went straight back to sleep again. But many months battery life was not uncommon; later machines could only last ten hours or so (on two medium-sized NiCads).

Solar-powered would be really cool.
Logged

sevenlayermuddle

  • Helpful
  • Addicted Kitizen
  • *
  • Posts: 5369
Re: New project, A Clock
« Reply #11 on: November 18, 2020, 11:54:23 AM »

Using the LCD displays I purchased, with the PIC asleep and LCD displaying "Hello world", the overall contraption is getting by on just under 200µA.  An alkaline AA can supply something like 2500mAh before dropping to 1V or so, so that would predict a useful battery life of ~500 days or so.   These figures will change, as I'll probably use a boost converter for stable voltage, in which case a single 'C' cell might make more sense.   But implication is that battery life won't be a show stopper - should be years, not weeks.

Bad news is this morning... RIP, prototype LCD number 1,  I have just managed to kill it. :'(

Owing to a software bug, in an attempted sleep condition, I was driving the interface bus from the PIC whilst also setting the R/W signal so the LCD was driving the bus too.  This creates a fight between the PIC and the LCD with a theoretical risk of damage to one or the other part  which in this case seems to have instantly become a reality.    :-[

While I'm very sad for the loss of that LCD, in time, I will probably get over it. It cost only £2 or £3 or so, and I've a few more.  But worried now about how many more I might accidentally destroy if they're that darned fragile.   Might be worth putting some resistors on the bus, but there's nothing to document what the actual current limits need to be.  I'm beginning to remember why I chose a career in software, rather than hardware.   :blush:
Logged

tickmike

  • Kitizen
  • ****
  • Posts: 3640
  • Yes Another Penguin !. :)
Re: New project, A Clock
« Reply #12 on: November 18, 2020, 08:46:07 PM »

An interesting project to keep the brain active, good luck. :)
Logged
I have a set of 6 fixed IP's From  Eclipse  isp.BT ADSL2(G992.3) line>HG612 as a Modem, Bridge, WAN Not Bound to LAN1 or 2 + Also have FTTP (G.984) No One isp Fixed IP >Dual WAN pfSense (Hardware Firewall and routing).> Two WAN's, Ethernet LAN, DMZ LAN, Zyxel GS1100-24 Switch.

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: New project, A Clock
« Reply #13 on: November 18, 2020, 09:18:44 PM »

Indeed, a superb project.
Logged

sevenlayermuddle

  • Helpful
  • Addicted Kitizen
  • *
  • Posts: 5369
Re: New project, A Clock
« Reply #14 on: November 18, 2020, 11:20:04 PM »

An interesting project to keep the brain active, good luck. :)

Don’t raise your hopes re my brain activity, it might take more than this to yield any improvement, but thanks for encouragement.

Recent email order confirmations suggest that the nice man who drives the Parcelforce van might, tomorrow, be bringing me the remaining bits I need to make a ‘proof of concept’ first cut that can be left running undisturbed for a few days.  It won’t do any geolocation stuff, but will simply try to tell me the time, or at least, tell me a time.

There is likely to be a lapse of updates while I implement that.  Pressure from elsewhere suggests I may have other priorities too, like clearing up a small mountain of Autumn leaves, clearing gutters, etc.

Rest assured, even if  the results from proof of concept are embarrassing and disastrous, I will confess in due course. :)

Logged
Pages: [1] 2 3 ... 6