Intermediate
20 min

Control two-phase bipolar stepper motors with TB67S128FTG and STM32F407VGT6

Microstepping bipolar stepper motor driver

Stepper 10 Click with Clicker 4 for STM32F4

Published Mar 09, 2024

Click board™

Stepper 10 Click

Dev. board

Clicker 4 for STM32F4

Compiler

NECTO Studio

MCU

STM32F407VGT6

High-power motor control from full- to 1/128 micro-steps with advanced performance optimization and error detection features

A

A

Hardware Overview

How does it work?

Stepper 10 Click is based on the TB67S128FTG, a two-phase bipolar stepper motor driver from Toshiba Semiconductor, which features adjustable current limiting and micro-stepping down to 1/128 step operation. Fabricated using a leading-edge BiCD process with low power consumption and low output on-resistance, the TB67S128FTG in a thermally enhanced small package helps improve efficiency and reduce the size of motor applications. This stepping motor driver incorporates a high-speed, high-precision control technology required for factory automation systems and office equipment. The chip can dynamically select an optimal decay mode by monitoring the actual motor current and automatically reduce the driving current below the full amount when the motor is lightly loaded to minimize power consumption and heat generation. The driver has a wide operating voltage range of 6.5V to 44V and can continuously deliver approximately 2.1A per phase without a heat sink or forced air flow (up to 5A peak). It features built-in protection against under-voltage, over-current, and over-temperature

conditions. There are two interface modes to select from: CLK mode for simple step and direction control and serial mode for controlling and setting the driver through a serial interface. Step resolution is configurable using MODE2, MODE1, and MODE0 by setting the appropriate pin level. Most pins are controlled using an IO expander via the I2C bus except DIR, STEP, ENABLE, and RESET routed to the mikroBUS™ socket. Stepper 10 Click has eight different step modes: full-step, half-step, 1/4-step, 1/8, 1/16, 1/32, 1/64, and 1/128. Besides that, four different decay modes are available using the MDT0 and MDT1 pins. The onboard trimmer potentiometer can be used to set the current limit to prevent damage to the motor. The actual calculation of the predefined output current can be found in the TB67S128FTG datasheet. Toshiba’s unique AGC feature stepping motor technology optimizes the drive current according to the load torque in real-time. It helps reduce unnecessary currents and drastically cut power consumption and heat generation. Stepper 10 Click has the function to detect several error states indicated by two

LEDs: LO1 and LO0. If the overcurrent is detected, the LO0 will toggle, while the LO1 represents the motor load open indication. If both LEDs are toggled, then the thermal shutdown is detected. The errors are cleared by toggling standby mode or performing a power cycle to the driver. The LED designated as MO is toggled if the driver’s electrical angle is equal to the initial value of 45°, which occurs immediately after reset or whenever the driver has stepped a full cycle. Stepper 10 Click uses the two TCA9534APWR Low-Power IO Expanders that support the I2C interface protocol. To avoid conflicts on the bus, the slave addresses can be reconfigured by SMD jumpers labeled ADDR1 and ADDR2. 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. Also, this 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.

Stepper 10 Click hardware overview image

Features overview

Development board

Clicker 4 for STM32F4 is a compact development board designed as a complete solution that you can use to quickly build your own gadgets with unique functionalities. Featuring an STM32F407VGT6 MCU, four mikroBUS™ sockets for Click boards™ connectivity, power management, and more, it represents a perfect solution for the rapid development of many different types of applications. At its core is an STM32F407VGT6 MCU, a powerful microcontroller by STMicroelectronics based on the high-performance

Arm® Cortex®-M4 32-bit processor core operating at up to 168 MHz frequency. It provides sufficient processing power for the most demanding tasks, allowing Clicker 4 to adapt to any specific application requirements. Besides two 1x20 pin headers, four improved mikroBUS™ sockets represent the most distinctive connectivity feature, allowing access to a huge base of Click boards™, growing on a daily basis. Each section of Clicker 4 is clearly marked, offering an intuitive and clean interface. This makes working with the

development board much simpler and, thus, faster. The usability of Clicker 4 doesn’t end with its ability to accelerate the prototyping and application development stages: it is designed as a complete solution that can be implemented directly into any project, with no additional hardware modifications required. Four mounting holes [4.2mm/0.165”] at all four corners allow simple installation by using mounting screws.

