Skip to content
Miniature rotation-speed, angle and magnetic-field sensor

Projects / Measurements, sensors and data acquisition

Magnetic rotation and angle sensor

Compact TLV493D/STM32L4 sensor for 3-axis magnetic field, angle and rotation speed, with USB/UART, filtering, calibration and saved settings.

Task

What had to be solved

The task was to make a small universal sensor that could be used not only as a magnetometer but also as a rotation sensor. One device had to combine 3D magnetic-sensor polling, angle calculation, rotation-speed measurement, turn counting and a simple setup interface without a separate user application.

Result

What the project reached

The project was brought to working STM32L4 firmware. The sensor is polled over I2C, data is processed in firmware and transmitted through USB CDC or UART. The user can select measurement mode, output rate, speed units, filtering level and transmission interface. Settings are stored in microcontroller Flash memory.

Miniature rotation-speed, angle and magnetic-field sensor
Rotation-speed, angle and magnetic-field sensor without enclosure

Project materials

Photos and working materials

Back view of the rotation-speed, angle and magnetic-field sensor
Rotation-speed, angle and magnetic-field sensor measuring angle during rotation
Rotation-speed, angle and magnetic-field sensor measuring magnetic field during rotation

Video

Short demonstration

A short recording of the device or test bench in operation.

Engineering context

Important constraints

The device uses a TLV493D 3D magnetic sensor and communicates with it over I2C.

The internal polling cycle is designed for rates up to 2 kHz.

The firmware supports raw magnetic field, calibrated magnetic field, angle and rotation-speed modes.

Angle is calculated from two magnetic-field axes, while crossing the 180-degree boundary is handled by a turn counter.

Data can be transmitted over USB CDC or UART, and service information is sent through both interfaces.

Operating parameters can be changed with text commands and saved to Flash.

Work done

What was included

Polling of the TLV493D 3D magnetic sensor over I2C.

Calculation of magnetic field values on X, Y and Z axes.

Angle calculation from magnetic-field data.

Turn counter with full-rotation boundary handling.

Rotation-speed calculation in RPM or revolutions per second.

Data transmission modes over USB CDC and UART.

Text command protocol for device setup.

Configurable signal filtering.

Calibration procedure using two rotation directions.

Checks for read, write and sensor-state errors.

Storage of operating parameters in Flash memory.

Details

Engineering project description

Measurement modes

The firmware includes output modes for magnetic field, calibrated magnetic field, angle and rotation speed. In angle mode the device outputs the current angle and turn counter. In speed mode it calculates rotation speed, which can be output in RPM or revolutions per second.

Interfaces and commands

The device is configured with text commands over USB or UART. The help command prints built-in reference information. Commands can select operating mode, output period, transmission interface, UART speed, speed units, filter level, turn-counter reset, settings save and factory-default restore.

Filtering and calibration

Several filtering levels are provided for magnetic-field and speed signals: no filter, fast, medium and slow modes. Calibration is performed in two passes with rotation in different directions. The firmware checks for insufficient magnetic-field level and sensor saturation, then calculates offsets and normalization coefficients for X and Y axes.

Settings and operation

After setup, parameters can be saved to Flash memory so the device starts in the required configuration immediately after power-up. This matters for autonomous use when the sensor must operate without manual reconfiguration after each start.

Contact

Discuss your engineering task

Contact us by email. We discuss custom electronics and automation tasks remotely with companies, labs, small businesses and individual customers worldwide.