National Homebrew Club Ireland

Brewing Discussions => Equipment & Chemicals => Topic started by: admin on February 08, 2013, 12:32:44 PM

Title: ATmega Counter Timers
Post by: admin on February 08, 2013, 12:32:44 PM
The Tubeinator is coming along well, but I'm planning on using an ISR to advance the timers for both fermentation programmes, and have the main loop then reading the timers and turning on/off whatever needs to be turned on or off.

Problem is Timer1 compare match register is 16-bit, and when set to 65535 and configured to use the maximum prescaler (1024) at 16MHz this means the slowest I can get it to generate an interrupt is every ~4.1 seconds on a 16MHz system clock. Am I reading that right?

Ideally I'd like an interrupt once a minute, but I realise that's not possible, so is 4.1 second the longest interval I can configure?
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 08, 2013, 01:17:25 PM
Surely you have something wrong there. No system could work only generating interrupts every 4 seconds.

Not sure why you are writing your own timers though.
There should be something like gettimeofday() function. No?
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 08, 2013, 01:22:03 PM
Scratch that about gettimeofday - i remember having to get all this stuff right so my rs232 would work.

Have you seen this?
http://www.frank-zhao.com/cache/avrtimercalc.php
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 08, 2013, 01:25:21 PM
I think it says that 1 tick is equal to 0.000064 seconds,.

OR to get your 60 seconds you would generate an interrupt every 937500 timer ticks
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 08, 2013, 01:30:37 PM
Ahhh i read you OP again - You want it to generate the interrupt slower not faster.
4.1s is huge so you're prob right about that being the slow end.

I Forget the details of writing those ISR in AVRs - but it just means you do nothing on the ticks that you dont want.
Title: Re: ATmega Counter Timers
Post by: DEMPSEY on February 08, 2013, 01:32:16 PM
jesus Jimmy,your posting faster than your thinking. :)
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 08, 2013, 02:02:11 PM
I wouldnt worry about the cpu time - it wont affect your system - it should be mostly doing nothing.

Set it so that you get a nice round number to avoid skew.
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 08, 2013, 02:02:28 PM
Quotejesus Jimmy,your posting faster than your thinking. :)

Yeah talking to myself :)
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 08, 2013, 02:40:04 PM
Oh yea forgot about the ethernet jobby.
Title: Re: ATmega Counter Timers
Post by: Beerdoh on February 11, 2013, 05:08:15 PM
Have a look at this Maxim part: http://datasheets.maximintegrated.com/en/ds/DS2417.pdf

Depending on what you write to the register, you can have one interrupt from every second to every 36.4 hours.

It requires a 32.768k crystal to keep it running. These are pretty cheap, and I should be able to get you some FOC. Same as for the Maxim chip. Let me know if you think you can use it. I know it's more hardware but more is better, yea!? :D The only thing I can see that might be an issue for you is the package type. It's surface mount - you should be able to get a through hole socket if that's what you're working with and solder it in place. I've worked with devices about the same size but with 10 pins - it's do-able. I'll get you about 20 of them to play around with if you want them. Here's the link to the outline drawing - http://pdfserv.maximintegrated.com/package_dwgs/21-0382.PDF

IIRC you're using the DS18B20's so the 1-Wire addressing code you have for those will work in a similar way to this part, so sequencing etc shouldn't be an issue... (Famous last words...)

If you're polling your micro for another task, it's best to let this hardware raise the flag as to when something should be serviced. There are, as always, more than one way to skin a cat.
Let me know if I can help any more :)
Title: Re: ATmega Counter Timers
Post by: JimmyM on February 11, 2013, 05:16:21 PM
Sounds lik ethat could do the business for ya alright Shane.
That crystal will give you nice numbers re human timing - it divides down nicely to 1 tic a second.
I remember it from my second year college project - building a clock :)

Wish i had more time for this kinda stuff - if i ever get more time me n you will be bezzies Beerdoh. :)
Title: Re: ATmega Counter Timers
Post by: Beerdoh on February 11, 2013, 05:21:36 PM
QuoteSounds lik ethat could do the business for ya alright Shane.
That crystal will give you nice numbers re human timing - it divides down nicely to 1 tic a second.
I remember it from my second year college project - building a clock :)

Wish i had more time for this kinda stuff - if i ever get more time me n you will be bezzies Beerdoh. :)

Heh, no probs! Will be glad to help..God knows i'd still be licking the academic pavement if I didn't have a few buddies who knew what they were doing! :P