Clicker 4 for STM32F4 double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

10

Silicon Vendor

STMicroelectronics

Pin count

100

RAM (Bytes)

100

You complete me!

Accessories

The 28BYJ-48 is an adaptable 5VDC stepper motor with a compact design, ideal for various applications. It features four phases, a speed variation ratio of 1/64, and a stride angle of 5.625°/64 steps, allowing precise control. The motor operates at a frequency of 100Hz and has a DC resistance of 50Ω ±7% at 25°C. It boasts an idle in-traction frequency greater than 600Hz and an idle out-traction frequency exceeding 1000Hz, ensuring reliability in different scenarios. With a self-positioning torque and in-traction torque both exceeding 34.3mN.m at 120Hz, the 28BYJ-48 offers robust performance. Its friction torque ranges from 600 to 1200 gf.cm, while the pull-in torque is 300 gf.cm. This motor makes a reliable and efficient choice for your stepper motor needs.

Stepper 10 Click accessories image

Used MCU Pins

mikroBUS™ mapper

Direction Control
PC4
AN
Reset
PC15
RST
Motor Output Enable
PA4
CS
SPI Clock
PA5
SCK
NC
NC
MISO
SPI Data IN
PA7
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Step Clock Input
PE9
PWM
Interrupt
PD0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB10
SCL
I2C Data
PB11
SDA
Power supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Stepper 10 Click Schematic schematic

Step by step

Project assembly

Clicker 4 for STM32F4 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 4 for STM32F4 as your development board.

Clicker 4 for STM32F4 front image hardware assembly
LTE IoT 5 Click front image hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
Board mapper by product6 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for Stepper 10 Click driver.

Key functions:

  • stepper10_set_direction - This function sets the motor direction by setting the DIR pin logic state

  • stepper10_set_step_mode - This function sets the step mode resolution settings

  • stepper10_drive_motor - This function drives the motor for the specific number of steps at the selected speed

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 main.c
 * @brief Stepper 10 Click example
 *
 * # Description
 * This example demonstrates the use of the Stepper 10 Click board by driving the 
 * motor in both directions for a desired number of steps.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the Click default configuration.
 *
 * ## Application Task
 * Drives the motor clockwise for 200 full steps and then counter-clockiwse for 200 half
 * steps and 400 quarter steps with 2 seconds delay on driving mode change. All data is
 * being logged on the USB UART where you can track the program flow.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "stepper10.h"

static stepper10_t stepper10;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    stepper10_cfg_t stepper10_cfg;  /**< Click config object. */

    /** 
     * 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.
    stepper10_cfg_setup( &stepper10_cfg );
    STEPPER10_MAP_MIKROBUS( stepper10_cfg, MIKROBUS_1 );
    err_t init_flag = stepper10_init( &stepper10, &stepper10_cfg );
    if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( STEPPER10_ERROR == stepper10_default_cfg ( &stepper10 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    log_printf ( &logger, " Move 200 full steps clockwise, speed: slow\r\n\n" );
    stepper10_set_direction ( &stepper10, STEPPER10_DIR_CW );
    stepper10_set_step_mode ( &stepper10, STEPPER10_MODE_FULL_STEP );
    stepper10_drive_motor ( &stepper10, 200, STEPPER10_SPEED_SLOW );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );

    log_printf ( &logger, " Move 200 half steps counter-clockwise, speed: medium\r\n\n" );
    stepper10_set_direction ( &stepper10, STEPPER10_DIR_CCW );
    stepper10_set_step_mode ( &stepper10, STEPPER10_MODE_HALF_STEP );
    stepper10_drive_motor ( &stepper10, 200, STEPPER10_SPEED_MEDIUM );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );

    log_printf ( &logger, " Move 400 quarter steps counter-clockwise, speed: fast\r\n\n" );
    stepper10_set_direction ( &stepper10, STEPPER10_DIR_CCW );
    stepper10_set_step_mode ( &stepper10, STEPPER10_MODE_QUARTER_STEP );
    stepper10_drive_motor ( &stepper10, 400, STEPPER10_SPEED_FAST );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ 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.