PWM tester - display frequency/duty cycle of input pin

Here's a little sketch I knocked up to compare the frequency / duty cycle figures from my multimeter (Mastech MS8268). I did this because I have just built this square wave generator:
PWM - Pulse Width Modulation for DC Motor Speed and LED Brightness - Robot Room and I was getting some odd results (almost certainly due to my inexperience)

You can test it by connecting either pin 5 or pin 9 to input pin 7. Pin 5 should show about 1kHz, with pin 9 giving about 500Hz. In both cases the DC should be about 75% (the figure of 192 in the code...192/255= 75ish). It's not 100% accurate as it doesn't account for the time taken in the calls to pulseIn and its nigh-on impossible to start the pulseIn exactly at the same time as a rising (or falling) edge, but its within 1% or so of my meter (is THAT accurate?)

once that looks good, feed you unknown square wave to pin 7

the code takes samples and averages them to get a more accurate result
the sampling starts off by doing a dummy pulseIn to get as close as possible to a transition
then it counts how long the pin is HIGH
next it counts how long the pin is LOW
adding the two gives the total time of one cycle, which is added to the running total
totaltime is then averaged
the duty cycle is thre proportion of the total time that the signal is HIGH
(dividing into 1000000 [10-6] is because pulseIn returns microseconds [10-6 seconds] and freq =1/t

int PIN = 7;      // PWM input signal
int SELFTEST= 9;  // loopbacl @ approx 500Hz
int FASTEST= 5;  // loopback @ approx 1kHz

unsigned long hightime;
unsigned long lowtime;
unsigned long totaltime;
unsigned long totalhightime;
int SAMPLE= 500;

void setup()
{
  pinMode(PIN, INPUT);
  pinMode(SELFTEST,OUTPUT);
  pinMode(FASTEST,OUTPUT);
  analogWrite(SELFTEST,192);
  analogWrite(FASTEST,192);
  Serial.begin(115200);
}

void loop()
{
  totaltime=0;
  totalhightime=0;
  for(int i=0;i<SAMPLE;i++){
    pulseIn(PIN,LOW);
    hightime = pulseIn(PIN, HIGH);
    lowtime = pulseIn(PIN, LOW); // now low
    totaltime+=hightime + lowtime;
    totalhightime+=hightime;
    }
  totaltime/=SAMPLE;
  
  Serial.print((float) 1000000 / (totaltime));
  Serial.print("Hz @ ");
  Serial.print((float) ((float) (totalhightime / SAMPLE) * 100 / totaltime));
  Serial.println("% duty");

  Serial.println(" ");
  
  delay(1000);
  }