TLE5012B SSC in the TLE9879 evalboard

Announcements

Measure CO2 When It Matters - Infineon’s XENSIV™ PAS CO2 now comes in SparkFun Red. Check it now!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
raymond7
Level 1
Level 1
10 sign-ins 5 sign-ins First reply posted

I am trying to use TLE5012 SSC in the TLE9879 evalboard. I used the code from "https://community.infineon.com/t5/MOTIX-MCU/Tle5012b-ssc-via-tle987x-evalboard/td-p/298415" .

Here is the waveform.

yellow - SPI chip select

Light blue - SPI Data

Purple - SPI Clock

raymond7_0-1672939697577.png

Sending a command(0x8020) in the 1st SPI clock looks good.  but received data (2nd, 3rd SPI clock) have low voltage. Is it normal? angleValue is always same even though I turn the motor manually. The value is 0.351562. fixed. What is wrong?  What should I do more to find a right angle value?

raymond7_1-1672940543106.png

raymond7_2-1672940929899.png

 

#include "tle_device.h"
#include "eval_board.h"


double calculateAngleSpeed(double angRange, int16_t rawAngleSpeed, uint16_t firMD, uint16_t predictionVal);
uint8_t crcCalc(uint8_t* crcData, uint8_t length);
double angleValue=0;
uint8_t crc8(uint8_t *data, uint8_t length);
uint8_t getSecondByte(uint16_t twoByteWord);
uint8_t getFirstByte(uint16_t twoByteWord);
void enableSensor();
void disableSensor();
enum errorTypes getAngleValue();
enum errorTypes readFromSensor(uint16_t command, uint16_t *data);


int16_t rawAnglevalue=0;
uint16_t rawData = 0, status_global=0, old_rawData=0;
uint16_t new_angle_value=0;

/************************************************** ***************************/
/** SSC1: sends one byte (0xAA) as SPI master @ 1 Mbaud **/
/************************************************** ***************************/
/** program SSC1 to operate at 1 Mbaud **/
/** SSC1 sends one byte at P0.3 (CLK), P0.2 (MTSR) **/
/************************************************** ***************************/

#define TLE5012B_H

// Sensor registers
#define READ_SENSOR 0x8000 //!< base command for read
#define WRITE_SENSOR 0x5000 //!< base command for write
#define READ_BLOCK_CRC 0x8088 //!< initialize block CRC check command

 

#define SYSTEM_ERROR_MASK 0x4000 //!< System error masks for safety words
#define INTERFACE_ERROR_MASK 0x2000 //!< Interface error masks for safety words
#define INV_ANGLE_ERROR_MASK 0x1000 //!< Angle error masks for safety words

#define CRC_POLYNOMIAL 0x1D //!< values used for calculating the CRC
#define CRC_SEED 0xFF
#define CRC_NUM_REGISTERS 0x0008 //!< number of CRC relevant registers
#define MAX_REGISTER_MEM 0x0030 //!< max readable register values buffer

#define DELETE_BIT_15 0x7FFF //!< Value used to delete everything except the first 15 bits
#define CHANGE_UINT_TO_INT_15 0x8000 //!< Value used to change unsigned 16bit integer into signed
#define CHECK_BIT_14 0x4000 //!<
#define GET_BIT_14_4 0x7FF0 //!<

#define DELETE_7BITS 0x01FF //!< values used to calculate 9 bit signed integer sent by the sensor
#define CHANGE_UNIT_TO_INT_9 0x0200 //!< Value used to change unsigned 9bit integer into signed
#define CHECK_BIT_9 0x0100

#define POW_2_15 32768.0 //!< values used to for final calculations of angle speed, revolutions, range and value
#define POW_2_7 128.0 //!<
#define ANGLE_360_VAL 360.0

#define TEMP_OFFSET 152.0 //!< values used to calculate the temperature
#define TEMP_DIV 2.776

//!< Prints a binary number with leading zeros (Automatic Handling)
#define PRINTBIN(Num) for (uint32_t t = (1UL<< (sizeof(Num)*8)-1); t; t >>= 1) Serial.write(Num & t ? '1' : '0');

//!< Prints a binary number with leading zeros (Automatic Handling) with space
#define PRINTBINS(Num) for (uint32_t t = (1UL<< (sizeof(Num)*8)-1); t; t >>= 1) Serial.write(Num & t ? " 1 " : " 0 ");

