Could an AVR handle having its clock speed changed?

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

Hi - I am looking at driving an atmega168 from an external clock source, a Microchip MCP2515. It will initially drive it at 20/8Mhz, but then I'll have the AVR write a setting over SPI that will bring it up to a full 20Mhz. Will this mess up the AVR at all?

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

Why not drive the 168 at the highest freq. you need and use the clock prescaler to change your clock . It allows changing on the fly from what I see. I don't think the avr likes it's external clock source to change rapidly .

Pete

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

Hey,

According to the AVR datasheet you can't do that, somewhere it lists that you can't change the clock frequency more than XX percent.

Using the prescaller as mentinoed by digitool would do the trick, and you could just use an external crystal too.

-Colin

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

As long as you don't violate the minimum clock high and low times, you can change the frequency as fast and as often as you wish. So check the datasheet for your particular AVR and for your microchip part to ensure that you don't ever send a runt clock into the processor.

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

Looks like we need the linky ;-)

http://www.atmel.com/dyn/resourc...

Page 34, first paragraph.

-Colin

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

Well I was looking at the possibility of attaching a crystal to the MCP2515, then using it's clock output to drive the AVR. Problem with the MCP2515 is that by default it's clock output is 1/8 of it's clock input, so it'd be driving the AVR at 2.5Mhz. I would then change that setting over SPI so that it outputted the clock input, but so it would transition from 2.5Mhz to 20Mhz. Doing it this way would save me two GPIOs on the AVR, so it's a very attractive solution, if it'll work.

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

c_oflynn wrote:
Looks like we need the linky ;-)

http://www.atmel.com/dyn/resourc...

Page 34, first paragraph.

-Colin


Could I get away with doing something like changing the clock speed from 2.5Mhz to 20Mhz, then doing a whole bunch of NOPs, and then resuming? The datasheet doesn't say what exactly happens - but I figure if nothing is being written to/read from I'll probabaly be ok, right?

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

If you are changing clock freqs because of battery life then the clock prescaler works to limit power needed to run and there are no glitches. If you are going to the trouble of adding complexity for changing the clock then add a reset circuit when changing freqs . Store whats needed in eeprom.

Pete

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

> As long as you don't violate the minimum clock high and low times,
> you can change the frequency as fast and as often as you wish.

Definately not. The reason is that there are issues with the flash
ROM clocking, so when changing the clock frequency too rapidly, you
risk reading garbage out of the flash. While there are only two clock
ranges (and it's crossing the border between both that is the critical
event), nobody wants and will tell you where that border actually is,
as this heavily depends on manufacturing influences, so it could be
quite differently for each device.

Issuing an external reset while changing clocks (as suggested) should
be safe then.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.