Copy D8-D13 to D2-D7

Hello all.

I need to do a test validation for something which, if it succeeds, will probably made with hardware.

In short, I have 6 input pulse signals (from an encoder) which I need to put, as quickly as possible, in 6 outputs.
Doing the digitalWrite(....digitalRead(...)) 6x is probably too slow. Is there a faster way to do it?

Thanks

Which processor?

aarg:
Which processor?

Thank you for your quick reply. I'm using a small nano (328P)

In short, I have 6 input pulse signals (from an encoder) which I need to put, as quickly as possible, in 6 outputs.

Six lengths of wire.

Yes, D8-D13 are just PB0-PB5 and D2-D7 are just PD2-PD7. So you can do a port read of PORTB, shift left twice and do a port write to PORTD (first reading and masking the bits for PD0 and PD1 to preserve their values).

TheMemberFormerlyKnownAsAWOL:
Six lengths of wire.

That's it! I wish I thought of that before :slight_smile:

Now imagine that I need to do some kind of signal coupling and that I would like to test it with an arduino before I go with hardware components that I would still need to buy. Do you see a way to do it with my nano and my breadboard?

aarg:
Yes, D8-D13 are just PB0-PB5 and D2-D7 are just PD2-PD7. So you can do a port read of PORTB, shift left twice and do a port write to PORTD.

Thank you. I will try it.

aarg:
Yes, D8-D13 are just PB0-PB5 and D2-D7 are just PD2-PD7. So you can do a port read of PORTB, shift left twice and do a port write to PORTD (first reading and masking the bits for PD0 and PD1 to preserve their values).

That worked perfectly (with some surprises - reading PORTB always returns 0, but PINB works just fine).

while(1)
{
  tempB = (PINB & B00111111) << 2;
  tempD = PIND & B00000011;
  PORTD = tempD | tempB;
}

Here's why I need this: The original encoder signal has a minimum value of ~~1V and a maximum of ~~4V. I need it to have 0-5V. I needed to test if the equipment which must receive this encoder signal works with 0-5V, because it was not working with 1-4V. It does work :slight_smile:
IMG_0522.JPG
CH1: original signal (sorry for the interferences)
CH2: output on the nano.

At maximum input frequency (51,2kHz) there is a small delay (around 1us) from the input to the output signal but, as far as I could see, it's constant so not a problem.

Thank you very much for your help

IMG_0522.JPG

Don't forget that clock interrupts are going to introduce jitter.