/*!
* Error types from safety word
*/
enum errorTypes
{
NO_ERROR = 0x00, //!< NO_ERROR = Safety word was OK
SYSTEM_ERROR = 0x01, //!< SYSTEM_ERROR = over/under voltage, VDD negative, GND off, ROM defect
INTERFACE_ACCESS_ERROR = 0x02, //!< INTERFACE_ACCESS_ERROR = wrong address or wrong lock
INVALID_ANGLE_ERROR = 0x03, //!< INVALID_ANGLE_ERROR = NO_GMR_A = 1 or NO_GMR_XY = 1
ANGLE_SPEED_ERROR = 0x04, //!< ANGLE_SPEED_ERROR = combined error, angular speed calculation wrong
CRC_ERROR = 0xFF //!< CRC_ERROR = Cyclic Redundancy Check (CRC), which includes the STAT and RESP bits wrong
};

/*!
* Set the UPDate bit high (read from update buffer) or low (read directly)
*/
enum updTypes
{
UPD_low = 0x0000, //!< read normal registers
UPD_high = 0x0400, //!< read update buffer registers
};

/*!
* Switch on/off safety word generation
*/
enum safetyTypes
{
SAFE_low = 0x0000, //!< switch of safety word generation
SAFE_high = 0x0001, //!< switch on safety word generation
};

uint8_t mMOSI; //!< Pin for SPI MOSI (pin 0.6 on test board);
uint8_t mMISO; //!< Pin for SPI MISO (pin 0.7 on test board)
uint8_t mSCK; //!< Pin for CLOCK (pin 0.8 on test board)
uint8_t mCS; //!< Pin for chip select (pin 0.9 on test board)

uint16_t data;
uint16_t _command1; //!< command write data [0] = command [1] = data to write
uint16_t _command2; //!< command write data [0] = command [1] = data to write
uint16_t _received[MAX_REGISTER_MEM] = {0}; //!< fetched data from sensor with last word = safety word
uint16_t _registers[CRC_NUM_REGISTERS]; //!< keeps track of the values stored in the 8 _registers, for which the CRC is calculated

int main(void)
{
/************************************************** ***************************
** initialization of the hardware modules based on the configuration done **
** by using the IFXConfigWizard **
************************************************** ***************************/
TLE_Init();

disableSensor();
Delay_us(5000);


for (;;)
{
WDT1_Service();
getAngleValue();
}
}

enum errorTypes getAngleValue()
{
enum errorTypes status = readFromSensor(0x0020, &rawData);

status_global = status;
if (status != NO_ERROR)
{
return (status);
}
// new_angle_value = (rawData & 0x8000) >> 15;
old_rawData = rawData;
rawData = (rawData & DELETE_BIT_15); // bit 15 represents a new value if it is 1

//check if the value received is positive or negative
if (rawData & CHECK_BIT_14) // CHECK_BIT_14 is 0x4000
{
rawData = rawData - CHANGE_UINT_TO_INT_15; // CHANGE_UINT_TO_INT_15 is 0x8000
}
rawAnglevalue = rawData;
angleValue = (ANGLE_360_VAL / POW_2_15) * ((double) rawAnglevalue);

return (status);
}

enum errorTypes readFromSensor(uint16_t command, uint16_t *data)
{
enum errorTypes checkError = NO_ERROR;

_command1 = READ_SENSOR | command | UPD_low | SAFE_low;
// 0x8000 | 0x0020 | 0x0000 | 0x0000

enableSensor();
PORT_ChangePinAlt(0x11,0x0); // SPI chip selected
Delay_us(1);

SSC1_SendWord(_command1);
Delay_us(20); // write read delay(twr_delay) is min 130ns

SSC1_SendWord(0x0000);
_received[0]=SSC1_ReadWord();
Delay_us(20);

SSC1_SendWord(0x0000);
_received[1]=SSC1_ReadWord();
Delay_us(20);

disableSensor();

PORT_ChangePinAlt(0x11,0x1); // SPI chip disabled
Delay_us(100);

*data = _received[0];
Delay_us(1000);

if (true)
{
// checkError = checkSafety(_received[1], _command1, &_received[0], 1);
if (checkError != NO_ERROR)
{
// data = 0;
}
}

checkError=NO_ERROR;
return (checkError);
}

void enableSensor()
{
PORT_P11_Output_Low_Set();
}

void disableSensor()
{
PORT_P11_Output_High_Set();
//digitalWrite(mCS, low);
}

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Adithya_S
Moderator
Moderator
Moderator
100 sign-ins First question asked 50 replies posted

