PWM shunt current measurement

Hello,

I want to ask new, because the main question could be confusing.

The situation:

There's a pwm driven Motor. On the high side current is measured with a shunt and the corresponding voltage is amplified with an opamp circuit to 0,2 - 4V. This voltage goes to the ain input of the arduino.

So, you know that pwm current isn't smooth so the simplest measurement method is to measure at the right time -> if the digital port of the pwm driver is high.

Now my question again:

Is there a function (or any way) to call to find out that the digital port (pwm driven) is just now high?

Also I could take some true rms ics like the AD636. I won't need it because I don't need any absolute measurements here.

The 3rd method would be to measure like the ad636:

Vrms = (Avg * ( Vin^2) )^(1/2)

Any code suggestions?

Thanks!