Intermediate
30 min

Design more efficient motor drive systems using TC78H660FTG and PIC18F45K40

Experience motor control like never before

DC Motor 17 Click with EasyPIC v8

Published Jul 01, 2023

Click board™

DC Motor 17 Click

Dev. board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18F45K40

Experience the difference. Add brushed motor control and witness the transformation in your projects, amplifying their speed, precision, and overall potential!

A

A

Hardware Overview

How does it work?

DC Motor 17 Click is based on the TC78H660FTG, a dual H Bridge driver for one or two DC brushed motors incorporating a DMOS output transistor with low on-resistance from Toshiba Semiconductor. This driver is a PWM-controlled constant-current drive with supply voltages from 2.5 to 16V and 2A maximum output current. It features a built-in dual H-bridge, sense-resistor less current control architecture (advanced current detection system), and a VCC regulator for the internal circuit. Besides, it offers thermal shutdown, overcurrent detection, Undervoltage lockout error detections (with error detection flag function), and several selectable operational modes (Forward, Reverse, Stop, and Brake) controlled by four GPIO pins routed on the RST, AN, PWM, and INT pins of the mikroBUS™ socket. The TC78H660FTG possesses two operational modes, IN Input Mode and PHASE Input Mode, whose selection can be achieved via headers Control Mode pin labeled as MODE. PHASE Mode represents the default mode of this Click board™, and the Control Mode is set up by the input state of the MODE pin after releasing the SBY pin. This way, the MODE pin is used as the Enable signal

while the direction selection is realized via GPIO pins routed on the mikroBUS™ socket. The pin labeled as ERR represents the Error Detection Flag. When TC78H660FTG detects some errors, the ERR pin outputs a low level to the peripheral block. In Normal status, since the internal MOSFET is OFF, the logic level of the ERR pin is equal to the MODE control voltage from outside. When some event like thermal shutdown or overcurrent occurs, the ERR pin will become low (the internal MOSFET is ON). When the error detection is released by reasserting the external power supply or setting the device to Standby Mode, ERR pins show Normal Status. In the case of constant current control, the rate of Mixed Decay Mode, which determines the current ripple, is fixed at 37.5%. Peak current can be set by the voltage value of the VREF pin obtained by the MAX6100, a low-cost, low-dropout, micropower voltage reference IC from Analog Devices. This series-mode voltage reference draws only 90μA of supply current and can source 5mA and sink 2mA of load current. The current threshold point for the VREF pin of the TC78H660FTG, alongside MAX6100, can be set manually using an onboard trimmer labeled VR1.

As mentioned in the product description, DC Motor 17 Click communicates with MCU using several GPIO pins. Also, this Click board™ has a Standby pin labeled as SBY routed to the CS pin of the mikroBUS™ socket used to switch to Standby mode by toggling the pin. When the SBY pin is low, TC78H660FTG stops supplying the power to the logic circuit. The difference in DC Motor modes between IN and PHASE Input Modes needs to be especially emphasized. In addition to motor modes such as Forward, Reverse, Stop, and Standby, only IN Input Mode has another additional, Short Brake Mode. More information on the Motor Mode Selection can be found in the attached datasheet. 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. Additionally, there is a possibility for motor-driver power supply selection via jumper labeled as VM SEL to supply TC78H660FTG from an external input terminal in the range from 2.5 to 16V or with voltage levels used from mikroBUS™ power supply pins.

DC Motor 17 Click hardware overview image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector.

Communication options such as USB-UART, USB DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC v8 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.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU

PIC18F45K40

Architecture

PIC

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

You complete me!

Accessories

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.

DC Motor 17 Click accessories image

Used MCU Pins

mikroBUS™ mapper

A Channel Input 1
RA2
AN
A Channel Input 2
RE1
RST
Standby
RE0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
B Channel Input 1
RC0
PWM
B Channel Input 2
RB0
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

DC Motor 17 Click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v8 as your development board.

EasyPIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v8 Access DIPMB 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
Necto image step 8 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 DC Motor 17 Click driver.

Key functions:

  • dcmotor17_stop - DC Motor 17 stop motor function
  • dcmotor17_forward - DC Motor 17 forward function
  • dcmotor17_reverse - DC Motor 17 reverse 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 DC Motor 17 Click Example.
 *
 * # Description
 * The library covers all the necessary functions to control DC Motor 17 Click board. 
 * Library performs a standard GPIO interface communication.
 * DC Motor 17 Click board is a dual H Bridge driver IC for one or two DC brushed
 * motors which incorporates DMOS with low on-resistance in output transistors. 
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes GPIO driver, set default configuration and start to write log.
 *
 * ## Application Task
 * This is an example that demonstrates the use of the DC Motor 17 click board.
 * This example demonstrates the use of DC Motor 17 click,
 * we first control motion A by driving it forward motion for 5 seconds, 
 * than applying short brakes it for 2 second, then driving it in reverse for 5 seconds
 * and stop the motor for 2 seconds.
 * In the second part of the example, we control motion B by the same principle.
 * Results are being sent to the Usart Terminal where you can track their changes.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "dcmotor17.h"

static dcmotor17_t dcmotor17;   /**< DC Motor 17 Click driver object. */
static log_t logger;            /**< Logger object. */

void application_init ( void ) {
    log_cfg_t log_cfg;              /**< Logger config object. */
    dcmotor17_cfg_t dcmotor17_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_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "      DC Motor 17 click     \r\n" );
    log_printf( &logger, "----------------------------\r\n" );
    log_info( &logger, " Application Init " );

    // Click initialization.

    dcmotor17_cfg_setup( &dcmotor17_cfg );
    DCMOTOR17_MAP_MIKROBUS( dcmotor17_cfg, MIKROBUS_1 );
    if ( dcmotor17_init( &dcmotor17, &dcmotor17_cfg ) == DIGITAL_OUT_UNSUPPORTED_PIN ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    dcmotor17_default_cfg ( &dcmotor17 );
    log_info( &logger, " Application Task " );
}

void application_task ( void ) {
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "          Motor A           \r\n" );
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "  Start the motor forward.  \r\n" );
    dcmotor17_forward( &dcmotor17, DCMOTOR17_SEL_OUT_A );
    Delay_ms( 5000 );
    
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "       Stop the motor.      \r\n" );
    dcmotor17_stop( &dcmotor17, DCMOTOR17_SEL_OUT_A );
    Delay_ms( 2000 );
    
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "  Start the motor reverse.  \r\n" );
    dcmotor17_reverse( &dcmotor17, DCMOTOR17_SEL_OUT_A );
    Delay_ms( 5000 );
    
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "       Stop the motor.      \r\n" );
    dcmotor17_stop( &dcmotor17, DCMOTOR17_SEL_OUT_A );
    Delay_ms( 2000 );
    
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "          Motor B           \r\n" );
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "  Start the motor forward.  \r\n" );
    dcmotor17_forward( &dcmotor17, DCMOTOR17_SEL_OUT_B );
    Delay_ms( 5000 );
    
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "       Stop the motor.      \r\n" );
    dcmotor17_stop( &dcmotor17, DCMOTOR17_SEL_OUT_B );
    Delay_ms( 2000 );
    
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "  Start the motor reverse.  \r\n" );
    dcmotor17_reverse( &dcmotor17, DCMOTOR17_SEL_OUT_B );
    Delay_ms( 5000 );
    
    log_printf( &logger, "----------------------------\r\n" );
    log_printf( &logger, "       Stop the motor.      \r\n" );
    dcmotor17_stop( &dcmotor17, DCMOTOR17_SEL_OUT_B );
    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.