Clocking two atmega32

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

Hallo, I have four atmega32s which need to work in parallel. The need to work as equally as possible. This would mean that they have to be clocked by the same source. Can you give me some ideas how to do this correctly?

Is it possible to output the clock frequency on any of the atmega's pins?

Somewhere I read that MCU have OSC outputs for this purpose, but I can't understand how to do this. I read the datasheet but it didn't help. The atmega32 has TOSC pins but as far as I understood they are used for clocking timer2.

My idea was to use timer1 in CTC mode to output the oscillator frequency divided by 2 and then clock the other mega32 with it. But I don't really like this approach.

PS. I guess you might suggest me to use some clock generator chips, but this is not the point, because I can't place them on my PCB :)

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

You can use the modern ATmega324, which has a clock output.

But if CPUs doing different things, they need different time.
So they not synchron, even on the same clock.

Thus the typical ways was, that one CPU send a sync pulse to all others, e.g. every second.
This can be done over a wire or over a data bus (UART, I2C).

Peter

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

Hello,
to run multiple ATmega32 with the same clock use a crystal at the first one and set the CKOPT fuse. Then connect the Xout pin to the Xin pin of the other and set fuses for external clock for them.
To synchronize handling I suggest to use first chip timer output and connect it to external interrupt of all chips. Then they start at least at the same clock.

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

Thank you for the quick answers.

Danni, I don't have development tools for Atmega324 :) I use a homemade debugger and it is working only with 6 MCU and atmega324 is not among them.
As for the synch pulses you suggest I have already done that and it was working fine. But I need high speed and accuracy between the devices, so I am not sure that this is a reliable approach.

uC-Harry, what you said sounds perfect for my goal. I guess the Xin and Xout pins are Xtal1 and Xtal2. I will try this later.

Thank you both.

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

nedsana wrote:

I use a homemade debugger and it is working only with 6 MCU and atmega324 is not among them.

Why you need a debugger?

If many CPUs works together (this was my typical case), a debugger should be useless, since on debugging one CPU stops its working and all further communication would fail.
Thus I insert some UART messages, if debugging was needed, which was sent to a terminal, without stoping any operation.

nedsana wrote:

But I need high speed and accuracy between the devices

Please can you name real numbers instead the vague "high speed" and "accurate".

If every CPU has its own crystal, the deviation was only some ppm.
E.g. for light effects it should be sufficient, if all CPUs are synchron less than 10ms.
So a synchronisation every minute should be sufficient.

Peter

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

nedsana wrote:
uC-Harry, what you said sounds perfect for my goal. I guess the Xin and Xout pins are Xtal1 and Xtal2. I will try this later.

I tried it on an older project and made very bad experience.
About 5% of the devices fails suner or later.
It was not reliable, even if I connected only a second CPU and the wire was short (<20mm).

Please watch, that a crystal should typical only consume about 1mW, since on higher energy it may be damaged.

Thus the Xout pin has only very weak driving capability.

Peter

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

Hello,
you guess right

Quote:
Crystal Oscillator XTAL1 and XTAL2 are input and output
and I have used already a lot of systems where I clocked two devices (ATmega168) from one crystal. The wire had more than 100mm and a connector in between. I did it because the data sheet tells us:
Quote:
When CKOPT is programmed, the Oscillator output will oscillate will a full rail-to-rail swing on the output. This mode is suitable when operating in a very noisy environment or when the output from XTAL2 drives a second clock buffer.

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

Danni,
I mentioned the debugger, because this is the only programming device I have. And it does not support Atmega324.
As I said, I had two boards each of them had its own crystal. Before using a synch signal there was noticeable difference in the speed of the devices. When I added the synch signal and all necessary waiting the MCUs were working perfect.
The speed: I need to fill 8 shift registers with data and I have to do this as fast as possible. Now I use 16MHz crystal and I fill the registers in 440us. And I find it slow :)

uC-Harry - tomorrow I will try to do what you suggested. But can you send me some simple schematics on the matter. I have not went through the datasheet looking for this approach.

And another question to you: actually I have 4 Atmega32s which need to work in parallel. And I am concerned about what Danni mentioned, that XTAL2 output will be overloaded if I connect the other 3 MCUs to it. Is it possible to connect the devices serially? Something like this:

Crystal -> dev1, XTAL1 -> dev1, XTAL2 -> dev2, XTAL1 -> dev2, XTAL2 -> dev3, XTAL1 ...

Thank you for the answers.

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

Quote:
a debugger should be useless, since on debugging one CPU stops its working and all further communication would fail.
But 2 or more debuggers woul help :) as you can have more than 1 instance of Studio running with 2 different debuggers.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

You are totally right, but I've got nowhere to take them from :)