freq=20000
min_good=0
max_bad=0
direction=0
missed=0
while [ ${max_bad} -eq 0 -o ${missed} -eq 0 ]
do
  missed=`./testskew -qm ${freq} 1`
  if [ ${missed} -lt 1000 ]
  then
    freq=$((${freq} * 2))
  else
    max_bad=${freq}
    break
  fi
done
while [ ${min_good} -eq 0 -o ${max_bad} -eq 0 -o $((${max_bad} - ${min_good})) -gt 100 ]
do
  missed=`./testskew -qm ${freq} 1`
  if [ ${missed} -lt 10 ]
  then
    if [ ${direction} -eq 0 ]
    then
      direction=1
    fi
    min_good=${freq}
    freq=$((${min_good} + (${max_bad} - ${min_good}) / 2))
  else
    if [ ${direction} -eq 1 ]
    then
      direction=0
    fi
    max_bad=${freq}
    freq=$((${min_good} + (${max_bad} - ${min_good}) / 2))
  fi
done
echo ${min_good} "-" ${max_bad}

#!/bin/sh

freq=20000
min_good=0
max_bad=0
direction=0
missed=0
while [ ${max_bad} -eq 0 -o ${missed} -eq 0 ]
do
  missed=`./testskew -qS ${freq} 1 | sed 's|^-||'`
  if [ ${missed} -lt 1000 ]
  then
    freq=$((${freq} * 2))
  else
    max_bad=${freq}
    break
  fi
done
while [ ${min_good} -eq 0 -o ${max_bad} -eq 0 -o $((${max_bad} - ${min_good})) -gt 100 ]
do
  missed=`./testskew -qS ${freq} 1 | sed 's|^-||'`
  if [ ${missed} -lt 1000 ]
  then
    if [ ${direction} -eq 0 ]
    then
      direction=1
    fi
    min_good=${freq}
    freq=$((${min_good} + (${max_bad} - ${min_good}) / 2))
  else
    if [ ${direction} -eq 1 ]
    then
      direction=0
    fi
    max_bad=${freq}
    freq=$((${min_good} + (${max_bad} - ${min_good}) / 2))
  fi
done
echo ${min_good} "-" ${max_bad}

Make 1% cycles missed a threshold, rather than rely on cycle count.
Make 1% cycles missed a threshold, rather than rely on cycle count.
