Library for the TLE5012B magnetic 360° angle sensor.

Dependents:   TLE5012B_Hello

This is a Mbed port of the TLE5012B-Angle-Sensor Arduino library.

TLE5012B

200


The TLE5012B is a 360° angle sensor that detects the orientation of a magnetic field. This is achieved by measuring sine and cosine angle components with monolithic integrated Giant Magneto Resistance (iGMR) elements. These raw signals (sine and cosine) are digitally processed internally to calculate the angle orientation of the magnetic field (magnet). The TLE5012B is a pre-calibrated sensor. The calibration parameters are stored in laser fuses. At start-up the values of the fuses are written into flip-flops, where these values can be changed by the application-specific parameters. Further precision of the angle measurement over a wide temperature range and a long lifetime can be improved by enabling an optional internal autocalibration algorithm. Data communications are accomplished with a bi-directional Synchronous Serial Communication (SSC) that is SPI-compatible. The sensor configuration is stored in registers, which are accessible by the SSC interface.

A bi-directional Synchronous Serial Communication (SSC) Interface (aka 3-wire SPI) is used for the communication. The TLE5012B has a single pin for Data input and and Data output. This pin is connected to the Mbed's SPI MOSI and MISO pins using a series/pull-up resistor as proposed for the 3-wire SPI by Wim Huiskamp.

Wiring of the 8MHz SSC (aka 3-wire SPI) communication:

https://os.mbed.com/media/uploads/hudakz/tle5012b_wiring02.png


Example program:

Import programTLE5012B_Hello

Example program for the TLE5012B magnetic 360° angle sensor.

