Patent ID: 8476579

Claim:
A method of dynamically adjusting gain and offset in an optical encoder, the method comprising: providing an encoder disk comprising a diffraction grating; illuminating the encoder disk with light; providing a detector structured to detect light diffracted from the diffraction grating and output a first fine count channel; calculating a first target gain and first target offset for the first fine count channel; and applying a correction to data sampled from the first fine count channel based on the first target gain and first target offset; wherein calculating the first target gain and the first target offset includes: determining a minimum value and maximum value in a set of data from the first fine count channel; calculating a moving average minimum based on the minimum value and minimum values from a plurality of prior sets of data from the first fine count channel; calculating a moving average maximum based on the maximum value and maximum values from the plurality of prior sets of data from the first fine count channel; calculating the first target gain according to the equation G cal =(ave_max A −ave_min A )/2, where G cal is the first target gain, ave_max A is the moving average maximum, and ave_min A is the moving average minimum; and calculating the first target offset according to the equation OFFSET cal =(ave_max A +ave_min A )/2, where OFFSET cal is the first target offset.