Hi All,

In the previous blog2 we have created the GPIO example with LED blinking demo for XMC4200. In this blog we going to

interfacing TLE94112El H-Bridge driver with XMC4200.

 

Take a look into TLE94112 user manual , It has 12 half bridge outputs , can be configured as LOW or HIGH or HZ.

each output drives the maximum of 900mA current. for more details look read the UM.

 

Requirements:

In our case we are going to drive a 12V DC motor pump. The Motor is rated to 350mA. we going to combine two of the outputs (OUT1 & OUT2) and connecting to

negative side of motor. Also we enable the PWM channel for OUT1 and OUT2 with frequency of 200HZ.

All these requirements we are going to configure on TLE94112 via SPI commands.

 

SPI Interface:

we are going to add SPI drivers in our GPIO LED project, I noted one thing in DAVE IDE, could not rename the project (->feedback to infineon-> Rename feature is important  )

An SPI example project is found under XMC4300 ->  XMC_Peripheral_Library_v2.1.24\XMCLib\examples\XMC4300_series

We use this project as a reference to port into XMC4200.

 

Its a bit tricky to add or link the existing files from the source folder. (feedback -> infineon -< i request them to allow right click option to add /link existing .c/.h files )

 

 

SPI Pins:

As per the H-Bridge shield board we chooses these pins for XMC4200

 

SCLKP1_8
MOSIP1_9
CSP1_7
MISOP0_0
EN  P0_11

 

SPI Initialization & Configuration:

SPI Mode - 10 - CLK_POL = 0 , CLK_PHA =  1;

SPI baud - 1 MHZ

SPI Bit Order - LSB 1st

XMC_SPI_CH_SetFrameLength(SPI_CH, 16U);
XMC_SPI_CH_SetWordLength(SPI_CH, 8U);
XMC_SPI_CH_SetBitOrderLsbFirst(SPI_CH);
/* Configure the clock polarity and clock delay */    
XMC_SPI_CH_ConfigureShiftClockOutput(SPI_CH, XMC_SPI_CH_BRG_SHIFT_CLOCK_PASSIVE_LEVEL_0_DELAY_ENABLED,
                                               XMC_SPI_CH_BRG_SHIFT_CLOCK_OUTPUT_SCLK);

/* Establish Slave Select signal polarity */
XMC_SPI_CH_SetSlaveSelectPolarity(SPI_CH, XMC_SPI_CH_SLAVE_SEL_INV_TO_MSLS);
/* Enable the Slave Select 0 Signal */
XMC_SPI_CH_EnableSlaveSelect(SPI_CH, XMC_SPI_CH_SLAVE_SELECT_2);

XMC_USIC_CH_TXFIFO_Configure(SPI_CH, 0U, XMC_USIC_CH_FIFO_SIZE_8WORDS, 0U);

XMC_GPIO_SetMode(CS, XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P1_7_AF_U1C1_SELO2);
XMC_GPIO_SetMode(SCLK, XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P1_8_AF_U1C1_SCLKOUT);
XMC_GPIO_SetMode(MOSI, XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P1_9_AF_U1C1_DOUT0);

 

Just check with DSO or Analyzer to confirm SPI communication is proper,

Now we can send the SPI (two bytes) commands to the H-Bridge Shield board.

H-Bridge Configuration:

I have created my own version of driver to setup.

refer the datasheet to know about register and bytes configuration.

 

As i told earlier we are intrested only in OUT1 and OUT , so i have configured the below registers with PWM

void tle_configHB_LS12(uint8_t value, uint8_t pwm_mode)
{
    uint8_t spiframe[2]={0};

    spiframe[0] = HB_ACT_1_CTRL | 0x80;
    spiframe[1] = value |  value<<2;
    spi_write_buffer(spiframe,2);

    spiframe[0] = HB_MODE_1_CTRL | 0x80;
    spiframe[1] = pwm_mode | pwm_mode<<2;
    spi_write_buffer(spiframe,2);

}

 

The DC motor +Ve and Shield board BAT Pin is connected with +9V of Battery. OU1 and OUT2 lines are combined and connected to the  -Ve of DC motor.

To communicate with the h-bridge , the EN pin shou be at high state.

 

Running the Motor:

To start the motor with PWM, its necessary to have high PWM value to get high torque.

tle_init(); /* reset all the register by writing 0x00 */
tle_configHB_LS12(1,1);
tle_setpwmModFreq(0, 0, 3);
tle_setpwm1(250);

 

Now the motor starts with PWM value of 250, Inside the systick isr I'm gradually decreasing to level 30 and rising to 250

Observation:

In my case at a speed of 30 PWM -> Motor rotates slowly but could not pump the water.

The motor is rated for 350mA but I could not drive with a single OUT which is capable of 900mA.

 

The working video is here -> Embedded Club

meet you all on the next blog with some more updates.