Intermediate
20 min

Achieve smooth and quiet BLDC motor control with MCF8316A and ATmega644

Sensorless Field Oriented Control (FOC) integrated FET BLDC driver solution

Brushless 33 Click with EasyAVR v7

Published Jan 30, 2025

Click board™

Brushless 33 Click

Dev Board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega644

Brushless DC (BLDC) motor control solution based on a sensorless Field Oriented Control (FOC) integrated FET motor driver

A

A

Hardware Overview

How does it work?

Brushless 33 Click is based on the MCF8316A, a sensorless Field Oriented Control (FOC) integrated FET brushless DC (BLDC) driver from Texas Instruments, designed for BLDC motor control applications. This three-phase motor driver incorporates a code-free sensorless FOC algorithm, making it an ideal solution for controlling speed-regulated 12V to 24V BLDC or Permanent Magnet Synchronous Motors (PMSM) with a peak current of up to 8A. The MCF8316A integrates three half-bridges with an exceptionally low RDS(ON) value of 95mΩ (combined high-side and low-side), ensuring minimal energy loss and maximum efficiency during operation. Furthermore, the device allows for standalone functionality by storing algorithm configurations in its non-volatile EEPROM, enabling consistent and reliable motor control without additional external coding or adjustments once configured. Based on its broad range of features, the Brushless 33 Click is well-suited for numerous applications, including residential and living fans, air purifiers, humidifier fans, automotive fans, blowers, and medical CPAP blowers. The MCF8316A includes protection features to safeguard the device, motor, and overall system from potential faults. These integrated protections ensure robust performance and long-term reliability across diverse operating conditions. With its sensorless FOC algorithm, the MCF8316A offers smooth motor speed control, even in

applications requiring quiet and efficient operation. The Brushless 33 Click operates from an external power supply connected to the VM terminal, with a recommended operating range of 4.5V to 35V. Its output terminals, A, B, and C, can deliver a peak drive current of up to 8A, ensuring operation for spinning a three-phase sensorless Brushless DC (BLDC) motor. The A2212/13T 1000KV BLDC motor is one of our recommendations for optimal performance. In addition to the motor connection terminals, the board includes three dedicated hooks that serve as test points for the three phases of the BLDC motor, allowing for convenient monitoring and diagnostics during operation. This Click board™ is controlled by the host MCU using several pins and their corresponding logic states. The SPD pin allows for motor speed control through PWM by varying the duty cycle of the input signal, while speed can also be adjusted using frequency or an analog input on the SPD pin or configured via the I2C configuration register. The BRK pin brakes the motor when set to a HIGH logic state and enables normal operation when set to LOW. The DIR pin determines the direction of motor rotation, with a LOW state resulting in an A-C-B driving sequence and a HIGH state corresponding to an A-B-C sequence. Additionally, the FLT pin signals when a fault condition occurs in the MCF8316A. To provide visual feedback, several LED indicators reflect the state of key signals: a

green LED for SPEED, a yellow LED for BRAKE, and a red LED for FAULT, ensuring quick and intuitive monitoring of the system's operation. The MCF8316A includes the mentioned I2C interface, which allows an external host MCU to configure its various settings and access fault diagnostic information. The board also features a DRVOFF switch that enables or disables the internal gate drivers; in position 0, the MCF8316A is disabled, while in position 1, it is enabled for operation. Additionally, the board includes unpopulated pins offering extended functionality. The FG pin outputs pulses proportional to the motor's speed, providing a convenient way to monitor rotational speed. The SOX pin outputs the signal from one of the current sense amplifiers, offering precise current measurement capabilities. The EWD and ECK pins are optional inputs for external oscillator and watchdog signals. The ECK pin can provide an external clock reference, while the EWD pin can accept an external watchdog signal, enhancing system reliability and enabling advanced timing control. 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.

Brushless 33 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

ATmega644

Architecture

AVR

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

4096

You complete me!

Accessories

BLDC A2212/13T/1000 KV Brushless DC Motor is a high-performance motor designed for reliable operation. Crafted with high-quality materials, including Japanese NMB ball bearings, Kawasaki stator steel, and oxygen-free pure copper wires, it ensures durability and smooth performance. With a lightweight aluminum CNC-machined case, 930KV high RPM, and patented balance techniques, this motor delivers powerful thrust for an exhilarating flight experience. Its N40UH magnets and silicone wire leads provide excellent high-temperature resistance, making it ideal for demanding applications.

