I'd like to keep time on my atmega8.

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well what I'm trying to do is open a water valve solenoid at certain times of the day. It's ok if the time isn't 100% accurate, but how would I go about measuring time on my atmega8? If I wanted truly accurate time I could put wireless access on the thing and query an NTP server for correction.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Count seconds?

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yea guess I was over thinking it, only issue is getting the correct 'starting time' programmed to the chip. Guess I could do some push button inputs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You could use a Real Time Clock IC. Very simple to use and you now can create schedules easily

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Corey,

 

If the start time is convenient to you, why couldn't you simply start the device at the time you want and have your software reset the counts in 24 hours, rinse and repeat...

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

He does mention several times a day, hence why I mentioned the RTC, but you and bob are correct the avr could simply count seconds

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Time piece?

 

Lots of options.

 

As you already pointed out, one of the key design considerations is how to set the original time.

 

Another is the back-up power supply, so that it doesn't have to be reset every time there is a glitch in the primary supply.

 

If you are powering a water supply solenoid, then there is a good chance your project will be Main's powered, so low power which is often a consideration for time keeping devices doesn't apply in this case.

 

You could certainly count the Main's power line zero crossings, be it 50 Hz of 60 Hz.

Although the short term accuracy isn't very good, the long term accuracy, for a simple clock, is quite good.

A step down transformer is very useful for this purpose, it gives you a low voltage signal to work with, and isolation from the Mains.

 

An RTC chip was already mentioned, and they come in various models and accuracies, (and costs...).

 

Some of the AVR's let you put a 32.x kHz "clock crystal" on one of the Timer/Counters to generate a clock interrupt signal.

You then count the minutes, hours, days, etc., in software.

IIRC, on some uC's if you use the clock Xtal, then you run the uC on the internal RC osc, (8 MHz, or whatever), which would be more than fine for your application.

 

There are also the radio time signals, with small RF receiver modules available to make receiving the signal easy.

Again, you use software to decode the time signal and periodically reset the clock to the known good time.

Depending upon one's location you might have a strong signal, or one that tends to come in loud and clear at night, and fade during the day.

 

One of my favorite methods is to put a GPS module on the device, assuming it will be located where it can pick up a signal.

Again, one would typically maintain an internal, software clock, and synch it with the GPS time signal now and then.

GPS modules used to be quite expensive, now they are quite inexpensive. (Especially the older models without all of the new bells and whistles).

 

With the newer WiFi breakout boards one can also go the NTP server route, if you have an open WiFi signal in the vicinity.

 

Just using the "normal" external Xtal on the uC can give one a "pretty good" clock.

Many Threads have discussed the ppm Xtal accuracy and how it converts to minutes / day or per month accuracy; and the common software method of adjusting for this.

(If you Xtal clock runs 4 minutes fast a day, then add 4 minutes every midnight, or 2 minutes every 12 hours, or 1 minute every 6 hours, or 30 sec every 3 hours...)

 

Of course one can purchase a temperature and voltage compensated clock module to get better accuracy, if desired.

 

As a practical matter, you probably want to add an LCD to display the time, and the on/off status of the water supply.

Add a push button switch or two to enable you to set the time.

 

If you are only building one or several such devices, the increased cost for an LCD and a couple push button switches is minimal, and the convenience is significant.

 

An RTC chip / breakout board will often have its own coin cell battery back up supply.

If you go with one of the other options, then some design time and effort, (and cost), needs to go into the back up power supply.

 

I thought there was another Thread on this same to[pic, (water plants), just recently, but I can't seem to locate it.

There are many Threads on time of day clocks.

 

Good luck with your project.

 

JC

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

You could use a Real Time Clock IC. Very simple to use and you now can create schedules easily

Jim

 

I just researched and this would be a great idea for my circuit, is there a good tutorial for talking to this over SPI and what real time clock IC would you suggest?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Corey.

 

I like the DS1307. Easily available (Ebay has lots of them). But it is an I2C or TWI interfaced chip not SPI.

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

Hi Corey.

 

I like the DS1307. Easily available (Ebay has lots of them). But it is an I2C or TWI interfaced chip not SPI.

 

Cheers,

 

Ross

 

 

Thanks that looks very nice, is there a good tutorial around for interfacing and using this ex:setting the time ? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Corey,

 

Read these two last posts.

 

https://www.avrfreaks.net/comment...

 

You can also read the whole thread, but if you are in a hurry the last two should be enough.

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I should use this library to read and write the i2c protocol from my atmega but, what output and inputs should I expect to give and receive from the RTC?

I'll have to set the RTC time from my atmega?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Corey,

 

I suggest that you have a read of a completed project that employs the DS1307 with Peter's code. One such project can be seen here.

 

http://pointersgonewild.com/2012...

 

... which was found using Google "avr ds1307 Fleury". There are others, but this one may be of greatest value because it incorporates an LCD display and keypad for entry of initial times.

 

Have fun.

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Corey,

I used a Maxim RTC3234 in a clock project a year or so ago with a Mega88.  Super easy to set the time, and use, but the pert is expensive and way overkill for the job.  If I had to do it over again I would go with the DS1307 as Ross pointed out for cost savings.  I also liked the 3234 because of the SPI interface over TWI but I have been forcing myself to use parts with TWI to improve my experience with the interface.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use one of these, controlled by my home automation system. 

http://www.smarthome.com/smarten...

 

Jim