Intermediate
30 min

Command motors with precision using NCV7535 and PIC32MZ1024EFH064

Unleashing the force!

H-Bridge Driver 2 Click with PIC32MZ clicker

Published Jul 25, 2023

Click board™

H-Bridge Driver 2 Click

Dev Board

PIC32MZ clicker

Compiler

NECTO Studio

MCU

PIC32MZ1024EFH064

Drive external MOSFETs to control DC motors! Take the first step towards engineering greatness.

A

A

Hardware Overview

How does it work?

H-Bridge Driver 2 Click is based on the NCV7535, H-bridge gate driver (or full-bridge pre-driver) with independent high and low-side driver channels from ON Semiconductor. This monolithic H−bridge pre-driver has an enhanced feature set helpful in various applications for a DC motor drive. It allows bi-directional or uni-directional motor operations with integrated MOSFET and load protection. The onboard VIN terminal is the device's power supply input, allowing a wide operating voltage range from 6V to 18V. The NCV7535 also has built-in protection against short-circuit and overtemperature conditions,

under-voltage (UV), overvoltage (OV), and overcurrent events. When the supply returns to a level above the UV threshold or below the OV threshold, the device resumes regular operation according to the established condition of the input pins. H-Bridge Driver 2 Click communicates with MCU through a standard SPI interface supporting the common SPI mode, SPI Mode 0, providing data in a digital format of 24 bits. It also uses the Enable pin labeled as EN and routed to the RST pin of the mikroBUS™ socket to optimize power consumption, used for its power ON/OFF purposes. Besides, the user can use the PWM

signal from the mikroBUS™ socket, combined with the SPI interface and its control register, and use active or passive free-wheeling bridge configurations. 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. The 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.

H-Bridge Driver 2 Click hardware overview image

Features overview

Development board

PIC32MZ Clicker is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC32MZ microcontroller with FPU from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing access anywhere and under

any circumstances. Each part of the PIC32MZ Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the PIC32MZ Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current, which is more than enough to operate all onboard

and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. PIC32MZ Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

PIC32MZ clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

1024

Silicon Vendor

Microchip

Pin count

64

RAM (Bytes)

524288

You complete me!

Accessories

H-Bridge MOSFET board represents an easy-to-use adapter board that allows the user to exercise all the functions of the H-Bridge Driver Click board™. This board has five 5.08mm pitch screw terminals to connect power and loads easily. Three of them on the left side of the board are suitable for a target H-Bridge Driver Click board™ connection with appropriate high and low side gate drive channels used to control the outputs or functions inside the circuit. The first VIN terminal on the upper-left board side represents the PSMN019-100YLX MOSFET’s power supply connector, allowing an operating voltage range like the connected H-Bridge Driver Click board™. On the right side of the board, the OUT terminal is used to drive a load, such as a brushed DC motor. This board also provides two LED indicators labeled REVERSE and FORWARD to indicate when output operates reverse or forward.

H-Bridge Driver 2 Click accessories 1 image

DC Gear Motor - 430RPM (3-6V) represents an all-in-one combination of a motor and gearbox, where the addition of gear leads to a reduction of motor speed while increasing the torque output. This gear motor has a spur gearbox, making it a highly reliable solution for applications with lower torque and speed requirements. The most critical parameters for gear motors are speed, torque, and efficiency, which are, in this case, 520RPM with no load and 430RPM at maximum efficiency, alongside a current of 60mA and a torque of 50g.cm. Rated for a 3-6V operational voltage range and clockwise/counterclockwise rotation direction, this motor represents an excellent solution for many functions initially performed by brushed DC motors in robotics, medical equipment, electric door locks, and much more.

H-Bridge Driver 2 Click accessories 2 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Enable
RE5
RST
SPI Chip Select
RG9
CS
SPI Clock
RG6
SCK
SPI Data OUT
RG7
MISO
SPI Data IN
RG8
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Signal
RB3
PWM
NC
NC
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

Schematic

H-Bridge Driver 2 Click Schematic schematic

Step by step

Project assembly

PIC32MZ clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the PIC32MZ clicker as your development board.

PIC32MZ clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker Access - 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
Flip&Click PIC32MZ 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

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for H-Bridge Driver 2 Click driver.

Key functions:

  • hbridgedriver2_run_forward - H-Bridge Driver 2 run forward function

  • hbridgedriver2_run_backward - H-Bridge Driver 2 run backward function

  • hbridgedriver2_stop_with_brake - H-Bridge Driver 2 stop with brake function

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief HBridgeDriver2 Click example
 *
 * # Description
 * This library contains API for the H-Bridge Driver 2 Click driver.
 * This demo application shows the use of a H-Bridge Driver 2 Click board™.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of SPI, PWM module and log UART.
 * After driver initialization and default settings,
 * the application displays the device ID data, sets PWM duty cycle to 50% 
 * and start PWM module.
 *
 * ## Application Task
 * This example demonstrates the use of the H-Bridge Driver 2 Click board™.
 * The application turns connected MOSFETs gates high or low in order to drive 
 * the motor forward, backward, stop with brake or stop.
 * Results are being sent to the Usart Terminal, where you can track their changes.
 * 
 * ## Additional Function
 * - static void display_status ( void )
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "hbridgedriver2.h"

