View previous topic :: View next topic |
Author |
Message |
Sharp
Joined: 01 Aug 2007 Posts: 16 Location: Antwerp
|
Posted: Tue Apr 01, 2008 5:56 pm Post subject: Accurate timing |
|
|
Hello,
I'm working with the ATMega16 and need accurate timing so I want to use a 32KHz Crystal.
Now I was wondering if this will have influence on the working speed of the µC.
Can anybody help me?
Thanks |
|
Back to top |
|
|
DToolan
Joined: 14 Aug 2004 Posts: 1384 Location: Dallas / Fort Worth, Texas (USA)
|
Posted: Tue Apr 01, 2008 5:58 pm Post subject: |
|
|
No, the 32KHz crystal is seperate and independant from the operating crystal of the AVR. No influence at all. |
|
Back to top |
|
|
Sharp
Joined: 01 Aug 2007 Posts: 16 Location: Antwerp
|
Posted: Thu Apr 03, 2008 3:19 am Post subject: |
|
|
Thanks !!! |
|
Back to top |
|
|
Sharp
Joined: 01 Aug 2007 Posts: 16 Location: Antwerp
|
Posted: Thu Apr 10, 2008 2:38 pm Post subject: |
|
|
Hello,
I used Ian's software tool for the timing.
While reading the Bascom help to understand the code I read that the prescaler devides the sytem clock.
From help:
"The TIMER is connected to the system clock in this case. You can select the division of the system clock with this parameter."
I don't know what they mean whit "in this case" but it makes me think the µC works at 32Khz while using the 32Khz Crystal unless I use a different code ore something.
Can anybody help? |
|
Back to top |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Thu Apr 10, 2008 7:46 pm Post subject: |
|
|
The prescaler affects only the timer clock rate, not the CPU clock rate.
The CPU is clocked from the crystal oscillator (or whatever clock you specify in the fuses) and the timer is clocked by the output of the prescaler. The input to the prescaler is the main clock oscillator. _________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5 |
|
Back to top |
|
|
Sharp
Joined: 01 Aug 2007 Posts: 16 Location: Antwerp
|
Posted: Sat Apr 12, 2008 11:59 am Post subject: |
|
|
mattcro wrote: | The prescaler affects only the timer clock rate, not the CPU clock rate.
The CPU is clocked from the crystal oscillator (or whatever clock you specify in the fuses) and the timer is clocked by the output of the prescaler. The input to the prescaler is the main clock oscillator. |
Ok, thanks a lot!
I just wich to provent problems before they occure! |
|
Back to top |
|
|
Sharp
Joined: 01 Aug 2007 Posts: 16 Location: Antwerp
|
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Mon Apr 14, 2008 1:38 pm Post subject: |
|
|
Hi,
What is for you "accurate timing"?
Call some code exactly every second? (Every 1000 ms).
If yes, why not just use the Bascom Soft clock routines? (See help CONFIG CLOCK).
Best regards,
Luciano |
|
Back to top |
|
|
Sharp
Joined: 01 Aug 2007 Posts: 16 Location: Antwerp
|
Posted: Mon Apr 14, 2008 3:46 pm Post subject: |
|
|
Luciano wrote: | Hi,
What is for you "accurate timing"?
Call some code exactly every second? (Every 1000 ms).
If yes, why not just use the Bascom Soft clock routines? (See help CONFIG CLOCK).
Best regards,
Luciano |
Hello,
by accurate I mean as accurate as my watch.
It's supposed the fit in somekind of "gameconsole" I'm making whitch you can use during paintball/airsoft. It's supposed to be shut down by entering a code before a certain time has passed. All the players use there watches to know home much time there is left so I can't afford to be off.
Because this project is also for my graduation I really like to do this in the most accurate way...
Thanks 4 the reply |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
|
Back to top |
|
|
Jonas
Joined: 06 Jul 2006 Posts: 109
|
Posted: Mon Apr 14, 2008 6:31 pm Post subject: |
|
|
Time is one of the things that we can measure most accurate in this world.
But we do not know what we are measuring.
/Jonas |
|
Back to top |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Mon Apr 14, 2008 9:34 pm Post subject: |
|
|
I notice in several datasheets (eg M32, M128, though it's not specified for some newer devices) that the internal loading capacitors for the asynchronous 32kHz oscillator are 36pF each - that's a lot higher than the typical 6pF or 12.5pF specifications for 32768Hz watch crystals, so I guess everybody's RTCs based on AVR timers are going to run on the slow side...
I've had good results with the Dallas RTC devices - DS1307 and 1306 with cheap watch crystals have been within a second or 2 over a day (compared to GPS time). I'm about to try an AVR timer based RTC as part of a logger, so I'm interested to see how it compares for accuracy. _________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5 |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Tue Apr 15, 2008 9:30 am Post subject: |
|
|
Hi mattcro,
ATmega16 datasheet page 28
Low-frequency Crystal Oscillator
To use a 32.768 kHz watch crystal as the clock source for the device, the Low-frequency
Crystal Oscillator must be selected by setting the CKSEL Fuses to “1001”. The
crystal should be connected as shown in Figure 12. By programming the CKOPT Fuse,
the user can enable internal capacitors on XTAL1 and XTAL2, thereby removing the
need for external capacitors. The internal capacitors have a nominal value of 36 pF.
The 36 pF capacitors are not enabled by default and can be enabled/disabled with the
CKOPT Fuse bit. These capacitors are on the pins XTAL1 and XTAL2. In this thread we are
talking about the ATmega16 and the use of its timer2 in asynchronous operation with
a 32.768 kHz watch crystal connected to the pins TOSC1 and TOSC2. (Not XTAL1 and XTAL2).
Best regards,
Luciano |
|
Back to top |
|
|
Sharp
Joined: 01 Aug 2007 Posts: 16 Location: Antwerp
|
Posted: Tue Apr 15, 2008 10:13 am Post subject: |
|
|
Thanks Luciano,
Interesting thread!
Now I understand that watch-accuracy will not be possible but a fault of 20sec a day will be acceptable considering that a game probably will never last longer then half a day.
But I'm still strugling with the code. I don't know why it doesn't work.
I've tried changing the TCCR2A/B registers to TCCR1A/B. The program runs in the simulator but it doesn't coun't. So the solution must be something else...
Can anybody help me out with the register thing?
Thanks!! |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Tue Apr 15, 2008 2:44 pm Post subject: |
|
|
Luciano wrote: | Hi,
What is for you "accurate timing"?
Call some code exactly every second? (Every 1000 ms).
If yes, why not just use the Bascom Soft clock routines? (See help CONFIG CLOCK).
Best regards,
Luciano |
Just use the Bascom Soft clock routines. (See help CONFIG CLOCK). |
|
Back to top |
|
|
|