Example program for the TLE5012B magnetic 360° angle sensor.

Dependencies:   TLE5012B

Example program for the TLE5012B 360° angle sensor.

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 a SSC (aka 3-wire SPI) communication bus:

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



Used library:

Import libraryTLE5012B

Library for the TLE5012B magnetic 360° angle sensor.

main.cpp

Committer:
hudakz
Date:
2020-09-19
Revision:
2:e2300152c6c5
Parent:
1:f29ea5fe380f

File content as of revision 2:e2300152c6c5:

#include "mbed.h"
#include "TLE5012B.h"
//

using namespace TLE5012;

DigitalOut      led1(PC_13);
TLE5012B_SPI    tle5012b_spi(D11, D12, D13);    // mosi, miso, sck (spi connections to be shared by all devices)
TLE5012B        tle5012b(&tle5012b_spi, D10);   // shared spi bus, cs of this device
errorTypes      checkError = NO_ERROR;
Ticker          ticker;
volatile bool   tick = false;

/**
 * @brief
 * @note
 * @param
 * @retval
 */
void onTick()
{
    tick = true;
}

/**
 * @brief
 * @note
 * @param
 * @retval
 */
int main()
{
    int16_t aRaw = 0;
    int16_t sRaw = 0;
    int16_t tRaw = 0;

    double  a = 0.0;
    int16_t b = 0;
    double  r = 0.0;
    double  s = 0.0;
    double  t = 0.0;
    //

    checkError = tle5012b.begin(TLE5012B_S0);
    printf("\r\n");
    printf("checkError:\t%d\r\n", checkError);
#if MBED_MAJOR_VERSION < 6
    wait(1);
#else
    ThisThread::sleep_for(1s);
#endif
    printf("Init done\r\n");

    ticker.attach_us(onTick, 500 * 1000);   // 500ms

    while (1) {
        if (tick) {
            tick = false;
            led1 = !led1;
            tle5012b.getAngleValue(a, aRaw, UPD_LOW, SAFE_LOW);
            tle5012b.getNumRevolutions(b, UPD_LOW, SAFE_LOW);
            tle5012b.getAngleRange(r);
            tle5012b.getAngleSpeed(s, sRaw, UPD_LOW, SAFE_LOW);
            tle5012b.getTemperature(t, tRaw, UPD_LOW, SAFE_LOW);
            printf("Angle:\t\t%f°\r\n", a);
            printf("Revolution:\t%i\r\n", b);
            printf("Range:\t\t%f\r\n", r);
            printf("Speed:\t\t%f\r\n", s);
            printf("Temperature:\t%f°C\r\n", t);
            printf("----------------------\r\n");
        }
    }
}