modulo-n counter