Encoder capable of compensating tilt, hard disk drive using the same, and servo track writing system for the hard disk drive

PURPOSE: An encoder, a hard disk drive thereof, and a servo track recording device thereof are provided to compensate for a slope between a moving scale and a fixed scale due to distortion which is generated when an object moves. CONSTITUTION: An encoder(100) includes a plurality of patterns, an optical transmission and receiving part(110), a slope compensating part, and an encoder control part(190). The plurality of patterns have different phases. The plurality of moving scales are a plurality of grating patterns which are arranged in parallel at a uniform phase difference. The optical transmission and receiving part transmits light to the fixed scale and the moving scale and receives light from the moving scale. The slope compensating part is arranged on either the transmitting path of light or the receiving path of light. The slope compensating part compensates for a slope which is generated between the fixed scale and the moving scale. The encoder control part controls the slope compensating part.