Square wave generator and frequency meter

Also i think wavegenerator is the wrong function, because when i plug freq meter to pin which has analogWrite on it it gives me exactly 490hz or 980hz depending on pin which i use for analogWrite.