static hbridgedriver2_t hbridgedriver2;
static log_t logger;
static uint8_t global_fault;
static hbridgedriver2_dev_id_t dev_id;

static void display_status ( void )
{
    uint16_t status;
    
    log_printf( &logger, "- - - - - - - - -  - - - - - - -\r\n" ); 
    log_printf( &logger, " Status :" );
    hbridgedriver2_get_status( &hbridgedriver2, &status );
    
    if ( HBRIDGEDRIVER2_STAT_0_OCHS1 == status )
    {
        log_printf( &logger, " HS1 Over−current detected\r\n" );
    }
    
    if ( HBRIDGEDRIVER2_STAT_0_OCLS1 == status )
    {
        log_printf( &logger, " LS1 Over−current detected\r\n" );
    }
    
    if ( HBRIDGEDRIVER2_STAT_0_OCHS2 == status )
    {
        log_printf( &logger, " HS2 Over−current detected\r\n" );
    }
    
    if ( HBRIDGEDRIVER2_STAT_0_OCLS2 == status )
    {
        log_printf( &logger, " LS2 Over−current detected\r\n" );
    }
    
    if ( HBRIDGEDRIVER2_STAT_0_VSUV == status )
    {
        log_printf( &logger, " Under−voltage detected\r\n" );
    }
    
    if ( HBRIDGEDRIVER2_STAT_0_VSOV == status )
    {
        log_printf( &logger, " Overvoltage detected\r\n" );
    }
    
    if ( HBRIDGEDRIVER2_STAT_0_OK == status )
    {
        log_printf( &logger, " Normal Operation\r\n" );
    }
    
    log_printf( &logger, "--------------------------------\r\n" );    
    Delay_ms ( 100 );    
}

void application_init ( void )
{
    log_cfg_t log_cfg;                        /**< Logger config object. */
    hbridgedriver2_cfg_t hbridgedriver2_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.
    hbridgedriver2_cfg_setup( &hbridgedriver2_cfg );
    HBRIDGEDRIVER2_MAP_MIKROBUS( hbridgedriver2_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == hbridgedriver2_init( &hbridgedriver2, &hbridgedriver2_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    Delay_ms ( 1000 );
    
    hbridgedriver2_enable( &hbridgedriver2 );
    Delay_ms ( 100 );
    log_info( &logger, "  Default config " );
    
    if ( HBRIDGEDRIVER2_ERROR == hbridgedriver2_default_cfg ( &hbridgedriver2 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    Delay_ms ( 1000 );

    log_printf( &logger, "--------------------------------\r\n" );
    Delay_ms ( 100 );
    
    hbridgedriver2_get_device_id( &hbridgedriver2, &global_fault, &dev_id );
    Delay_ms ( 100 );  
    log_printf( &logger, " ID header      : 0x%.4X \r\n", dev_id.id_header ); 
    log_printf( &logger, " Version        : 0x%.4X \r\n", dev_id.version );
    log_printf( &logger, " Product Code 1 : 0x%.4X \r\n", dev_id.product_code_1 );
    log_printf( &logger, " Product Code 2 : 0x%.4X \r\n", dev_id.product_code_2 );
    log_printf( &logger, " SPI Frame ID   : 0x%.4X \r\n", dev_id.spi_frame_id );
    log_printf( &logger, "--------------------------------\r\n" );
    Delay_ms ( 100 );
    
    hbridgedriver2_set_duty_cycle ( &hbridgedriver2, 0.5 );
    hbridgedriver2_pwm_start( &hbridgedriver2 );
    Delay_ms ( 100 );
    
    log_printf( &logger, "\t>>> START <<<\r\n" );
    display_status( );
    Delay_ms ( 1000 );
}

void application_task ( void )
{
    log_printf( &logger, "\t>>> Run Forward\r\n" );
    hbridgedriver2_run_forward( &hbridgedriver2, &global_fault );
    display_status( );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    log_printf( &logger, "\t>>> Stop With Brake\r\n" );
    hbridgedriver2_stop_with_brake( &hbridgedriver2, &global_fault );
    display_status( );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    log_printf( &logger, "\t>>> Run Backward\r\n" );
    hbridgedriver2_run_backward( &hbridgedriver2, &global_fault );
    display_status( );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    log_printf( &logger, "\t>>> Stop\r\n" );
    hbridgedriver2_stop( &hbridgedriver2, &global_fault );
    display_status( );
    Delay_ms ( 1000 );
    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.