Intermediate
30 min

Unlock the full potential of your DC motors with TLE9201SG and ATmega3250

Experience the next-level motor control

H-Bridge 3 Click with UNI-DS v8

Published Jul 25, 2023

Click board™

H-Bridge 3 Click

Dev Board

UNI-DS v8

Compiler

NECTO Studio

MCU

ATmega3250

With our H-Bridge motor driver solution, you can effortlessly control the rotation and torque of your DC motors, allowing for smooth and precise movement in robotics, automation, and more

A

A

Hardware Overview

How does it work?

H-Bridge 3 Click is based on the TLE9201SG, an H-Bridge DC motor driver, with up to 28V and 6A, from Infineon. This IC is an efficient integrated H-bridge driver with a low RDS ON output per switch. H-bridge, in general, allows the current to flow in one or another direction. All internal supply voltages are derived from the external VIN connector. A charge pump provides the gate voltage for the high-side switches. The output buffer of the digital output SO is supplied by the pin VSO. Therefore the output logic level at SO can be easily configured for 3.3 V or 5 V logic by moving the VCC SEL jumper to the respective voltage. The output stages consist of four n-channel MOSFETs in an H-bridge configuration.

The outputs are protected against short circuits and over-temperature.  The bridge is controlled using the inputs PWM and DIR. The signal at DIR defines the direction of the driven DC motor, whereas the PWM signal sets the duty cycle. The outputs can be set tristate (i.e., high side and low side switches are turned off) by setting DIS to a high level. The TLE9201SG is equipped with a “Serial Peripheral Interface“ (SPI) for diagnosis purposes. The H-bridge 3 click is configured as a “slave” device. This means that the host microcontroller, as the master, is providing the chip select (CS) and the clock signal (SCK). A data transfer on the SPI bus is initiated with a falling edge on CS and is terminated by a rising edge

on CS. The serial input pin SI data is sampled with the falling edge of SCK, and the rising clock edge determines the serial data output at MISO. The data is transferred “MSB first. The word length of the SPI is 8-bit. Please note that there is no check for the number of clocks within an SPI frame. Any low pulse at the CS line will be regarded as one frame. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. However, the Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used, as a reference, for further development.

H-Bridge 3 Click hardware overview image

Features overview

Development board

UNI-DS v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports a wide range of microcontrollers, such as different STM32, Kinetis, TIVA, CEC, MSP, PIC, dsPIC, PIC32, and AVR MCUs regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer over WiFi. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, UNI-DS v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the UNI-DS v8 development board contains the components necessary for the most efficient operation of the same board. An advanced integrated CODEGRIP programmer/debugger module offers many valuable programming/debugging options, including support for JTAG, SWD, and SWO Trace (Single Wire Output)), and seamless integration with the Mikroe software environment. Besides, it also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector. Communication options such as USB-UART, USB

HOST/DEVICE, CAN (on the MCU card, if supported), and Ethernet is also included. In addition, it also has the well-established mikroBUS™ standard, a standardized socket for the MCU card (SiBRAIN standard), and two display options for the TFT board line of products and character-based LCD. UNI-DS v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

UNI-DS v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

2048

You complete me!

Accessories

DC Gear Motor - 430RPM (3-6V) represents an all-in-one combination of a motor and gearbox, where the addition of gear leads to a reduction of motor speed while increasing the torque output. This gear motor has a spur gearbox, making it a highly reliable solution for applications with lower torque and speed requirements. The most critical parameters for gear motors are speed, torque, and efficiency, which are, in this case, 520RPM with no load and 430RPM at maximum efficiency, alongside a current of 60mA and a torque of 50g.cm. Rated for a 3-6V operational voltage range and clockwise/counterclockwise rotation direction, this motor represents an excellent solution for many functions initially performed by brushed DC motors in robotics, medical equipment, electric door locks, and much more.

H-Bridge 3 Click accessories image

Used MCU Pins

mikroBUS™ mapper

Direction Control
PF0
AN
Output Disable
PG0
RST
SPI Chip Select
PG1
CS
SPI Clock
PB1
SCK
SPI Data OUT
PB3
MISO
SPI Data IN
PB2
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Speed Control
PB4
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

H-Bridge 3 Click Schematic schematic

Step by step

Project assembly

Fusion for PIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI-DS v8 as your development board.

Fusion for PIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
v8 SiBRAIN Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

Software Support

Library Description

This library contains API for H-Bridge 3 Click driver.

Key functions:

  • hbridge3_set_duty_cycle - This function sets the PWM duty cycle

  • hbridge3_spi - This function sends SPI command and receives response to command sent

  • hbridge3_generic_transfer - Generic SPI transfer, for sending and receiving packages

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file 
 * @brief HBridge3 Click example
 * 
 * # Description
 * H-bridge in general, allows the current to flow in one or another direction.
 * This click is used for driving a H-Bridge motor by changing output states. 
 * The outputs can be pulse width modulated at frequencies up to 20kHz by means of PWM/DIR control. 
 * 
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes SPI and LOG modules, AN, RST, CS and PWM pins
 * 
 * ## Application Task  
 * This example demonstrates the use of H-Bridge 3 Click board, 
 * by running dc motor in both directions - increasing and decreasing PWM duty cycle.
 * Results are being sent to the Usart Terminal where you can track their changes.
 * 
 * 
 * @author Nikola Peric
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "hbridge3.h"

// ------------------------------------------------------------------ VARIABLES

static hbridge3_t hbridge3;
static log_t logger;
uint8_t motor_direction = 0;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    hbridge3_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    hbridge3_cfg_setup( &cfg );
    HBRIDGE3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    hbridge3_init( &hbridge3, &cfg );
    Delay_ms( 500 );
    
    hbridge3_pwm_start( &hbridge3 );
    log_info( &logger, "---- Application Task ----" );
    log_printf( &logger, "> CLOCKWISE <\r\n" );
}

void application_task ( void )
{
    static int8_t duty_cnt = 1;
    static int8_t duty_inc = 1;
    float duty = duty_cnt / 10.0;


    hbridge3_set_duty_cycle ( &hbridge3, duty );
    log_printf( &logger, " Duty: %d%%\r\n", ( uint16_t )( duty_cnt * 10 ) );
    Delay_ms( 500 );

    if ( 10 == duty_cnt ) 
    {
        duty_inc = -1;
    }
    else if ( 0 == duty_cnt ) 
    {
        duty_inc = 1;
        
        if ( motor_direction == 1 )
        {
            log_printf( &logger, "> COUNTER CLOCKWISE <\r\n" );
            motor_direction = 0;
             hbridge3_dir_set ( &hbridge3 , 0 );
        }
        else if ( motor_direction == 0 )
        {
            log_printf( &logger, "> CLOCKWISE <\r\n" );
            motor_direction = 1;
            hbridge3_dir_set ( &hbridge3 , 1 );
        }
    }
    duty_cnt += duty_inc;
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.