Long time reader here, first time poster! First off thanks for even reading this!
I am trying to synchronize 6 or more arduinos (preferenably Nanos (for the small footprint) but I would consider Unos too). Basically my setup/idea is to have 6 arduinos running SPI controlled radios grab a piece of data ( in this case a voltage measurement from 6 transmitters) and then all 6 write to DAC ICs. I want this all to happen as close to the same time as possible (not sure how much I can withstand yet but for arguments sake lets say all arduinos needed to do this within 50 microseconds of each other or less).
My thought was to remove the capacitors, crystal/resonator and feedback resistor from the board of each micro and create my own board with one crystal, two caps, and one resistor to then "feed" a clock signal to pads where the crystal/resonator used to be on each micro. Ensuring to keep trace/wire lengths the exact same so signals reached the micros at the same time (this package would be small and trace/wire lengths would be less that 3-4 inches). The below link gave me much of my understanding of crystals but thats about it:
To tell each micro to read from radio and then write to DAC, I was thinking some sort of pulse signal and running interrupts.
Also from reading here: http://forum.arduino.cc/index.php?topic=23487.0
it looks like the nano uses a resonator but then other places I read people call it a crystal. Is this a case of mistaken identity? Does the nano run a ceramic resonator or crystal oscillator? From my limited knowledge I would think I want a crystal as people say they are more accurate with less drift especially during temp changes. Can anyone confirm if my idea above can use a crystal?
Thoughts on any of this? Sources of error I am missing?
Long wires carrying 16MHz signals will radiate like an antenna. While it's not impossible, it sounds like a bad idea compared to the alternatives.
Why can't one Arduino write to 16 DACs? Are the transmitters unsynchronised? How do you receive these many instructions and coordinate?
I would look at having a single sync wire between all the units so that the output command is sent with time for all the recipients to get ready, then sync goes off like a starting gun. You can easily get 50us accuracy with interrupts on the recipients.
Depending on the clock selection fuse settings, PB6 can be used as input to the inverting Oscil-
lator amplifier and input to the internal clock operating circuit.
Depending on the clock selection fuse settings, PB7 can be used as output from the inverting
Oscillator amplifier.
If the Internal Calibrate
d RC Oscillator is used
as chip clock source, PB7..6 is used as TOSC2..1
input for the Asynch
ronous Timer/Counter2 if th
e AS2 bit in ASSR is set.
The various special features of Port B are elaborated in
”Alternate Functions of Port B” on page
76
and
”System Clock and Clock Options” on page
so I guess would be better use an external oscillator (not just a crystal) and feeding in this way all mcus. Still valid what MorganS said about pcb traces.
You are asking for an external CLOCK. A chip that uses a crystal or resonator as its timing source, which then amplifies that signal so that it can travel long distances (here centimetres is considered long.) One crystal can't be connected to two chips.
If you look into the way that the Atmel chip drives the crystal/resonator, you will see that it is also an amplifier. If I had two chips soldered on the same PCB side-by-side, then I would consider using the output of one as the input of the other (where the first has a crystal also connected to that output) but it's a bad idea anyway.
Even if the clocks are synchronised, how can you be sure that the program running on the two chips is sychronised? If one gets an interrupt half a clock before the other, then they will start to get out of sync. Then you would need other sync lines so that they could wait for each other to catch up.
Why can't one Arduino write to 16 DACs? Are the transmitters unsynchronised? How do you receive these many instructions and coordinate?
The DACs are SPI controlled so I can only write to one at a time, so I was thinking if I could tell hey mostly just flood the airwaves with data and the receivers grab information when they are told to. I get it there is some error here too from when the voltage is measured ( on Tx side) and when received on Rx side but I dont really know hoe to sync the transmitter as they are not connected in anyway. FYI I am using nRF24L01+.
I would look at having a single sync wire between all the units so that the output command is sent with time for all the recipients to get ready, then sync goes off like a starting gun. You can easily get 50us accuracy with interrupts on the recipients.
I am hoping the interrupts would be triggered by yet another arduino or "pulse maker" that I can control. Essentially controlling the sample rate of the six arduinos, if this makes sense.
so I guess would be better use an external oscillator (not just a crystal) and feeding in this way all mcus. Still valid what MorganS said about pcb traces.
Yes that makes sense too but there is a lot of talk about fuses and 4 letter pins that confuse me. I will do more research if this is the best way to go.
Even if the clocks are synchronised, how can you be sure that the program running on the two chips is sychronised? If one gets an interrupt half a clock before the other, then they will start to get out of sync. Then you would need other sync lines so that they could wait for each other to catch up.
If the clocks are synced and I interrupt each micro with the same signal and they are running very fast, lightweight code wouldnt they stay pretty close in sync? I understand code runs different on each micro but I am just trying to minimize the possibility of code running at different speeds
My thought was to remove the capacitors, crystal/resonator and feedback resistor from the board of each micro and create my own board with one crystal, two caps, and one resistor to then "feed" a clock signal to pads where the crystal/resonator used to be on each micro.
Make one the "master". The master would have the typical clock (crystal + capacitors). Change the master's fuses so CLKO is enabled. Change the "children" fuses to "External Clock". Connect master CLKO to children XTAL1 (or XTAL2; check the datasheet for which is correct).
Note: There may be a synchronization delay going into the children.
Note: There may be a synchronization delay going out of the master.
Basically my setup/idea is to have 6 arduinos running SPI controlled radios grab a piece of data ( in this case a voltage measurement from 6 transmitters) and then all 6 write to DAC ICs. I want this all to happen as close to the same time as possible (not sure how much I can withstand yet but for arguments sake lets say all arduinos needed to do this within 50 microseconds of each other or less).
That is a woefully incomplete problem description. I suspect you have become obsessed with an overly complicated, possible poor quality, "solution" before exploring other possibilities.
Make one the "master". The master would have the typical clock (crystal + capacitors). Change the master's fuses so CLKO is enabled. Change the "children" fuses to "External Clock". Connect master CLKO to children XTAL1 (or XTAL2; check the datasheet for which is correct).
Yes this solution is the one that keeps getting mentioned in my research so I will pursue this path. Maybe I can have a 7th arduino send a signal that splits off to the 6.
That is a woefully incomplete problem description. I suspect you have become obsessed with an overly complicated, possible poor quality, "solution" before exploring other possibilities.
What possibilities would that be? Suggestions are welcomed
Well, since it looks like you will need another wire coming from a master to sync the slaves anyway, why not just do that? No need to massacre the Nano crystals.
J_Maz:
If the clocks are synced and I interrupt each micro with the same signal and they are running very fast, lightweight code wouldnt they stay pretty close in sync?
No.
You are over thinking this and I suspect the last thing you want to do is to synchronize 6 Arduinos.
If you must have 6 Arduinos, which is something I very much doubt, you will get a much closer synchronization if you have a digital output from one and look at that with all the others and then do the stuff. The difference in clock speed is nether here nor there.
I have six transmitters sending strain based measurements to a homebase (the 6 arduinos I was referring before). This homebase will then output the six received signals as analog outputs to my normal data acquisition system.
I suspect the last thing you want to do is to synchronize 6 Arduinos.
If you must have 6 Arduinos, which is something I very much doub
Why would you suspect or doubt this? I want 6 simultaneous measurements. I don't think the nrf24l01 does six measurements at once. It does one at a time in sequence which might be acceptable for each measurement but then you have to write the data to a multiplexed dac or six different dacs which would also be in sequence and further offset the data.
If you must have 6 Arduinos, which is something I very much doubt, you will get a much closer synchronization if you have a digital output from one and look at that with all the others and then do the stuff. The difference in clock speed is nether here nor there.
With more and more research this is becoming a good idea. I think I agree that maybe the difference in clock speed tolerances from board to board may not be a huge deal. I was always planning to have a pulse signal to run interrupts on the 6 micros
Put all the AVR's on an SPI bus with one master and use the SPI clock as your synch.
SPI lines
SCK or CK = spi clock : slower than the chip clock, still fast
SS or CS = slave select or chip select : selected chips listen and/or talk
MOSI = master output slave input : master talks to selected chips
MISO = master input slave output : master listens one slave talks
SPI also needs power and ground.
I've seen a picture of a wire sculpture circuit with 4 328P's close around one crystal and caps node.
Have you had a hand at making standalone AVR's?
Put all the AVR's on an SPI bus with one master and use the SPI clock as your synch
By AVRs do you mean the microcontroller/arduino itself?
If yes, are you saying have one arduino send a SPI clock that all my ICs see and then have 6 arduinos read the MISO lines? Each one of my radios requires a MOSI write (which could be the same command for each one) and then maybe they could return information via MISO to 6 arduinos??? This sounds sketchy. How would the 6 arduinos know data is coming across the line? The more I write the more I think you cannot mean this, so what do you mean by "put the AVRs on the same SPI bus"?
Put all the AVR's on an SPI bus with one master and use the SPI clock as your synch
What do you mean by "standalone AVRs"? You mean just using the ATmega328 chip itself without using the entire Arduino package? If yes, then no I do not have any experience with this.
Well, you're not going to be able to reliably solder to the vacant crystal pads on a Nano. You basically have to make your own PCBs if you were going to use that original scheme.
Actually, the SPI idea might be useful. Imagine all your DACs share a clock line. Then you send out the clock for the SPI transfer and you have 16 different MOSI lines, to send the different data to each one. They all latch their output on the final clock, so they all change simultaneously, at least within a nanosecond or less.
You could do this with one Arduino. Manually write the SPI data to general digital pins. You don't need to do it especially fast. Most SPI devices tolerate a really really slow clock. You could make it a bit faster by using direct port writes to set 8 MOSI lines simultaneously but a proof-of-concept can use lots of digitalWrite() and it will probably work adequately well.
Do you?
How important is it that they are exactly simultaneous? Would a separation of 1uS be too much?
What is your sample rate?
Normally this will be way less than the acquisition rate. Why not sample all six signals as fast as possible and then go about sending them one at at time. Gather them up at the far end and then fire them out to your external D/As.