Beginner
10 min

Manage the operation of two-phase bipolar stepper motors with TB67S269FTG and PIC18F27K42

Two-phase bipolar stepping motor driver using a PWM chopper

Stepper 4 click with EasyPIC v8

Published Mar 26, 2024

Click board™

Stepper 4 click

Dev. board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18F27K42

User-friendly solution for controlling bipolar stepper motors featuring advanced technologies that ensure efficient, precise, and noiseless operation

A

A

Hardware Overview

How does it work?

Stepper 4 Click is based on the TB67S269FTG, a bipolar stepper motor driver IC with a translator section from Toshiba Semiconductor. This highly integrated IC offers a very simple bipolar stepper motor control interface, thanks to the integrated translator section. This section controls the output drivers, providing smooth action of the stepper motor. By controlling the current intensity and its decay throughout the rotation cycle, a constant torque is achieved for every position. This IC features a high-efficiency motor current control mechanism (Advanced Dynamic Mixed Decay), which results in the optimal ripple while regulating the motor current. The current is limited by the value of the sensing resistor and a reference voltage at the VREF pins. It is possible to adjust the reference voltage via the onboard potentiometer labeled as torque from 0V to 3.3V, changing the current limit through the motor coils, thus changing the torque. The absolute current limit on this IC is 2A, after which the overcurrent protection is activated. A LOW to HIGH transition

(rising edge) on the CLK pin of the TB67S269FTG IC will perform one rotational step. The direction of the rotation is controlled by the logic state on the CW/CCW pin (routed to the mikroBUS™ AN pin, labeled as DIR). The step size is determined by three pins: DMODE0, DMODE1, and DMODE2. It is possible to work with seven movement step sizes, ranging from full to 1/32 step size. These pins are routed to the DIP switch labeled as STEP MODE, allowing step size to be selected by moving each of them. The ENABLE pin allows the host MCU to turn on or off the output stages of the TB67S269FTG IC. Asserting this pin to a HIGH logic level enables the output stage. The RESET pin is used to reset the electrical angle to the initial position and is active at HIGH. The ENABLE pin is routed to the CS (labeled as EN), while the RESET pin is routed to the RST pin of the mikroBUS™, allowing the host MCU to control the IC via these pins. The TB67S269FTG offers monitoring of the electrical angle and fault condition signaling. These two pins are routed to the SMD jumper labeled as INT SEL.

While in the MO position, the angle monitoring pin will be routed to the mikroBUS™ INT pin. If the jumper is set at the LO position, it will route the LO pin to the INT pin of the mikroBUS™, allowing faulty conditions, such as thermal or overcurrent failure, to be reported. These pins feature a pull-up resistor and will have a LOW logic level when asserted. This Click board™ can be interfaced with 3.3V and 5V MCUs, thanks to an SMD jumper labeled VCC SEL. It is enough to move the SMD jumper to the appropriate position (3V3 or 5V), and the logic voltage level of the communication signals will be properly set for both types of MCUs. The Click board™ is equipped with the input and output screw terminals. The terminal labeled TB1 on the schematic connects the external power supply, which should stay in the range from 10V to 35V. The stepper motor can be connected securely via the TB2 and TB3 screw terminals, with their input terminals labeled as A+, A-, and B+, B-.

Stepper 4 click hardware overview image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. 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, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board 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 DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC 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.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

28

RAM (Bytes)

8192

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 4 click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Direction Control
RA3
AN
Reset
RA0
RST
Chip Enable
RA5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Step Trigger
RC1
PWM
Angle Monitor / Error Detection
RB1
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
2

Take a closer look

Click board™ Schematic

Stepper 4 click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v8 as your development board.

EasyPIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v8 Access DIPMB 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 DIP 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

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 4 Click driver.

Key functions:

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

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

  • stepper4_reset_device - This function resets the device by toggling the RST pin

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 4 Click Example.
 *
 * # Description
 * This example demonstrates the use of the Stepper 4 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 steps and then counter-clockiwse for 100 steps with
 * 2 seconds delay before changing the direction.
 * Each step will be logged on the USB UART where you can track the program flow.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "stepper4.h"

static stepper4_t stepper4;   /**< Stepper 4 Click driver object. */
static log_t logger;    /**< Logger object. */

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    stepper4_cfg_t stepper4_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.
    stepper4_cfg_setup( &stepper4_cfg );
    STEPPER4_MAP_MIKROBUS( stepper4_cfg, MIKROBUS_1 );
    if ( DIGITAL_OUT_UNSUPPORTED_PIN == stepper4_init( &stepper4, &stepper4_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    stepper4_default_cfg ( &stepper4 );
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    log_printf ( &logger, " Move 200 steps clockwise \r\n\n" );
    stepper4_set_direction ( &stepper4, STEPPER4_DIR_CW );
    stepper4_drive_motor ( &stepper4, 200, STEPPER4_SPEED_FAST );
    Delay_ms ( 2000 );
    
    log_printf ( &logger, " Move 100 steps counter-clockwise \r\n\n" );
    stepper4_set_direction ( &stepper4, STEPPER4_DIR_CCW );
    stepper4_drive_motor ( &stepper4, 100, STEPPER4_SPEED_FAST );
    Delay_ms ( 2000 );
}

int main ( void ) 
{
    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.