Intermediate
20 min

Say goodbye to complex motor control with DRV8889A and ATmega324P

Empower your designs with precision and efficiency!

Stepper 15 Click with EasyAVR v7

Published Oct 28, 2023

Click board™

Stepper 15 Click

Dev. board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega324P

Our integrated motor-driver solution for bipolar stepper motors offers the perfect blend of precision and efficiency, ensuring your projects perform flawlessly

A

A

Hardware Overview

How does it work?

Stepper 15 Click is based on the DRV8889A, an integrated motor-driver solution for bipolar stepper motors from Texas Instruments. The DRV8889A integrates two N-channel power MOSFET H-bridges (disabled by default after Power-Up), integrated current sense and regulation circuitry, and a microstepping indexer. It can be powered with a supply voltage from 4.5 to 45V, providing an output current of up to 2.4A peak, 1.5A full-scale, or 1.1A RMS. The DRV8889A uses an integrated current-sense architecture, eliminating the need for two external power-sense resistors. This architecture removes the power dissipated in the sense of resistors using a current mirror approach and the internal power MOSFETs for current sensing. It also includes an integrated torque DAC that allows the controller to scale the output current through a full-duplex, 4-wire

synchronous SPI interface without needing to scale the voltage reference. The torque DAC allows the controller to save system power by decreasing the motor current consumption when high output torque is not required. A simple STEP/DIR interface allows an external MCU to manage the direction and step rate of the stepper motor. The internal indexer can execute high-accuracy microstepping without requiring the MCU to handle the winding current level. The indexer is capable of the whole step, half step, and 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, and 1/256 microstepping. Also, a noncircular half-stepping mode is available for increased torque output at higher motor RPM and a standard half-stepping mode. Unlike the STEP pin controlled by the PWM pin from the mikroBUS™ socket, other pins from the DRV8889A, such as Sleep mode selection, fault indicator, direction selection, and

device turn-off pins are controlled through a well-known 8bit I/O expander, the PCA9538 from NXP Semiconductor using the standard I2C 2-Wire interface with a maximum frequency of 400kHz. The PCA9538 also uses RST and INT pins from the mikroBUS™ socket as a hardware reset and interrupt function. This Click board™ can operate with both 3.3V and 5V logic voltage levels selected via the VCC SEL jumper. It allows both 3.3V and 5V capable MCUs to use the communication lines properly. Additionally, there is a possibility for stepper motor driver power supply selection via jumper labeled as VM SEL to supply the DRV8889A from an external input terminal in the range from 4.5 to 45V or with a 5V from mikroBUS™ power rail.

Stepper 15 Click hardware overview image

Features overview

Development board

EasyAVR v7 is the seventh generation of AVR development boards specially designed for the needs of rapid development of embedded applications. It supports a wide range of 16-bit AVR microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyAVR v7 allows you to connect accessory boards, sensors, and custom electronics more

efficiently than ever. Each part of the EasyAVR v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B)

connector. Communication options such as USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets which cover a wide range of 16-bit AVR MCUs. EasyAVR v7 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.

EasyAVR v7 horizontal image

Microcontroller Overview

MCU Card / MCU

ATmega324P

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

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 15 Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PA6
RST
SPI Chip Select
PA5
CS
SPI Clock
PB7
SCK
SPI Data OUT
PB6
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Step Rate
PD4
PWM
Interrupt
PD2
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC0
SCL
I2C Data
PC1
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Stepper 15 Click Schematic schematic

Step by step

Project assembly

EasyAVR v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v7 as your development board.

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyAVR v7 Access DIP 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 DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step 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 15 Click driver.

Key functions:

  • stepper15_make_one_step - Stepper 15 make one step function.

  • stepper15_set_direction - Stepper 15 set direction function.

  • stepper15_step_by_angle - Stepper 15 step by angle function.

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 Stepper15 Click example
 *
 * # Description
 * This library contains API for the Stepper 15 Click driver.
 * The library contains drivers for work control of the Stepper Motor.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes I2C and SPI driver and set default configuration,
 * enable the device and enable outputs mode.
 *
 * ## Application Task
 * The application task represents an example that demonstrates 
 * the use of the Stepper 15 Click board™ 
 * with which the user can sequentially move the motor. 
 * The first part of the sequence executes the clockwise/counterclockwise motor movement
 * for an angle of 90-degrees with a step speed of 85/100%, 
 * all the way to the last sequence of the same movement routine of 360-degree angle
 * with a step speed of 85/100%. 
 * Results are sent to the USART Terminal, where you can track their changes.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "stepper15.h"

