just like setInterval but based on frequency instead of period.