Intermediate
20 min

Deliver smooth and accurate stepper motor motion with DRV8452 and PIC18F57Q43

High-power, ultra-precise control for bipolar stepper motors

Stepper 25 Click with Curiosity Nano with PIC18F57Q43

Published Apr 03, 2025

Click board™

Stepper 25 Click

Dev. board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Achieve ultra-precise bipolar stepper motor control with 1/256 microstepping and a powerful 5A full-scale output

A

A

Hardware Overview

How does it work?

Stepper 25 Click is based on the DRV8452 motor driver IC from Texas Instruments for precise control of bipolar stepper motors. The DRV8452 includes two N-channel power MOSFET H-bridges, current sense resistors, an advanced current regulation system, and a microstepping indexer, all within a single package. This robust integration enables the board to handle a wide supply voltage range from 4.5V to 55V, while delivering an impressive output current of up to 5A full-scale, or 3.5A RMS, ensuring stable performance in high-power scenarios. Thanks to the capabilities of the DRV8452, Stepper 25 Click is ideally suited for a wide range of applications including textile and sewing machines, factory automation systems, robotic platforms, diagnostic equipment, multifunction printers, as well as PLC, DCS, and PAC-based systems. This makes it a versatile and reliable choice for engineers and developers working on complex motion control tasks that demand both power and precision. One of the standout features of the DRV8452 is the auto-torque function, which dynamically adjusts the output current based on the motor load. This not only enhances the overall efficiency of the system but also significantly reduces power losses during operation. Fine-tuning of the motor current is made simple through the onboard VREF trimmer, allowing for precise adjustments to match specific load requirements. Additionally, the board includes an ENABLE switch that allows users to control the activation of the output channels - when set to

position 0, all outputs are disabled, and when set to position 1, the outputs are enabled and ready for operation. Stepper 25 Click uses a standard 4-wire SPI interface for communication with the host MCU, allowing precise configuration of the DRV8452 and optimization of the auto-torque algorithm for various motor applications. It features stall detection to notify the system when the motor is blocked or reaches its travel limit, ensuring safe operation. To reduce energy usage, the standstill power saving mode minimizes power loss when the motor is holding position. The DRV8452 also includes an integrated current-sense architecture that eliminates the need for external sense resistors by using a current mirror and internal MOSFETs. A combination of STP and DIR pins allows a host MCU to manage the direction and step rate of the stepper motor. The integrated microstepping indexer of the DRV8452 enables precise motion control without requiring the host to manage winding currents. The indexer supports a wide range of resolutions, including full step, half step, and microsteps down to 1/256, ensuring exceptionally smooth and accurate motion. Higher microstepping levels significantly reduce audible noise and enhance movement fluidity. Additionally, the automatic microstepping mode interpolates low-frequency input signals into high-resolution steps, improving current regulation and further minimizing noise during operation. To regulate the winding current effectively, the DRV8452 use various decay modes such as slow, mixed, and fast decay. The

DRV8452 also features advanced smart tune decay modes that automatically adapt to ensure optimal current regulation, regardless of changes in supply voltage, motor speed, or aging. Smart tune Ripple Control employs a variable off-time ripple current scheme to reduce current distortion in the motor windings, while Smart tune Dynamic Decay uses a fixed off-time with dynamic fast decay percentages for improved performance. In addition to these, the DRV8452 includes a silent step decay mode designed to enable extremely quiet operation during standstill and low-speed motion. Stepper 25 Click features two additional control pins: FLT and SLP. The FLT pin serves as a fault indicator, signaling any fault conditions such as overcurrent or thermal shutdown. The SLP pin controls the device’s power mode - setting it to logic HIGH enables normal operation, while logic LOW puts the device into a low-power sleep mode to conserve energy. Both pins are paired with red LED indicators labeled FAULT and SLEEP, providing clear visual feedback on the device’s fault status and power state for easier monitoring and debugging. 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 25 Click hardware overview image

Features overview

Development board

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

The 17HD40005-22B stepper motor is a two-phase hybrid motor for high torque, high speed, and low noise performance. It features a 1m wire with optional ports on the connection end and heat shrink tubing to prevent tangling. The motor's D-shaped axle is 22mm in length. This motor operates with a chopping wave constant current drive and has a two-phase 4-wire exciting mode, allowing for both forward and reverse rotation. The power order follows AB-BC-CD-DA, viewed as clockwise from the shaft end. It has a rated current of 1.3A DC, a rated voltage of 2.4V, and a stepping angle of 1.8°, with an insulation grade of B. This stepper motor is ideal for applications requiring precise movement control and reliability.

