Intermediate
30 min

Design more efficient motor drive systems using TC78H660FTG and PIC18F57Q43

Experience motor control like never before

DC Motor 17 Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

DC Motor 17 Click

Dev. board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

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

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

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
PA0
AN
A Channel Input 2
PA7
RST
Standby
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
B Channel Input 1
PB0
PWM
B Channel Input 2
PA6
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

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

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.