XTAL1 and XTAL2 questions

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

Hi,

Up until now with AVR devices, if I want high F_CPU freq for my AVR device, I would attach a crystal to the XTAL1 and XTAL2 with a couple 22pF caps.

I've seen CPUs/MPUs, like the Z80, have only one XTAL pin. Can't I simply attach a crystal to this pin? I can understand, for example, some ATMEGA devices have CLKOUT pin that can feed the frequency into another ATMEGA's XTAL1 pin for clock input. But, that's different from have a crystal connecting to XTAL1 ALONE (NOT to XTAL2) directly. Is that possible?

I've read also there is "crystal" and "crystal oscillator." Are they the same terms? I see that oscillators are much more expensive than just crystals.

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

Quote:

I've seen CPUs/MPUs, like the Z80, have only one XTAL pin.

Let's start there. The pinouts I can find indicate a CLK pin. No "XTAL" that implies "crystal". "CLK" implies "external clock" to me.

The datasheet isn't explicit (strangely, the CLK pin is not in the Pin Descriptions table) but there are specifications on the CLK waveform.

Short answer: Z80 didn't use a crystal directly, but rather an external clock as input.

You can configure your AVRs to also use an "external clock". In most modern AVR8 models, that will allow you to use XTAL2 as another I/O pin.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

When there are two pins, Xtal1 and Xtal2, it is because they are part of an oscillator circuit. The Xtal is part of the feedback loop, given the right conditions the circuit will oscillate at about the Xtal frequency.

For the oscillator, one can often use an inverter, (or its equivalent). One of the pins is an input, one is an output.

One can feed a square wave into the input of the "oscillator" circuit and the inverter will generate an inverted output square wave. The rest of the circuitry doesn't know or care if the square wave came from an external source, or from the feedback loop on the inverter (oscillator).

That is somewhat simplified, the actual oscillator circuitry generally makes some other adjustments to the oscillator circuit when it is being externally driven, but that gets the idea across.

A crystal oscillator usually refers to an external device which generates a square wave. It is typically a 4-Pin device, with its own V+ and Ground connections, and an output signal pin.

It likely has a crystal within its small package.

A device which expects a clock signal, i.e. a square wave at 4 MHz, or 20 MHz, or whatever, won't do anything with just an Xtal connected to the pin. An Xtal only generates a square wave when it is connected to an oscillator circuit, in a feedback loop.

JC

OK, I'm a slow typist...

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

If you want to see how Z80's were clocked then try "z80 schematic" at Google Image search. You hit things like these:


that one shows "TTL OSc" input to pin 6


another external oscillator


"Can oscillator"


external oscillator

Of course you can run an AVR on an external oscillator too - in that case you just feed the TTL clock into XTAL1. If you do this XTAL2 is effectively a wasted pin.

EDIT: dare I even ask this on the "last day" but is Lee right in the previous post - I thought that when fused for external clock the XTAL2 is just shown as "NC" but that it isn't available as I/O - anyone know?

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

Quote:

If you do this XTAL2 is effectively a wasted pin.


Now, what did I just say?

Quote:

You can configure your AVRs to also use an "external clock". In most modern AVR8 models, that will allow you to use XTAL2 as another I/O pin.


I think we are both right -- it AFAICR depends on the AVR model.

See e.g. the diagram in the 8.8 External Clock section of Mega88 datasheet.

I seem to recall a thread confirming XTAL2 availability.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

In the beginning a CPU required an external clock. e.g. Z80's CLK pin.

Then MCUs appeared with an inbuilt inverter that could oscillate with an external crystal. e.g. 8051's XTAL1 and XTAL2 pins

Then MCUs appeared with an internal RC oscillator that required no pins. e.g. AVR Mega

In fact you can use all three types of clock with a modern AVR. And re-use any redundant external pins. The early AVR's XTAL pins were useless if you used RC or EXT e.g. mega32.

Yes, an external clock module has 4 pins.
A simple crystal has 2 pins (but you need the 22pF load capacitors)
A ceramic resonator has 3 pins (and you don't need 22pF capacitors)

All these choices are driven by cost, space, reliability, ...

David.

Edit.

Quote:
I thought that when fused for external clock the XTAL2 is just shown as "NC" but that it isn't available as I/O - anyone know?

A mega328 can use XTAL1, XTAL2 pins for GPIO or for ASSR.
Most Tinys can use XTAL1, XTAL2 for GPIO e.g XTAL2 is available when you use EXTCLK on XTAL1.

Last Edited: Fri. Sep 5, 2014 - 03:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff--As is often the case, we've been here before. ;) See this thread:
https://www.avrfreaks.net/index.p...

It may indeed depend on the model.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:

Cliff--As is often the case, we've been here before. ;) See this thread:
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=1107278#1107278

It may indeed depend on the model.

[OT]

 

So here's a good example of "how will topics from the old site be accessible?"

 

Lee, your link above simply redirect me to the landing page rather than the real topic.

 

Changing the link:

http://legacy.avrfreaks.net/inde...

 

Seems to work.

 

"Will there be a day when this happens automatically?" he asked, not unkindly...

 

[/OT]

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Sat. Sep 6, 2014 - 03:21 AM