Stepper 25 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Motor Direction Control
PA0
AN
Sleep Mode / ID SEL
PA7
RST
SPI Select / ID COMM
PD4
CS
SPI Clock
PC6
SCK
SPI Data OUT
PC5
MISO
SPI Data IN
PC4
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Motor Step Control
PB0
PWM
Fault Indicator
PA6
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

Stepper 25 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Board mapper by product8 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
PIC18F57Q43 Curiosity 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

Software Support

Library Description

Stepper 25 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.

Example Description
This example demonstrates the operation of the Stepper 25 Click board, which is used to control a bipolar stepper motor. The application initializes the board and executes different step modes, directions, and speeds to showcase precise motor control.

Key functions:

  • stepper25_cfg_setup - This function initializes Click configuration structure to initial values.

  • stepper25_init - This function initializes all necessary pins and peripherals used for this Click board.

  • stepper25_default_cfg - Click Default Configuration function.

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

  • stepper25_set_step_mode - This function sets the step mode (microstepping level) of the Stepper 25 device.

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

Application Init
Initializes the logger and Stepper 25 Click board. Configures the motor driver with default settings, preparing it for stepper motor control.

Application Task
Moves the stepper motor in different step modes and directions at varying speeds. The motor completes a predefined number of steps in each mode, switching between clockwise (CW) and counterclockwise (CCW) directions with different step resolutions.

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 25 Click example
 *
 * # Description
 * This example demonstrates the operation of the Stepper 25 Click board, 
 * which is used to control a bipolar stepper motor. The application initializes 
 * the board and executes different step modes, directions, and speeds to 
 * showcase precise motor control.
 *
 * The demo application is composed of two sections:
 *
 * ## Application Init
 * Initializes the logger and Stepper 25 Click board. Configures the motor driver 
 * with default settings, preparing it for stepper motor control.
 *
 * ## Application Task
 * Moves the stepper motor in different step modes and directions at varying speeds. 
 * The motor completes a predefined number of steps in each mode, switching between 
 * clockwise (CW) and counterclockwise (CCW) directions with different step resolutions.
 *
 * @note
 * Ensure proper power supply and motor connections before running the example.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "stepper25.h"

static stepper25_t stepper25;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    stepper25_cfg_t stepper25_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.
    stepper25_cfg_setup( &stepper25_cfg );
    STEPPER25_MAP_MIKROBUS( stepper25_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == stepper25_init( &stepper25, &stepper25_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( STEPPER25_ERROR == stepper25_default_cfg ( &stepper25 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    log_printf ( &logger, " Step mode: 1/16\r\n" );
    log_printf ( &logger, " Direction: CW\r\n" );
    log_printf ( &logger, " Steps: 1600\r\n" );
    log_printf ( &logger, " Speed: Medium\r\n\n" );
    stepper25_set_direction ( &stepper25, STEPPER25_DIR_CW );
    stepper25_set_step_mode ( &stepper25, STEPPER25_STEP_MODE_1_OVER_16 );
    stepper25_drive_motor ( &stepper25, 1600, STEPPER25_SPEED_MEDIUM );
    Delay_ms ( 1000 );

    log_printf ( &logger, " Step mode: 1/8\r\n" );
    log_printf ( &logger, " Direction: CCW\r\n" );
    log_printf ( &logger, " Steps: 1600\r\n" );
    log_printf ( &logger, " Speed: Fast\r\n\n" );
    stepper25_set_direction ( &stepper25, STEPPER25_DIR_CCW );
    stepper25_set_step_mode ( &stepper25, STEPPER25_STEP_MODE_1_OVER_8 );
    stepper25_drive_motor ( &stepper25, 1600, STEPPER25_SPEED_FAST );
    Delay_ms ( 1000 );

    log_printf ( &logger, " Step mode: 1/4\r\n" );
    log_printf ( &logger, " Direction: CW\r\n" );
    log_printf ( &logger, " Steps: 400\r\n" );
    log_printf ( &logger, " Speed: Slow\r\n\n" );
    stepper25_set_direction ( &stepper25, STEPPER25_DIR_CW );
    stepper25_set_step_mode ( &stepper25, STEPPER25_STEP_MODE_QUARTER );
    stepper25_drive_motor ( &stepper25, 400, STEPPER25_SPEED_SLOW );
    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.