Intermediate
30 min

Drive a bipolar stepping motor easily with TB67S549FTG and STM32F042C6

Smooth motor drive operation

Stepper 12 Click with Fusion for STM32 v8

Published Mar 05, 2023

Click board™

Stepper 12 Click

Dev Board

Fusion for STM32 v8

Compiler

NECTO Studio

MCU

STM32F042C6

Accurate rotation angle and speed control using pulse signals

A

A

Hardware Overview

How does it work?

Stepper 12 Click is based on the TB67S549FTG, a two-phase bipolar stepping motor driver designed to control one bipolar stepping motor with resistorless current sensing owing to the built-in function of Advanced Current Detect System (ACDS) from Toshiba Semiconductor. The TB67S549FTG incorporates low on-resistance DMOS FETs, which can deliver a 1.5A maximum current with a motor output voltage rating of 40V and integrated protection mechanisms such as over-current, over-temperature, and under-voltage lockout for error detection (LO LED indicator). It supports full-step to 1/32 steps resolution for less motor noise and smoother control, with a built-in Advanced Dynamic Mixed Decay (ADMD) function that helps stabilize the current waveforms. Thanks to the many steps that TB67S549FTG supports, motor noise can be significantly reduced with smoother operation and more precise control. It is suited to various applications such as office automation and commercial and industrial equipment. The current value in the PWM constant-current mode is set by the reference voltage obtained by the MCP1501, a high-precision voltage regulator. Also, the current threshold point of the TB67S549FTG, alongside MCP1501, can be set manually using an onboard trimmer labeled VR.

In addition to the I2C communication, several GPIO pins connected to the mikroBUS™ socket pins are also used to forward the information to the MCU associated with the PCA9555A port expander. The PCA9555A also allows choosing the least significant bit (LSB) of its I2C slave address by positioning SMD jumpers labeled as ADDR SEL to an appropriate position marked as 0 and 1, alongside its interrupt feature routed to the INT pin of the mikroBUS™ socket. The CLK clock signal, routed to the PWM pin of the mikroBUS™ socket, shifts the current step and electrical angle of the motor with its every up-edge, while the Enable pin, labeled as EN and routed to the CS pin of the mikroBUS™ socket, controls the state of the output A and B stepping motor drive channels. The normal constant current control is started by turning the motor drive ON (HIGH level), while by setting the motor drive OFF, the outputs are turned high impedance because the MOSFETs are set to OFF (LOW level). Besides, all circuits can be stopped using the Sleep function and thus enable power saving mode. A simple DIR pin routed to the AN pin on the mikroBUS™ socket allows MCU to manage the direction of the stepper motor (clockwise or counterclockwise), while the RST pin of the mikroBUS™ socket

initializes an electrical angle in the internal counter to set an initial position. Achieving an initial position is indicated via onboard orange LED labeled as MO. A specific addition to this Click board™ is a multifunctional switch that allows the user, by selecting a particular switch, to set appropriate features such as 1 – Sleep Mode Activation; 2, 3 – Motor Torque Setting; 5 – Decay Control; 6, 7, 8 – Step Resolution Setting. In addition to this physical way of setting these functions, the user can select them digitally via the I2C interface. The Stepper 12 Click supports an external power supply for the TB67S549FTG, which can be connected to the input terminal labeled as VM and should be within the range of 4.5V to 34V, while the stepper motor coils can be connected to the terminals labeled as B+, B-, A-, and A+. 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.

stepper-12-click-hardware-overview

Features overview

Development board

Fusion for STM32 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 32-bit ARM® Cortex®-M based MCUs from STMicroelectronics, 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, Fusion for STM32 v8 provides a fluid and immersive working experience, allowing

access anywhere and under any circumstances at any time. Each part of the Fusion for STM32 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. Fusion for STM32 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.

Fusion for STM32 v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

48

RAM (Bytes)

6144

Used MCU Pins

mikroBUS™ mapper

Rotation Direction
PA0
AN
Electrical Angle Intilizing
PA15
RST
Enable
PB10
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Step Clock
PA7
PWM
Interrupt
PB0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

Stepper 12 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 Fusion for STM32 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 via UART Mode

1. Once the code example is loaded, pressing the "FLASH" button initiates the build process, and programs it on the created setup.

2. After the programming is completed, click on the Tools icon in the upper-right panel, and select the UART Terminal.

3. After opening the UART Terminal tab, first check the baud rate setting in the Options menu (default is 115200). If this parameter is correct, activate the terminal by clicking the "CONNECT" button.

4. Now terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART_Application_Output

Software Support

Library Description

This library contains API for Stepper 12 Click driver.

Key functions:

  • stepper12_set_direction This function sets the motor direction by setting the DIR pin logic state.

  • stepper12_drive_motor This function drives the motor for a specific number of steps at the selected speed.

  • stepper12_set_step_mode This function sets the step mode resolution settings.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief Stepper 12 Click example
 *
 * # Description
 * This example demonstrates the use of the Stepper 12 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 400 quarter
 * steps with 2 seconds delay before changing the direction. 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 "stepper12.h"

static stepper12_t stepper12;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    stepper12_cfg_t stepper12_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.
    stepper12_cfg_setup( &stepper12_cfg );
    STEPPER12_MAP_MIKROBUS( stepper12_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == stepper12_init( &stepper12, &stepper12_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( STEPPER12_ERROR == stepper12_default_cfg ( &stepper12 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    log_printf ( &logger, " Move 200 full steps clockwise \r\n\n" );
    stepper12_set_step_mode ( &stepper12, STEPPER12_MODE_FULL_STEP );
    stepper12_set_direction ( &stepper12, STEPPER12_DIR_CW );
    stepper12_drive_motor ( &stepper12, 200, STEPPER12_SPEED_FAST );
    Delay_ms ( 2000 );
    
    log_printf ( &logger, " Move 400 quarter steps counter-clockwise \r\n\n" );
    stepper12_set_step_mode ( &stepper12, STEPPER12_MODE_QUARTER_STEP );
    stepper12_set_direction ( &stepper12, STEPPER12_DIR_CCW );
    stepper12_drive_motor ( &stepper12, 400, STEPPER12_SPEED_FAST );
    Delay_ms ( 2000 );
}

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.