Simultaneous Output - Arduino Mega1280

Hello,
I need to set 12 Outputs at the exact same moment in time.
Do i need to use an external latch which i "open" when every output is set or is this already on the arduino mega board?

I mean when i use 2 ports of the arduino it could be that the arduino sets up the first port in the first processor tact and the other one later, which would mean that it is not 100% simultaneous.

Please tell me if you could not understand my issue!

regards,
Flo

Use a device with latch, like hc595.

Yes, two 74HC595s. Shift 2 bytes into them, and use the same 'latch' signal to both so all 16 outputs update at the same time.

On the other hand, using Direct Port Manipulation, for example:

PORTC = B00001111;
PORTD = B11001100;

would only have tens of nanoseconds difference, or nearly simultaneous.
What is it you're driving?

Hi thanks for the fast answer,

I want to drive drum circuits...
is one port for itself 100 % simultaneous? so the first 8 drums would trigger at the super exact same point in time?

Nothing in this real world can get you to 100 percent simultaneous triggering. We can comfortably get you to 99.999999999999 percent without much difficulty. Or 99.999999999999999999999999999999999999 percent on a Pentagon budget.

Anyone telling you that they can do 100 percent is a liar or a fool (or both).

You have to make a decision for yourself if you can live with 99.9 or 99.99 percent. Of if it even makes a real life difference.

yes yes... but just for interest, is one port set with port manipulation as exact simultaneous as with a latch after ?

Yes, if they are on the same port.

Music drums? If striking 8 drums at once, I don't think you can hear a few uS of difference - not until you get up into low mS,like 2-3mS, will you start to hear it. I made a audio digital delay machine a few years ago, and it needed delay set at 5mS before echo started becoming apparent.
So two direct port writes a few instances of 62.5nS apart are going to sound instantaneuos.
Even 1000 clocks apart is 0.0625microseconds apart. That's 16 KHz.

So, first let's look at the genuine issue which has probably caused you to be concerned, put a number on it, then look at the arduino numbers.

Triggering instruments over MIDI, which is a serial protocol at 31250 baud with 1 start bit, 8 data bits and 1 stop bit, but no event clock worth speaking of, can introduce audible effects. To send 12 'simultaneous' note-on messages each of three bytes, takes

10 * 3 * 12 / 31250 = 11.5 ms.

That will be clearly visible on a scope in terms of transient smearing, may produce phase cancellation effects and may easily be audible.

Now lets look at sending two port out instructions, at a 16MHz clock, and to be charitable lets say that is 4 machine instructions (it is probably one but my connection in this hotel sucks so i can't easily check right now). The delay between the first set of 8 triggers and the second set of four is

4 / 16000000 = 250 ns

or 46 thousand times less than the MIDI delay. Or to put it another way, if your DAW is running at 96kHz sampling rate, the delay is less than 1/40th of one sample.

Okay these facts are compelling = )

I just thought that the resonances/addition of the very short transients in the beginning of a punching sound might be weaker if there is more delay because the transient of the first knocking sound is over when the last channel gets triggered if you know what i mean.
but anyways if the first 8 channels of the sequencer are at least the mega exact i can later check if i can hear any difference which i dont believe because of the calculation you made.

Thanks again!
Flo

No drum has a zero rise time to peak sound - they all have an attack, sustain, and decay.
You can use a microphone and this PC oscilloscope software to see this

I did it when I was designing a sampled electronic drum set in the late 80's.
No sound goes from off to peak in tens of nanoseconds.

yes, in my case a Roland tr808 instruments i cloned are triggered. the peaks are delayed by that time but anyways these circuits are by far not so exact that the it is sencefull to talk about these little times.