Committer:
hudakz
Date:
Sat Sep 19 18:49:44 2020 +0000
Revision:
1:220a2496380e
Parent:
0:4b76b1dc05cd
Library for the TLE5012B Giant Magneto Resistance (GMR) based angle sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:4b76b1dc05cd 1 /*!
hudakz 0:4b76b1dc05cd 2 * \name TLE5012B_SPI.h - Mbed port of Arduino library for the TLE5012B angle sensor.
hudakz 0:4b76b1dc05cd 3 * \author Infineon Technologies AG (Dr.Olaf Filies)
hudakz 0:4b76b1dc05cd 4 * \copyright 2019 Infineon Technologies AG
hudakz 0:4b76b1dc05cd 5 * \version 2.0.1
hudakz 0:4b76b1dc05cd 6 * \brief GMR-based angle sensor for angular position sensing in automotive applications
hudakz 0:4b76b1dc05cd 7 * \details Ported to Mbed by Zoltan Hudak 2020-08
hudakz 0:4b76b1dc05cd 8 *
hudakz 0:4b76b1dc05cd 9 * The TLE5012B is a 360° angle sensor that detects the orientation of a magnetic field.
hudakz 0:4b76b1dc05cd 10 * This is achieved by measuring sine and cosine angle components with monolithic integrated
hudakz 0:4b76b1dc05cd 11 * Giant Magneto Resistance (iGMR) elements. These raw signals (sine and cosine) are digitally
hudakz 0:4b76b1dc05cd 12 * processed internally to calculate the angle orientation of the magnetic field (magnet).
hudakz 0:4b76b1dc05cd 13 * The TLE5012B is a pre-calibrated sensor. The calibration parameters are stored in laser fuses.
hudakz 0:4b76b1dc05cd 14 * At start-up the values of the fuses are written into flip-flops, where these values can be changed
hudakz 0:4b76b1dc05cd 15 * by the application-specific parameters. Further precision of the angle measurement over a wide
hudakz 0:4b76b1dc05cd 16 * temperature range and a long lifetime can be improved by enabling an optional internal autocalibration
hudakz 0:4b76b1dc05cd 17 * algorithm. Data communications are accomplished with a bi-directional Synchronous Serial Communication (SSC)
hudakz 0:4b76b1dc05cd 18 * that is SPI-compatible. The sensor configuration is stored in registers, which are accessible by the
hudakz 0:4b76b1dc05cd 19 * SSC interface. Additionally four other interfaces are available with the TLE5012B: Pulse-Width-Modulation (PWM)
hudakz 0:4b76b1dc05cd 20 * Protocol, Short-PWM-Code (SPC) Protocol, Hall Switch Mode (HSM) and Incremental Interface (IIF). These interfaces
hudakz 0:4b76b1dc05cd 21 * can be used in parallel with SSC or alone. Pre-configured sensor derivates with different interface settings are available.
hudakz 0:4b76b1dc05cd 22 * Online diagnostic functions are provided to ensure reliable operation.
hudakz 0:4b76b1dc05cd 23 *
hudakz 0:4b76b1dc05cd 24 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
hudakz 0:4b76b1dc05cd 25 * following conditions are met:
hudakz 0:4b76b1dc05cd 26 *
hudakz 0:4b76b1dc05cd 27 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
hudakz 0:4b76b1dc05cd 28 * disclaimer.
hudakz 0:4b76b1dc05cd 29 *
hudakz 0:4b76b1dc05cd 30 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
hudakz 0:4b76b1dc05cd 31 * disclaimer in the documentation and/or other materials provided with the distribution.
hudakz 0:4b76b1dc05cd 32 *
hudakz 0:4b76b1dc05cd 33 * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
hudakz 0:4b76b1dc05cd 34 * products derived from this software without specific prior written permission.
hudakz 0:4b76b1dc05cd 35 *
hudakz 0:4b76b1dc05cd 36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
hudakz 0:4b76b1dc05cd 37 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
hudakz 0:4b76b1dc05cd 38 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
hudakz 0:4b76b1dc05cd 39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
hudakz 0:4b76b1dc05cd 40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
hudakz 0:4b76b1dc05cd 41 * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
hudakz 0:4b76b1dc05cd 42 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hudakz 0:4b76b1dc05cd 43 *
hudakz 0:4b76b1dc05cd 44 */
hudakz 0:4b76b1dc05cd 45 #ifndef TLE5021B_SPI_H
hudakz 0:4b76b1dc05cd 46 #define TLE5021B_SPI_H
hudakz 0:4b76b1dc05cd 47
hudakz 0:4b76b1dc05cd 48 #include "mbed.h"
hudakz 0:4b76b1dc05cd 49
hudakz 0:4b76b1dc05cd 50 class TLE5012B_SPI
hudakz 0:4b76b1dc05cd 51 {
hudakz 0:4b76b1dc05cd 52 DigitalInOut _mosi;
hudakz 0:4b76b1dc05cd 53 DigitalOut _sck;
hudakz 0:4b76b1dc05cd 54 SPI _spi;
hudakz 0:4b76b1dc05cd 55
hudakz 0:4b76b1dc05cd 56 inline void writeBit(int value);
hudakz 0:4b76b1dc05cd 57 inline int readBit();
hudakz 0:4b76b1dc05cd 58 void write(uint16_t word);
hudakz 0:4b76b1dc05cd 59 uint16_t read();
hudakz 0:4b76b1dc05cd 60
hudakz 0:4b76b1dc05cd 61 public:
hudakz 0:4b76b1dc05cd 62
hudakz 0:4b76b1dc05cd 63 TLE5012B_SPI(PinName mosi, PinName miso, PinName sck);
hudakz 0:4b76b1dc05cd 64
hudakz 0:4b76b1dc05cd 65 void begin(DigitalOut* cs);
hudakz 0:4b76b1dc05cd 66 void triggerUpdate();
hudakz 0:4b76b1dc05cd 67 void sendReceiveSpi(DigitalOut*, uint16_t* txData, uint16_t txLen, uint16_t* rxData, uint16_t rxLen);
hudakz 0:4b76b1dc05cd 68 };
hudakz 0:4b76b1dc05cd 69
hudakz 0:4b76b1dc05cd 70 #endif // TLE5021B_INT_H