A
magnetic field sensor for measuring a direction of a
magnetic field in a plane comprises a sensing structure comprising a ring-shaped well, a plurality of contacts of
equal size placed at equal distance from each other along the ring-shaped well, and an
electronic circuit comprising a plurality of electronic switches associated with the contacts of the sensing structure, a
logic block for controlling the electronic switches, at least one
current source, a means for measuring a difference between a first
voltage and a second
voltage, a timing circuit providing a
control signal for controlling the
logic block and providing a reference
signal, wherein the
logic block is adapted to close and open the electronic switches under the control of the
control signal according to a predetermined scheme such that a predetermined number of contacts of the plurality of contacts form a vertical
Hall element that is supplied with current from the at least one
current source and that has two contacts connected to the means for measuring, and such that the vertical
Hall element is moved in steps along the ring-shaped well, and a means for measuring a phase shift between the reference
signal and an output
signal of the
voltage measuring means.