static stepper15_t stepper15;
static log_t logger;
static uint8_t step_speed = 100;
static uint16_t step_360 = 200;

void application_init ( void ) {
    log_cfg_t log_cfg;              /**< Logger config object. */
    stepper15_cfg_t stepper15_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.

    stepper15_cfg_setup( &stepper15_cfg );
    STEPPER15_MAP_MIKROBUS( stepper15_cfg, MIKROBUS_1 );
    err_t init_flag  = stepper15_init( &stepper15, &stepper15_cfg );
    if ( ( init_flag == I2C_MASTER_ERROR ) || ( init_flag == SPI_MASTER_ERROR ) ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    stepper15_default_cfg ( &stepper15 );
    log_info( &logger, " Application Task " );
    log_printf( &logger, "---------------------------------\r\n" );
    
    stepper15_set_work_mode( &stepper15, STEPPER15_WORK_MODE_ENABLE_DEVICE );
    Delay_ms( 100 );
    stepper15_set_output_mode( &stepper15, STEPPER15_OUTPUT_MODE_OUTPUTS_ENABLE );
    Delay_ms( 100 );
    
    if ( stepper15_get_fault_condition( &stepper15 ) == STEPPER15_FAULT_CONDITION ) {
        log_printf( &logger, "         Fault condition         \r\n" );   
    } else {
        log_printf( &logger, "        Correct condition        \r\n" );
    }
    
    log_printf( &logger, "---------------------------------\r\n" );
    log_printf( &logger, "      Stop the stepper motor     \r\n" );
    stepper15_motor_stop( &stepper15 );
    Delay_ms( 1000 );
}

void application_task ( void ) {
    log_printf( &logger, "---------------------------------\r\n" );
    log_printf( &logger, "        Clockwise motion         \r\n" );
    log_printf( &logger, " Angle of rotation :  90 degrees \r\n" );
    log_printf( &logger, " Step speed        :  85 %%      \r\n" );
    stepper15_set_direction ( &stepper15, STEPPER15_DIRECTION_CLOCKWISE );
    stepper15_step_by_angle( &stepper15, step_speed - 15, 90, step_360 );
    Delay_ms( 2000 );
    
    log_printf( &logger, "---------------------------------\r\n" );
    log_printf( &logger, "     Counterclockwise motion     \r\n" );
    log_printf( &logger, " Angle of rotation : 180 degrees \r\n" );
    log_printf( &logger, " Step speed        :  85 %%      \r\n" );
    stepper15_set_direction ( &stepper15, STEPPER15_DIRECTION_COUNTERCLOCKWISE );
    stepper15_step_by_angle( &stepper15, step_speed - 15, 180, step_360 );
    Delay_ms( 2000 );
    
    log_printf( &logger, "---------------------------------\r\n" );
    log_printf( &logger, "        Clockwise motion         \r\n" );
    log_printf( &logger, " Angle of rotation : 270 degrees \r\n" );
    log_printf( &logger, " Step speed        :  90 %%      \r\n" );
    stepper15_set_direction ( &stepper15, STEPPER15_DIRECTION_CLOCKWISE );
    stepper15_step_by_angle( &stepper15, step_speed - 10, 270, step_360 );
    Delay_ms( 2000 );
    
    log_printf( &logger, "---------------------------------\r\n" );
    log_printf( &logger, "     Counterclockwise motion     \r\n" );
    log_printf( &logger, " Angle of rotation : 360 degrees \r\n" );
    log_printf( &logger, " Step speed        : 100 %%      \r\n" );
    stepper15_set_direction ( &stepper15, STEPPER15_DIRECTION_COUNTERCLOCKWISE );
    stepper15_step_by_angle( &stepper15, step_speed, 360, step_360 );
    Delay_ms( 2000 );
    
    log_printf( &logger, "---------------------------------\r\n" );
    log_printf( &logger, "        Clockwise motion         \r\n" );
    log_printf( &logger, " Angle of rotation : 360 degrees \r\n" );
    log_printf( &logger, " Step speed        : 100 %%      \r\n" );
    stepper15_set_direction ( &stepper15, STEPPER15_DIRECTION_CLOCKWISE );
    stepper15_step_by_angle( &stepper15, step_speed, 360, step_360 );
    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.