Brushless 33 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Motor Brake Control
PA7
AN
Motor Direction Control
PA6
RST
ID COMM
PA5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Motor Speed Control
PD4
PWM
Fault 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

Brushless 33 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
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

Brushless 33 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 control of an A2212/13T 1000KV motor using the Brushless 33 Click board. The example showcases basic motor operations, including speed adjustments, direction switching, and fault handling. The motor speed is controlled by varying the PWM duty cycle.

Key functions:

  • brushless33_cfg_setup - Config Object Initialization function.

  • brushless33_init - Initialization function.

  • brushless33_default_cfg - Click Default Configuration function.

  • brushless33_set_duty_cycle - This function sets the PWM duty cycle in percentages ( Range[ 0..1 ] ).

  • brushless33_switch_direction - This function switches the direction of motor rotation by toggling the DIR pin logic state.

  • brushless33_get_fault_pin - This function returns the fault indication pin logic state.

Application Init
Initializes the logger and configures the Click board.

Application Task
Adjusts the motor's duty cycle to control its speed, alternating between increasing and decreasing duty values. Fault conditions are checked and resolved to maintain stable operation. Additional motor controls, such as switching direction and braking, are triggered based on the duty cycle limits. Each step will be logged on the USB UART where you can track the program flow.

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 Brushless 33 Click example
 *
 * # Description
 * This example demonstrates the control of an A2212/13T 1000KV motor using
 * the Brushless 33 Click board. The example showcases basic motor operations, including
 * speed adjustments, direction switching, and fault handling. The motor speed is
 * controlled by varying the PWM duty cycle.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the logger and configures the Click board.
 *
 * ## Application Task
 * Adjusts the motor's duty cycle to control its speed, alternating between increasing
 * and decreasing duty values. Fault conditions are checked and resolved to maintain
 * stable operation. Additional motor controls, such as switching direction and braking,
 * are triggered based on the duty cycle limits. Each step will be logged on the USB UART
 * where you can track the program flow.
 *
 * @note
 * The library is configured for an A2212/13T 1000KV motor with a 12V power supply.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "brushless33.h"

static brushless33_t brushless33;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    brushless33_cfg_t brushless33_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.
    brushless33_cfg_setup( &brushless33_cfg );
    BRUSHLESS33_MAP_MIKROBUS( brushless33_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == brushless33_init( &brushless33, &brushless33_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( BRUSHLESS33_ERROR == brushless33_default_cfg ( &brushless33 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }

    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static int8_t duty_cnt = 0;
    static int8_t duty_inc = 1;
    float duty = duty_cnt / 10.0;
    uint32_t gate_drv_flt = 0;
    uint32_t controller_flt = 0;

    if ( !brushless33_get_fault_pin ( &brushless33 ) )
    {
        if ( BRUSHLESS33_OK == brushless33_read_fault ( &brushless33, &gate_drv_flt, &controller_flt ) )
        {
            if ( gate_drv_flt )
            {
                log_printf( &logger, " GATE DRIVER FAULT: 0x%.8LX\r\n", gate_drv_flt );
            }
            if ( controller_flt )
            {
                log_printf( &logger, " CONTROLLER FAULT: 0x%.8LX\r\n", controller_flt );
            }
        }
        brushless33_clear_fault ( &brushless33 );
        // Motor startup delay
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
    }
    
    brushless33_set_duty_cycle ( &brushless33, duty );
    log_printf( &logger, "> Duty: %d%%\r\n", ( uint16_t )( duty_cnt * 10 ) );
    
    if ( ( 1 == duty_cnt ) && ( 1 == duty_inc ) )
    {
        // Motor startup delay
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
    }
    Delay_ms ( 1000 );

    duty_cnt += duty_inc;
    if ( duty_cnt > 10 ) 
    {        
        duty_cnt = 9;
        duty_inc = -1;
    }
    else if ( duty_cnt < 0 ) 
    {
        duty_cnt = 0;
        duty_inc = 1;
        log_printf( &logger, " Pull brake\r\n" );
        brushless33_pull_brake ( &brushless33 );
        Delay_ms ( 1000 );
        log_printf( &logger, " Switch direction\r\n" );
        brushless33_switch_direction ( &brushless33 );
        Delay_ms ( 1000 );
        log_printf( &logger, " Release brake\r\n" );
        brushless33_release_brake ( &brushless33 );
        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.