• Welcome to National Homebrew Club Ireland. Please login or sign up.
July 20, 2025, 05:48:45 AM

News:

Want to Join up ? Simply follow the instructions here
Not a forum user? Now you can join the discussion on Discord


ATmega Counter Timers

Started by admin, February 08, 2013, 12:32:44 PM

Previous topic - Next topic

admin

February 08, 2013, 12:32:44 PM Last Edit: February 08, 2013, 01:03:43 PM by admin
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?

JimmyM

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?
Formerly JamesM.

JimmyM

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
Formerly JamesM.

JimmyM

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
Formerly JamesM.

JimmyM

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.
Formerly JamesM.

DEMPSEY

jesus Jimmy,your posting faster than your thinking. :)
Dei miscendarum discipulus
Forgive us our Hangovers as we forgive those who hangover against us

JimmyM

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.
Formerly JamesM.

JimmyM

Quotejesus Jimmy,your posting faster than your thinking. :)

Yeah talking to myself :)
Formerly JamesM.

JimmyM

Oh yea forgot about the ethernet jobby.
Formerly JamesM.

Beerdoh

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 :)
To brew: Bohemian Lager, Munich Dunkel, Oatmeal / Milk Stout, Hefeweizen
Fermenting: Imperial IPA
Conditioning:
Serving:Munich Helles (Helles Bells), Oatmeal Stout

JimmyM

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. :)
Formerly JamesM.

Beerdoh

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
To brew: Bohemian Lager, Munich Dunkel, Oatmeal / Milk Stout, Hefeweizen
Fermenting: Imperial IPA
Conditioning:
Serving:Munich Helles (Helles Bells), Oatmeal Stout