30 Day Timer

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

Hi all. I am trying to program an ATtiny13V to hold a pin low for 30 days then fire the pin high for 20 min before doing it again. I'm trying to formulate the best way to go about attacking this problem.

Any suggestions are appretiated but this is what I have so far.

The ATtiny13V has a 10MHz internal clock and the data sheet says the maximum prescaler is Fclk_io/1024. This will give me an effective clock period of 102 uSec.

The onboard counter is 8bits wide which means it will be full after (2^8 * 102uSec) = 26.2mSec.

My thought was I could then begin storing the number of times the counter finishes and store that in an empty byte. However this would only give me a counter multiple of 256 which would only be 6.71sec. And there are 2,592,000sec in 30days.

Long story less long, I would have to count continuously through 4 bytes before I met the 30day mark.

I would then need to figure out exactly what byte value marked the end of the 30th day then switch to the 20min length code.

I assume that what I'm proposing is possible. But is this the best way to go about doing this?

Is there any suggestions or ideas to make this easier?

And any direction to sample code would be a great help. Thanks in advance!

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

How accurate do you need the timing? From factory the tolerance of the internal oscillator is +/-10%. In your case this would be +/-3 days.

/Martin.

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

1) Read the datasheet: tiny13 has not 10MHz intern RC
2) like said mtashi --> not accuracy You can caliber but I have not experience with long drift RC.
Perhaps if you have just one pin to fire use a ceramic resonator +-0,1% and cheap.
or but not see if it is working with tiny13 user a 32k crystal. low start frequency.
thierry

Thierry Pottier

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

Why dont you increase minutes when seconds hit 60 and set seconds back to 0?

Expanding this, why don't you incdrease hours when minutes hit 60?

Yet, days when hours==24?

And finally, toggle the pin when days==30?

Edit: this of course assumes you know how to count seconds.

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

Thanks for the helpful hints!

The timer did not need to be very accurate so multiple if statements worked fine. But it's good to know that if I needed more accuracy I could always use a crystal.

Thanks again!

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

Jepael wrote:
Why dont you increase minutes when seconds hit 60 and set seconds back to 0?

Expanding this, why don't you incdrease hours when minutes hit 60?

Yet, days when hours==24?

And finally, toggle the pin when days==30?

Edit: this of course assumes you know how to count seconds.


Or, why not just use a 32-bit unsigned integer?

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

There are 43200 minutes in 30 days & 60000 ms. in a minute, which can both be stored in a signed int.

Derive a 1 ms. interupt from timer to decrement the
60000 ms to 0 at which you decrement the minutes counter ( and reset the ms counter to 60000)
When minutes counter equals 0 , you reinitilaize it with 20 & start counting it down. etc.

Instead of watching for 30 days, reduce the minute counters & test it all in about 3 or 4 minutes.

Lee

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

Quote:

But is this the best way to go about doing this?

"Best" is always subjective. One way to approach long times like this--e.g., alert when periodic maintenance is required--is to use the watchdog timer in interrupt mode at the longest setting, typically 8 seconds.

While this will certainly not give you the timing precision of a crystal it can be calibrated or used as-is to be "close enough". The advantage is that the AVR is then keeping time with no external parts like 32k or other crystal (cheap), and the average current draw is a few uA (can live off the tiniest button cell).

Lee

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.

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

Yes, nice one. Another way to kill a cat!(sorry to cat lovers).

Quote:
One way to approach long times like this--e.g., alert when periodic maintenance is required--is to use the watchdog timer in interrupt mode at the longest setting, typically 8 seconds.

There are 5400 lots of 8 seconds in 30 days. Only requires an integer now, if loss of acuracy is not an issue.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

I have a similar requirement but am having a difficult time finding an example of how to best connect a button cell to the avr and how to isolate it so that the cell only drains during power outages.

Any ideas?

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

Quote:

There are 5400 lots of 8 seconds in 30 days.

There are a lot more than that here in the Northern hemisphere, but maybe it is different Down Under. ;)

Quote:

isolate it so that the cell only drains during power outages.

Any ideas?


Diodes?

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.

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

Imigis wrote:
I have a similar requirement but am having a difficult time finding an example of how to best connect a button cell to the avr and how to isolate it so that the cell only drains during power outages.

Any ideas?

use diodes preferably shotkey. or design some sort of FET switch that gets active when the supply gets below a certain threshold.

I know that there are also some integrated components that can do the trick, but they are rather expencive. I used one from maxim, but other vendors should also have them.

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

Quote:
There are a lot more than that here in the Northern hemisphere, but maybe it is different Down Under.

Forgot to add our siesta time in...Hi Hi!
Lee

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?