How to measure pulsewidth ratio

Hi, I would like to measure voltage and pulsewidth ratio at a frequency around 100Hz in my car in order to calculate the RSM out of it.

How to measure voltage is not an issue. Calculating the RMS is as well easy. But I do not have a idea how to measure the pulsewidth ratio. My first idea was to measure 10 data and take the mean out of it, but this is not very accurate. It would be ideal to measure 1 cycle of PWM only and calculate the ratio out of that.

Can anyone get me in the right direction how to attack the issue??

You can use pulseIn to get the information:

pulseIn with a HIGH value will return the duration of the high going pulse. Calling pulseIn again with a LOW value will return the duration of the next low pulse. pulseIn does not start measuring until it can get a complete pulse so the consecutive calls will be be measuring consecutive pulses so this technique is only suitable if the timing change between consecutive pulses is relatively.

If the frequency is stable, you can infer the ratio by measuring only HIGHs or only LOWs, but you'd still need to measure the frequency accurately first.

Thanks for the hints. Now I know what direction to go to!