A Giant MagnetoResistance(GMR) sensor was selected to design a magnetic encoder based on STM32 microcontroller. Dual orthogonal voltagesignals were generated by four GMR sensors which were orthogonally placed in the bottom of a columned magnet. And the two voltage signals were filtered and amplified through conditioning circuit, and converted into digital signals in STM32 chip. Rotational angle value would be accurately displayed after determined the quadrant, lookup table and performed arithmetic operation. And the output of the magnetic encoder can be flexible to choose as needed. The results showed that the magnetic encoder had a high detection accuracy and realtime.