dcmotor18  2.0.0.0
Main Page

DC Motor 18 click

DC Motor 18 Click is a compact add-on board that contains a brushed DC motor driver. This board features the TB9051FTG, an automotive PWM-type single-channel H-Bridge DC brushed motor driver from Toshiba Semiconductor.

click Product page


Click library

  • Author : Luka Filipovic
  • Date : Aug 2021.
  • Type : PWM type

Software Support

We provide a library for the DCMotor18 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for DCMotor18 Click driver.

Standard key functions :

Example key functions :

Example Description

This example application showcases ability of click

board to control DC motors using PWM modulation in both directions and different speeds.

The demo application is composed of two sections :

Application Init

Initialization of MCU communication modules (PWM, ADC, UART)

and additioal gpio for control of the device. Then sets default configuration that enables device to control the DC motor.

void application_init ( void )
{
log_cfg_t log_cfg;
dcmotor18_cfg_t dcmotor18_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
dcmotor18_cfg_setup( &dcmotor18_cfg );
DCMOTOR18_MAP_MIKROBUS( dcmotor18_cfg, MIKROBUS_1 );
err_t init_flag = dcmotor18_init( &dcmotor18, &dcmotor18_cfg );
if ( PWM_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
dcmotor18_default_cfg ( &dcmotor18 );
log_info( &logger, " Application Task " );
Delay_ms( 500 );
}

Application Task

Drives motor in one direction from 0 to 100% of the speed using

PWM, and then returns it back to 0. Then changes the rotation direction and repeats the process of increasing and decreasing acceleration.

void application_task ( void )
{
static int8_t duty_cnt = 1;
static int8_t duty_inc = 1;
float speed = duty_cnt / 10.0;
static uint8_t direction = 1;
dcmotor18_set_direction( &dcmotor18, direction );
dcmotor18_set_speed_percentage ( &dcmotor18, speed );
if ( dcmotor18.direction )
{
log_printf( &logger, "<<< " );
}
else
{
log_printf( &logger, ">>> " );
}
log_printf( &logger, "Speed: %d%%\r\n", ( uint16_t )( duty_cnt * 10 ) );
if ( 10 == duty_cnt )
{
duty_inc = -1;
}
else if ( 0 == duty_cnt )
{
duty_inc = 1;
direction = !direction;
}
duty_cnt += duty_inc;
Delay_ms( 1000 );
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.DCMotor18

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


dcmotor18_cfg_t
DC Motor 18 Click configuration object.
Definition: dcmotor18.h:131
dcmotor18_cfg_setup
void dcmotor18_cfg_setup(dcmotor18_cfg_t *cfg)
DC Motor 18 configuration object setup function.
dcmotor18_t
DC Motor 18 Click driver selector.
Definition: dcmotor18.h:108
dcmotor18_read_an_pin_current
err_t dcmotor18_read_an_pin_current(dcmotor18_t *ctx, float *data_out)
Read AN pin current.
dcmotor18_init
err_t dcmotor18_init(dcmotor18_t *ctx, dcmotor18_cfg_t *cfg)
DC Motor 18 initialization function.
application_task
void application_task(void)
Definition: main.c:70
dcmotor18_set_enable
void dcmotor18_set_enable(dcmotor18_t *ctx, uint8_t state)
Set enable pin state.
dcmotor18_default_cfg
err_t dcmotor18_default_cfg(dcmotor18_t *ctx)
DC Motor 18 default configuration function.
DCMOTOR18_MAP_MIKROBUS
#define DCMOTOR18_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: dcmotor18.h:88
dcmotor18_set_direction
void dcmotor18_set_direction(dcmotor18_t *ctx, uint8_t state)
Set diretion of motor rotation.
application_init
void application_init(void)
Definition: main.c:34
dcmotor18_set_speed_percentage
err_t dcmotor18_set_speed_percentage(dcmotor18_t *ctx, float speed_percentage)
Set speed output percentage.