What to use instead of PulseIn?

Hi everybody, I am using pulse in

void loop()
{
  incomingSignal = analogRead(A0) >> 2;//get new value from A0
  analogWrite(3, incomingSignal); //transmit the signal with a  PWM 
  
 voltage = ((pulseIn(A4, LOW) * 100) / T) >> 1;
 [code]


 /*I read the duration of the low pulse of the PWM in A4 I multiply it by 100 and I divided it for the period of the PWM in order to obtain the dutycycle.
*/ 
 [code]

 voltage = map(constrain(voltage, 0, 100), 0, 100, 0, 255);
 [code]


/*Then I constrain and map the dutycicle in order to have the same number that the ADC gave me before putting all in the dac. */

  [code]
 dac.output(voltage);

  }

My problem is when I am sending a square wave PulseIn block arduino and it takes one second or more to create a PWM after the ADC conversion.

Do you know how can I do same things without pulseIn? I read about interrups but I don't know how to use them Thank you a lot!

My problem is when I am sending a square wave PulseIn block arduino and it takes one second or more to create a PWM after the ADC conversion.

Say what? The pulseIn() function times how long it takes a digital pin to change state. That has NOTHING to do with PWM or ADC.

There may be some confusion here.

Can you explain what you are trying to do? I think what you may need is to count frequency rather than pulseIn(), but very hard to tell you anything without understanding the context.

The pulseIn() is blocking the rest of the sketch.

Yes there is an answer. It is to learn to make event-driven code which is easier than it sounds to those who don't.

You start with some form of the BlinkWithoutDelay Example to learn to use time events to trigger actions while not blocking execution and then move on to other triggers and the state machine concept.

In my signature space below are links to 3 blogs that explain the keys to that plus interrupts very simply.

y what? The pulseIn() function times how long it takes a digital pin to change state. That has NOTHING to do with PWM or ADC.

Off course I know that. PulseIn is measureing always a PWM going out from pin 3 trasmitted by a LED and received by a Photodiodo.

What I am saying is that IF my PWM it is the digitalization of a square wave (I read a squarewave in the input A0)

The pulseIn() is blocking the rest of the sketch.

Yes there is an answer. It is to learn to make event-driven code which is easier than it sounds to those who don't.

with sinusoid, or anykind of signal that are not square wave this block doesn't happen!!!

So, I will learn how to use interrupt...

In my signature space below are links to 3 blogs that explain the keys to that plus interrupts very simply.

I don't see other solution.. Thank!!!!

Well, I found a soultion easy and lazy (I will learn how to use interrupts when I will do another project :) ). I just add the timeout of 1280ms like the periodo of my PWM and it is working how I wanted. not

The pulseIn() is blocking the rest of the sketch.

Yes there is an answer. It is to learn to make event-driven code which is easier than it sounds to those who don't.

anymore!

I perfectly know the difference betwen ADC, PWM and PulseIn. my head is not confused like maybe the words that I use to explain what is going on.

GOFORSMOKE understood what was going on! thank for the link of the interrupts1 i will study it I promise :D And thank guys PaulS and marco_c. everytime somebody tells me that I can't understand or I am confusing my brain works faster XD this arduino forum is the best!! keep going with the good work! Viva arduino!! :D