time of digitalRead and digitalWrite

Hello!
How I can have a faster read and write for digital pin? I need to read one PWM and to invert it but the the original one goes up 100us before the inverted one goes down. and the opposite is the original one goes down 80us before the inve rted one goes up.
Any suggestion?

const byte photodiodo = 3; //signal converti de la photodiode
byte osservo = 7;

void setup()
{
  
  pinMode(osservo, OUTPUT);
  pinMode(photodiodo,INPUT);
}

void loop ()
{
if (digitalRead(photodiodo) == HIGH )
  { // se è premuto il pulsante
    PORTD &=~_BV(PD7);  // LOW
  }
  else
  {
    PORTD |= _BV(PD7); //high
  }
}

Try this to speed things up:

void loop () {
  while (true) {
    if (PIND & _BV(PD3))
      PORTD &= ~_BV(PD7); // LOW
    else
      PORTD |= _BV(PD7); //high
  }
}

Do it with external hardware - simple inverter chip.

6nS typical propagation delay, less than 1/10 of system clock (62.nS), practically instantaneous.

Thank you a lot for the answers!!!

if (digitalRead(photodiodo) == HIGH) //inverto il segnale fotodiodo
  {
    PORTD &= ~_BV(PD7); // LOW
  }
  else
  {
    TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00); //velocizzo la scrittura sulla porta1
    TCCR0B = _BV(CS00);
    PORTD |= _BV(PD7); //high
  }

If I write something like this I am going to have a lot of truble after with the timer?

I can't buy new component instrument at the moment :confused:

Hi,
Can you invert the signal before its transmitted by the IR source?
All you have is propagation delay, does it matter if the re-transmitted signal is 80us delayed?

Tom.... :slight_smile:

yes I can do it.
yeah it matters for the 80us delayed!
but the code written by johnwasser works! :slight_smile: Thank you all!