Hi Raymond,

Thank you for your patience.

Here, I am attaching a basic project code, in which a command is sent from the master and the sensor on receiving the command sends out the angle value over the SPI Data line.

You can use the above code and integrate it in your final application code. I am also attaching the snapshots of the motix configuration wizard for your reference.

Hope this helps.

Thanks and regards,

Adithya

View solution in original post

0 Likes
6 Replies
Adithya_S
Moderator
Moderator
Moderator
100 sign-ins First question asked 50 replies posted

Dear Valued Infineon Customer,

Thank you for reaching us out.

Looking into your query, I went through your code and attached snippets.

I would like to ask you few questions:

1) Is the communication between the controller and the sensor established?

2) Has the sensor not responded to this particular command or it is behaving the same for other commands also?

If you have not tried for other commands, can you please check once.

The function readFromSensor(), where the command is sent from the micro-controller to the sensor for retrieving data seems good, but still the sensor is not responding. I guess there may be some issues in software side.

Therefore, I request you to share the project code for better understanding. It is not very much clear looking into the text.

Also, please share the schematics or pin connection between the controller and the sensor.

Thanks and Regards,

Adithya

0 Likes

Hi Adithya, 

I am not sure SSC communication is eatablished. but 5012b chip is generating pulse signals on IFA, IFB pins when I turn the motor manually. Sensor is resonding the same way whenever I changed a command. It is a beginning stage to detect motor angle so I shared all code. I'm using TLE9879 evalkit. You can find a schematic from https://www.infineon.com/dgdl/Infineon-TLE987_Evalkit-UserManual-v01_04-EN.pdf?fileId=5546d462776229...

raymond7_0-1673040189935.png

Thank you,

Raymond

0 Likes
Adithya_S
Moderator
Moderator
Moderator
100 sign-ins First question asked 50 replies posted

Hi Raymond,

Thank you for your patience.

It took some time to replicate the whole setup inhouse. 

while I was working on your problem, few points I observed was, the example which you are using for your reference,"Tle5012b ssc via tle987x evalboard" and also in your code, I could not find the sensor initialization function.

While working with your code, I also received the same kind of waveform on SPI data line as you have received. I feel the sensor is not responding appropriately because of lack of sensor initialization function. Could you please check in your project whether this initialization function is present or not.

Also, I am sharing with you Github project for TLE5012B, you can use this as a reference for sensor initialization, if not present in your code.

https://github.com/Infineon/TLE5012-Magnetic-Angle-Sensor

Hope this helps.

Thanks and Regards,

Adithya

0 Likes

Hi Adithya,

 

I agree with you. Sensor is not responding with some reason.

The example code, TLE9879QXA40_SSC1_TO_SSSC2 (TLE9879 EvalKit) in the Pack installer, is working well. so TLE9879 doesn't have any problem. 

I am not familiar with Aduino. but I can find a initialization function (begin();) in the readAngleTest.ino. begin() function looks like a hardware initialization where I can set the values in Config Wizard for MOTIX MCU of TLE9879.  I think that begin() function in the Aduino is same as SSC1_INIT() which is defined in TLE_Init() in the TLE9879.

TLE5012B must be initialized and ready to communicate with SSC1_INIT() function. but it's not working. I don't know what else I can do. 

 

raymond7_0-1674830344787.png

raymond7_1-1674830399157.png

Thank you, 

Raymond

0 Likes
lock attach
Attachments are accessible only for community members.
Adithya_S
Moderator
Moderator
Moderator
100 sign-ins First question asked 50 replies posted

Hi Raymond,

Thank you for your patience.

Here, I am attaching a basic project code, in which a command is sent from the master and the sensor on receiving the command sends out the angle value over the SPI Data line.

You can use the above code and integrate it in your final application code. I am also attaching the snapshots of the motix configuration wizard for your reference.

Hope this helps.

Thanks and regards,

Adithya

0 Likes

Hi Adithya, 

New code is working well after removing 15bit. 

void readSensorAngle(void)
{
//uint16 ret;
PORT_P11_Output_Low_Set();
SSC1_SendWord(0x8020);

//PORT_P02_OpenDrain_En();
angval = SSC1_SendWord(0xFFFF);

// remove 15 bit
angval = angval & (0x7FFF);

//PORT_P02_OpenDrain_Dis();
PORT_P11_Output_High_Set();

//return angval;
}

raymond7_0-1676328261707.png

Thanks a lot,

Raymond

0 Likes