I will try to make it more explicit with an example. Imagine we have a microcontroller Atmega328P and one of its pin is set as output pin. And when we investigate about it we find that max current a pin can source is 40mA.
Now we also know that the average current through a resistive load is (PW/T)*(V/R) where PW is pulse width T is period of the PWM and V is 5V and R is 62 Ohm.
Now if PW = T the current becomes 80mA. But if PW = 0.2*T the current becomes 16 mA. But in the second case if PWM is 10 seconds and T is 50 seconds, it is still not okay.
So my question is how can we know the max peak current for known duration? I hope it is clear what Im asking. If we take average we conclude 16 mA is fine but it seems if PW is not short enough the current will be 80mA. Is there a relationship between PW and max current ratings?