can two atmega328's run on the same crystal/resonator
Short answer, no.
The oscillator works by the processors applying a voltage to a piece of crystal inside it. When voltage is applied to it, it vibrates (oscillates) back and forth at a known speed (for most Arduinos, 16MHz, which is 16 million times a second).
Because each Arduino has to apply its voltage to the oscillator, they can't both receive the signal from the crystal.
There is probably some way to do it, but it'd be more complex, and I don't know how. I believe there is also a way to apply a 16MHz signal (from a signal generator) to each of the ATmegas' pins, but I don't know how to do that either, and it's surely just as complex.
The crystal oscillator circuit sustains oscillation by taking a voltage signal from the quartz resonator, amplifying it, and feeding it back to the resonator.
from wikipedia... so no you cant have 2 devices doing a feedback loop on the same crystal
Section 8 of the datasheet covers all the clocking features avalible. And yes it is possible to use one crystal wired to one chip to then use the clock output pin to drive the clock input pin on another processor chip. There are fuse bits to change but it can be done, but probably not worth the effort as crystals/caps or resonators are pretty cheap these days.
Is there a specific reason you wish to use one crystal to drive two processor chips?
from wikipedia… so no you cant have 2 devices doing a feedback loop on the same crystal
But it is possible to set one processor to drive a crystal and set the second processor to use an external clock signal source. So only one processor is suppling feedback to the crystal but both are clocked be the single crystal. Section 8.8 covers some of this.
i wated to no because only had one on hand and i wated to something with 2 chips r
…use an external clock signal source
For some projects this may be useful.
The AtMega can be set to output its clock (e.g. 16MHz) on pin 14 (328p, CLKO). This requires setting a fuse on the master mcu and will be at the expense of one digitial IO pin (pin 14). On the slave mcu, you need to set a fuse to allow an external full swing clock input on pin 9 (XTAL1).
Another option is to program a timer (e.g. timer2) to output a clock signal on the master mcu (e.g. pin 5 or pin 17) and feed this to the XTAL1 pin on the slave mcu. This approach can also be used to source a clock signal to external peripherals (such as an analog to digital converter chip) in need of a clock. Max frequency for a timer based clock output is F_CPU/2.
what????? right over my head :-/
For some projects this may be useful.
The most useful purpose I can think of is when you want code on individual processors running in "lock-step" (minus clock signal propagation delays); this is useful for some parallel-processing computation. So - if you need both processors to be executing something at the exact same time, running 1-n processors off the same clock signal is a good way to do it.
what????? right over my head
Soory for that, but this is what you need to follow up on the idea of retrolefty.
Another option is to buy a full swing crystal. This is basically a small IC (crystal like) that include both the timekeeping crystal and the osscillator in a single package. The output from this single IC is capable of supplying the clock for multiple mcu's.
MicroController Unit, which is the ATmega chip on the Arduino. It's often referred to as a "CPU" but an MCU is different to a CPU in that it incorporates other subsystems such as non-volatile storage and specialised I/O.
Jon Freetronics: www.freetronics.com
Anyone remember the "dual core Arduino" thread on this forum from a few years ago? Looking for it now. As I recall, that design used a single crystal, two AVRs, and I2C to communicate between the chips.
Edit - I was right - two AVRs, one resonator. Here's the thread:
Anyone remember the “dual core Arduino” thread
I did think of that originally when I read this title, and tried to search for it to give the OP some starting points, but couldn’t find it :P.
Thanks for pointing it out.
Edit - I was right - two AVRs, one resonator. Here’s the thread:
While it may have worked as an experiment, it really isn’t something you should be attempting to use for anything “real world” or “production”; I don’t know if it could be scaled up (past 2 chips), either.
It seems like a neat “hack” - but not something I would trust long term…