Measuring the RPM using Pulses

i tried refreshing the counter after the loop that is , put a statements counter =0, and duration =0; at the end but it didnt work

You don't want to unconditionally reset counter. Resetting duration is silly, since it is always value by the pulseIn() function.

You need to determine if it is time to reset counter. Look at the millis() function, and the blink without delay example to see how to time activities.