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?

  • yes the data should be able to change if you are using the analog write function it will change the waves immediately so you will see a change immediately .
    – xbox gamer
    Commented Jun 9, 2021 at 4:31

1 Answer 1


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.

  • the PWM sets the duty cycle on an SMPS device, this in turn would effect the voltage and currents I am measuring. I am worried that the duty cycle would not change in time and hence this means the third line of the code there would not read the changed current and voltage values( A,B)
    – fred
    Commented Jun 9, 2021 at 22:45
  • I am unable to find timing information to be able to investigate this or find anything to draw an accurate conclusion.
    – fred
    Commented Jun 9, 2021 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.