Intermediate
20 min

Achieve smooth and quiet BLDC motor control with MCF8316A and PIC18F57Q43

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

Brushless 33 Click with Curiosity Nano with PIC18F57Q43

Published Jan 30, 2025

Click board™

Brushless 33 Click

Dev Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

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

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

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
PA0
AN
Motor Direction Control
PA7
RST
ID COMM
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Motor Speed Control
PB0
PWM
Fault Interrupt
PA6
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB2
SCL
I2C Data
PB1
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

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
Curiosity Nano with PICXXX 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 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

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.