In the implemenation, you act on the counter at every transition of either A or B, thus following X4 encoding. And you should choose the encoder type of direction for Channel A leading B or B leading A. The detail algorithm implementation is illustrated as below: