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.

Committer:
hudakz
Date:
Sat Sep 19 18:50:19 2020 +0000
Revision:
2:e2300152c6c5
Parent:
1:f29ea5fe380f
Example program for the TLE5012B Giant Magneto Resistance (GMR) based angle sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:0a652123777c 1 #include "mbed.h"
hudakz 0:0a652123777c 2 #include "TLE5012B.h"
hudakz 0:0a652123777c 3 //
hudakz 0:0a652123777c 4
hudakz 0:0a652123777c 5 using namespace TLE5012;
hudakz 0:0a652123777c 6
hudakz 0:0a652123777c 7 DigitalOut led1(PC_13);
hudakz 0:0a652123777c 8 TLE5012B_SPI tle5012b_spi(D11, D12, D13); // mosi, miso, sck (spi connections to be shared by all devices)
hudakz 0:0a652123777c 9 TLE5012B tle5012b(&tle5012b_spi, D10); // shared spi bus, cs of this device
hudakz 0:0a652123777c 10 errorTypes checkError = NO_ERROR;
hudakz 0:0a652123777c 11 Ticker ticker;
hudakz 0:0a652123777c 12 volatile bool tick = false;
hudakz 0:0a652123777c 13
hudakz 0:0a652123777c 14 /**
hudakz 0:0a652123777c 15 * @brief
hudakz 0:0a652123777c 16 * @note
hudakz 0:0a652123777c 17 * @param
hudakz 0:0a652123777c 18 * @retval
hudakz 0:0a652123777c 19 */
hudakz 0:0a652123777c 20 void onTick()
hudakz 0:0a652123777c 21 {
hudakz 0:0a652123777c 22 tick = true;
hudakz 0:0a652123777c 23 }
hudakz 0:0a652123777c 24
hudakz 0:0a652123777c 25 /**
hudakz 0:0a652123777c 26 * @brief
hudakz 0:0a652123777c 27 * @note
hudakz 0:0a652123777c 28 * @param
hudakz 0:0a652123777c 29 * @retval
hudakz 0:0a652123777c 30 */
hudakz 0:0a652123777c 31 int main()
hudakz 0:0a652123777c 32 {
hudakz 0:0a652123777c 33 int16_t aRaw = 0;
hudakz 0:0a652123777c 34 int16_t sRaw = 0;
hudakz 0:0a652123777c 35 int16_t tRaw = 0;
hudakz 0:0a652123777c 36
hudakz 0:0a652123777c 37 double a = 0.0;
hudakz 0:0a652123777c 38 int16_t b = 0;
hudakz 0:0a652123777c 39 double r = 0.0;
hudakz 0:0a652123777c 40 double s = 0.0;
hudakz 0:0a652123777c 41 double t = 0.0;
hudakz 0:0a652123777c 42 //
hudakz 0:0a652123777c 43
hudakz 0:0a652123777c 44 checkError = tle5012b.begin(TLE5012B_S0);
hudakz 0:0a652123777c 45 printf("\r\n");
hudakz 0:0a652123777c 46 printf("checkError:\t%d\r\n", checkError);
hudakz 0:0a652123777c 47 #if MBED_MAJOR_VERSION < 6
hudakz 0:0a652123777c 48 wait(1);
hudakz 0:0a652123777c 49 #else
hudakz 0:0a652123777c 50 ThisThread::sleep_for(1s);
hudakz 0:0a652123777c 51 #endif
hudakz 0:0a652123777c 52 printf("Init done\r\n");
hudakz 0:0a652123777c 53
hudakz 1:f29ea5fe380f 54 ticker.attach_us(onTick, 500 * 1000); // 500ms
hudakz 0:0a652123777c 55
hudakz 0:0a652123777c 56 while (1) {
hudakz 0:0a652123777c 57 if (tick) {
hudakz 0:0a652123777c 58 tick = false;
hudakz 0:0a652123777c 59 led1 = !led1;
hudakz 0:0a652123777c 60 tle5012b.getAngleValue(a, aRaw, UPD_LOW, SAFE_LOW);
hudakz 0:0a652123777c 61 tle5012b.getNumRevolutions(b, UPD_LOW, SAFE_LOW);
hudakz 0:0a652123777c 62 tle5012b.getAngleRange(r);
hudakz 0:0a652123777c 63 tle5012b.getAngleSpeed(s, sRaw, UPD_LOW, SAFE_LOW);
hudakz 0:0a652123777c 64 tle5012b.getTemperature(t, tRaw, UPD_LOW, SAFE_LOW);
hudakz 0:0a652123777c 65 printf("Angle:\t\t%f°\r\n", a);
hudakz 0:0a652123777c 66 printf("Revolution:\t%i\r\n", b);
hudakz 0:0a652123777c 67 printf("Range:\t\t%f\r\n", r);
hudakz 0:0a652123777c 68 printf("Speed:\t\t%f\r\n", s);
hudakz 0:0a652123777c 69 printf("Temperature:\t%f°C\r\n", t);
hudakz 0:0a652123777c 70 printf("----------------------\r\n");
hudakz 0:0a652123777c 71 }
hudakz 0:0a652123777c 72 }
hudakz 0:0a652123777c 73 }