user77576: I am using the Arduino Nano every. Take this example where I am measuring two things A and B.
Loop{// this loop runs once every second
    //Read A,B
    //Change something using analogueWrite which would effect A,B values
    //Read A,B
}

Would the analogueWrite values have changed fast enough such that the third line would read the new and changed A,B values?

user7508: The Arduino Nano Every does not have analog outputs. The function
analogWrite() uses PWM as an ersatz of analog output. As soon as the
function returns, you know that the timer registers controlling the PWM
feature have been set to the proper duty cycle. The timer, however, will
complete the current PWM cycle using the previous settings. Only when
this cycle is over will it use the updated settings for the next one.
Completing the current cycle can take up to 2 ms.
Now, I wonder how the PWM cycle can have any effect on what you are
measuring. If you expect to measure something that depends on the
apparent “analog” value you are outputting, this can only work if your
circuit contains (or behaves like) a low-pass filter. In order to
convert the PWM to an analog value, the filter's time constant has to be
significantly longer than the PWM period. This in turn will cause a
corresponding lag, so your readings will take roughly one filter's time
constant to catch up with the value you are outputting.
Note that all this has absolutely nothing to do with how fast the
Arduino executes code.

77576: <p>I am using the Arduino Nano every. Take this example where I am measuring two things A and B.</p>
<pre class="lang-cpp prettyprint-override"><code>Loop{// this loop runs once every second
    //Read A,B
    //Change something using analogueWrite which would effect A,B values
    //Read A,B
}
</code></pre>
<p>Would the <code>analogueWrite</code> values have changed fast enough such that the third line would read the new and changed A,B values?</p>
 7508: <p>The Arduino Nano Every does not have analog outputs. The function
<code>analogWrite()</code> uses PWM as an ersatz of analog output. As soon as the
function returns, you know that the timer registers controlling the PWM
feature have been set to the proper duty cycle. The timer, however, will
complete the current PWM cycle using the previous settings. Only when
this cycle is over will it use the updated settings for the next one.
Completing the current cycle can take up to 2 ms.</p>
<p>Now, I wonder how the PWM cycle can have any effect on what you are
measuring. If you expect to measure something that depends on the
apparent “analog” value you are outputting, this can only work if your
circuit contains (or behaves like) a low-pass filter. In order to
convert the PWM to an analog value, the filter's time constant has to be
significantly longer than the PWM period. This in turn will cause a
corresponding lag, so your readings will take roughly one filter's time
constant to catch up with the value you are outputting.</p>
<p>Note that all this has absolutely nothing to do with how fast the
Arduino executes code.</p>
