Solved: atmega328p using an external oscillator

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

Hi Guys,

 

Put a new prototype board today (SMD) with the aim of using an external oscillator (4 pin variety) connected to XTAL1. (5v@20Mhz) It didn't work.  I replaced it with an external crystal and it did.  I'm presuming it's because I had the wrong fuse set.  

 

I have two questions:

 

1.  Are brand new IC's set to the internal MHz clock?  If so, I presume I can then set the chip to use external clock?

2. There are 3 fuse options for LOW.SUT.CKSEL that mention Ext.Clock.  The only difference seems to be startup speed. I'm guessing the slowest is a safe bet.  But how to I get the chip to run at 20MHz?

 

regards

 

 

 

Last Edited: Thu. Aug 29, 2019 - 02:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Yes, out of the box fused for internal clock with the  CLKDIV fuse turned on to divide the 8MHs internal clock down to 1MHz.

 

2. Most external clocks have a pretty fast startup time. You should be able to use the slowest startup with no problem. If that is not a critical parameter in your application, then that is a good choice.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Thank you.

 

My final question though, how does the chip know the clock is at 20Mhz? Surely there's more than simply setting F_CPU ?

 

regards

 

 

 

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

nikm wrote:

.. Put a new prototype board today (SMD) with the aim of using an external oscillator (4 pin variety) connected to XTAL1. (5v@20Mhz) It didn't work.  I replaced it with an external crystal and it did. ...

 

1.  Are brand new IC's set to the internal MHz clock?  If so, I presume I can then set the chip to use external clock?

That seems inconsistent. If a Xtal worked, then you must have changed the the fuses to set for Xtal ?

If the Ext Osc failed, did you check it was working ( eg Enable pin wired ?) 

Most MCU take CLKIN on the Xtal IN pin, so can work in either Xtal or Ext osc mode with a CMOS-Swing Osc, and if you have a Clipped Sine external Osc, you would select Xtal, and AC couple to the XIN pin.

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

how does the chip know the clock is at 20Mhz?

It doesn't have any idea, nor does it really care (as long as you stay withing operational limits for the clock type & voltage you select [as well as the chip's rated speed grade*]).  If you try to pump in 300MHz, it won't work & still won't know. 

 

 

* for some goofy reason they bother to sell different chip versions rated for 16MHz  or 20MHz, as though that is light-years different.  How about selling 20MHz & 100MHz versions?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

The chip clocks at what ever the input frequency is. F_CPU ONLY tells the software what the clock frequency is; it has no effect, what so ever, on the frequency at which the CPU is clocked.

 

Well, there is the CKDIV fuse that (in an M328P) causes the cpu  to run at 1/8 the clock frequency., 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Wed. Aug 28, 2019 - 04:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks,

 

Made new board with new chip.  Worked until I set clock to Ext clock, then unreachable though it is flashing a led but very slowly (blink test program I initially uploaded)

 

I'm using this device (CB3-3I-20M0000) as an external source.  As far as I can tell, not connecting the enable pin to anything enables it.

 

regards

 

 

 

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

https://www.avrfreaks.net/forum/...

 

(the irony of this is that if an AVR is "not contactable" then the solution is to apply a clock to the Xtal1 pin - an "ext clock" such as you are trying to use should actually be an easy means of recovery - not a problem - what does a scope on Xtal1 show?)

Last Edited: Wed. Aug 28, 2019 - 12:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nikm wrote:
though it is flashing a led but very slowly

Your ISP speed must be set below 1/4 the actual cpu speed, so if it is slowing blinking then there is a working clock source, so you need to set the ISP speed below it in order for it to program or read properly.

It sounds like your still having problems selecting the correct fuse settings, suggest you post them here BEFORE your write them so some one can verify they are correct.

Also, many Freaks use this site for fuse guidance. http://www.engbedded.com/fusecalc/

 

Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

scope looks ok, but I'm no expert

 

regards

scope Clock signal

 

 

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

100MHz is out of spec for an AVR, most are 20MHz tops, your external clock is too FAST!

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

OMG.  You're absolutely right.  It says 100MHZ on the chip too (very small).  Duh!.  Packet they came is says 20MHz.  Lesson learnt, don't assume the supplier has picked the right parts.frown

 

Much appreciated.  So blindingly obvious in the end.

 

regards

 

 

 

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

nikm wrote:
 It says 100MHZ on the chip too (very small).
Sorry, are you saying you have bought mega328Ps that have 100MHz printed on the case ??

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

I think that 100MHz is the frequency of the external oscillator.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Oh I see. I never thought of ext-clocks as "chips" but I see that's what he means now.

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

nikm wrote:

OMG.  You're absolutely right.  It says 100MHZ on the chip too (very small).  Duh!.  Packet they came is says 20MHz.  Lesson learnt, don't assume the supplier has picked the right parts.frown

 

Much appreciated.  So blindingly obvious in the end.

hehe, Certainly not something anyone might look for at first tho !

 

100MHz is certainly too fast for the CPU clock, but as a curiosity, it might work if the drive is enough and the AVR dividers can toggle at 100MHz.

IIRC the xmegas spec they can run to 125MHz on clkin, provided you also limit CPU speed to <= 32MHz.

What is the swing on the 100MHz oscillator ? - Clipped sine parts are usually ~ 1vp-p, and they would need to be AC coupled to XIN, and even there the low gain of the amplifier at 100MHz might mean it cannot toggle.