ATmega328P clock question

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

Hi !

I would like to ask if I understood datasheet (Atmega328P http://www.atmel.com/images/atmel-8271-8-bit-avr-microcontroller-atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet.pdf) correctly.

I need stable clock for U(S)ART.

As ka7ehk said in :
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=140731

ka7ehk wrote:
Internal oscillator is often not accurate enough for baud rate setting.

The true operating baud rate of the two UARTs need to be within (about) 4% of each other. Internal oscillator CAN be further off than that.

Jim

So I need crystal oscillator lets say 8Mhz and connect it to PB6 and PB7 pins.

I also need to achieve long sleep times (1-2 min.)

Timer2 can wake up uC and is 8-bit. To achieve long sleep Timer2 should be fed with 32KHz Low-frequency
Crystal Oscillator on the same pins(PB6 and PB7).

If this above is OK then I can't do it like this, right?

Thanks !

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

Quote:

If this above is OK then I can't do it like this, right?


Yes but what a lot of people do when the app involved sleep (and hence potential delay on wake up for crystal to stabilize) is to actually use a 32.768kHz crystal to asynchronously clock timer 2 (think it's 2) then only use this to calibrate the internal RC from time to time (adjustments via OSCCAL) but the AVR clocks from intRC so when coming out of sleep it begins clocking quickly (so no huge power drain while it wakes).

YMMV

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

If you already have an 8MHz crystal running your mpu, if you use timer1, set the pre-scaler to /256, that will clock T1 at a 31250Hz rate, now set a compare match at 31250 and you have a 1Hz wake up interrupt. Add a little code to keep track of date + Hrs + Min + Secs and your good with a clock that should keep time fairly well.

JC

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

Thank you for suggestions guys !

clawson wrote:

... clock timer 2 (think it's 2) then only use this to calibrate the internal RC from time to time (adjustments via OSCCAL) but the AVR clocks from intRC so when coming out of sleep it begins clocking quickly (so no huge power drain while it wakes).

If I got this right, Cliff you are saying that 32.768kHz should be used for calibration?

I've read AVR053 and there is whole procedure described there , chapter 6.

I have ATmega16 and STK600 running at 1MHz internal oscillator, as default.

OSCCAL is set to 0xB8(I've printed it out).

As I understood calibration is preformed by programmer, what about during run time?
Changing OSCCAL(what value write to it) and RESET?

jccordill wrote:
If you already have an 8MHz crystal running your mpu, if you use timer1, set the pre-scaler to /256, that will clock T1 at a 31250Hz rate, now set a compare match at 31250 and you have a 1Hz wake up interrupt. Add a little code to keep track of date + Hrs + Min + Secs and your good with a clock that should keep time fairly well.

JC

JC,
Timer1 can't be used as a wake up source, according to datasheet p.38 or I'm missing something here?