Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Async timer with 32kHz crystal on ATtiny861

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
mega128

Bascom Member



Joined: 08 Feb 2009
Posts: 28

usa.gif
PostPosted: Mon Dec 21, 2009 9:51 pm    Post subject: Async timer with 32kHz crystal on ATtiny861 Reply with quote

Hi all,

I am new to BacomAVR and AVR so please bear with me.

I am trying to put micro in sleep mode to save coin cell battery and wake up every second to check the status of ADC. If ADC is higher than usual it should carry out some task and go back to sleep.

Now, the problem is I am using ATtiny861 since it has 32x gain capabilities in ADC. But can't find TOSC1/2 pins on this micro. Does it mean 261/461/861A don't have these pins to connect external watch crystal? If there is a way to connect watch crystal to it what pins?

Thanks Very Happy
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Dec 21, 2009 11:18 pm    Post subject: Reply with quote

According the data sheet the only way to connect a 32768Hz crystal is as main clock source. This may make execution of your code a tad slow. Very Happy

Better calculate the clock cycles needed for the awake period, before you take that approach. Be also aware that you need then an ISP frequency lower than 8kHz.

If the above doesn't work for you, use an external RTC with 1Hz clock output connected to Int0/1.

Or a different µC.
Back to top
View user's profile
mega128

Bascom Member



Joined: 08 Feb 2009
Posts: 28

usa.gif
PostPosted: Mon Dec 21, 2009 11:44 pm    Post subject: Reply with quote

Thanks for quick reply. I intend to use 16Mhz crystal as main clock source. This means I can't have two xtals at same time. Interrupt timing is not critical as I am not going to build a internal clock. As long as I can put micro on sleep and wake it up approx 1 second, do the ADC task and go back to sleep I am fine.

Would you recommend using watchdog or internal oscillator or something else that will consume least power similar to 32khz clock?

Thanks
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Dec 22, 2009 1:02 am    Post subject: Reply with quote

Hmm, everything depends on your requirements of speed / complexity of the circuit / power consumption. I would recommend to check the diagrams at the end of the Tiny data sheet.

The WDT Int combination shouldn't work bad, 4µA at 3V, but again, if you'd use an external RTC which would take about 400nA and the µC in power down at approx. 170nA, this combination would work with less than 600nA.

Of course the consumption for the time the µC is awake and running with 16MHz has to be added in this calculation, for example 1000 cycles would add about 500nA for an one second period, that's 1.1µA for the RTC versus 4.5µA for the watchdog.

Maybe you could also use a lower main clock, this would additionally reduce power consumption. Also be aware that the Tiny needs a certain voltage to run at 16MHz, with one lithium cell of 3V you will not get more than 10MHz.

But again, check the diagrams, everything's in there and then decide what's most important for you.
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Tue Dec 22, 2009 2:38 pm    Post subject: Reply with quote

Hi,

You can divide the system clock with IO register CLKPR.
Eg if you use 16 MHz crystal and CLKPR = 7, you will get clock 125 kHz.
See datasheet how to set CLKPR.
Back to top
View user's profile
mega128

Bascom Member



Joined: 08 Feb 2009
Posts: 28

usa.gif
PostPosted: Tue Dec 22, 2009 4:02 pm    Post subject: Reply with quote

MWS - WDT Int 4µA at 3V does not sound too bad to me as it reduces one external component. The reason I can't change 16Mhz is that is required by another chip. I am trying to use 16Mhz for both even though AVR can't run more than 10Mhz on 3V.

Visovian - "16 MHz crystal and CLKPR = 7, you will get clock 125 kHz" Can you explain little bit more. Do you mean that I should use watchdog timer or some internal timer and divide it to get 125khz. Will it consume less power and wake up the micro from sleep on int?

Thanks both of you for your suggestions.
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Wed Dec 23, 2009 9:58 am    Post subject: Reply with quote

Hi,
With CLKPR register you can change the main system clock during runtime.
When you have external crystal 16 MHz and in the code you set CLKPR to divide by 128, the clock is 128 kHz from this moment (16000000/128=128000).
Same as if you changed crystal for 128 kHz one.

Do you realy need 16 MHz in your application?

Quote:
The reason I can't change 16Mhz is that is required by another chip. I am trying to use 16Mhz for both even though AVR can't run more than 10Mhz on 3V.

Then you can feed both things with 16 MHz and in avr separately set other clock, as I have just described.

Another tip: you can at least slow the clock with CLKPR before going sleep and set it back after wake up.

In Idle mode you can use timer overflow for wake-up.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Wed Dec 23, 2009 3:18 pm    Post subject: Reply with quote

Visovian,

If the µC has to finish certain code, let's say 1000 clocks, it is more energy efficient to drive the core with 16MHz, than with 128kHz. If it's a wake-up for a fixed time, it's different.
Second, if energy effectiveness is an requirement, what sense should it make to run the µC in idle mode, current is approx. 60µA then, in contrary to 4µA at power down if done with the watchdog ?
The only sense to use CLKPR would be to use a common clock source of 16MHz and scale core frequency down below 10Mhz, so the µC runs stable at 3V.
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Wed Dec 23, 2009 4:47 pm    Post subject: Reply with quote

MWS:

You are right.
Power down and WDT interrupt will consume the least.

Quote:
If the µC has to finish certain code, let's say 1000 clocks, it is more energy efficient to drive the core with 16MHz, than with 128kHz.

Interesting. I have never thought about it deeply, but it sounds reasonable.
Thanks
Back to top
View user's profile
mega128

Bascom Member



Joined: 08 Feb 2009
Posts: 28

usa.gif
PostPosted: Sat Dec 26, 2009 3:10 pm    Post subject: Reply with quote

Thanks all for your input. WDT is working great for me.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum