fan5  2.1.0.0
Main Page

Fan 5 click

Fan 5 Click is a compact add-on board specially designed for fan speed management. This board features Microchip’s TC654, a PWM mode fan speed controller with FanSense™ technology suitable for brushless DC fans.

click Product page


Click library

  • Author : Stefan Ilic
  • Date : Dec 2022.
  • Type : I2C type

Software Support

We provide a library for the Fan 5 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 Fan 5 Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of FAN 5 click board by controlling and regulating the fan motors speed.

The demo application is composed of two sections :

Application Init

Initializes the driver, performs the click default configuration, reads

manufacturer id and sets configuration in correspondence to user-selected mode.

void application_init ( void )
{
log_cfg_t log_cfg;
fan5_cfg_t fan5_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
fan5_cfg_setup( &fan5_cfg );
FAN5_MAP_MIKROBUS( fan5_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == fan5_init( &fan5, &fan5_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( FAN5_ERROR == fan5_default_cfg ( &fan5 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
uint8_t id = 0;
fan5_get_mfr_id( &fan5, &id );
log_printf( &logger, " Manufacturer ID: 0x%X \r\n", ( uint16_t ) id );
#if defined FAN_CONTROL_MODE
fan5_set_fan_fault1( &fan5, 500 );
#else
fan5_set_fan_fault1( &fan5, 0 );
#endif
log_info( &logger, " Application Task " );
}

Application Task

If Fan control is selected example will monitor FAN 1 speed and if the speed

falls below 500 RPM for longer then 2.4 seconds fan output will be disabled. In other case, example is showcasing speed control by changing duty cycle and monitoring fan speed.

void application_task ( void )
{
#if defined FAN_CONTROL_MODE
uint16_t speed = 0;
uint8_t flag_data = 0;
fan5_get_rpm1( &fan5, &speed);
log_printf( &logger, " SPEED: %d RPM \r\n", speed );
if ( FAN5_FAULT == fan5_get_fault_state( &fan5 ) )
{
fan5_get_status_flags ( &fan5, &flag_data );
log_printf( &logger, " FLAG: %d \r\n", flag_data );
if ( FAN5_F1F_FLAG & flag_data )
{
log_printf( &logger, " FAN SPEED DROPED !!! \r\n" );
log_printf( &logger, " OUTPUT IS DISABLED \r\n" );
for( ; ; );
}
}
Delay_ms( 2000 );
#else
uint16_t speed;
uint8_t duty_value;
for ( duty_value = FAN5_30_PER_DUTY; duty_value <= FAN5_100_PER_DUTY; duty_value++ )
{
fan5_set_duty_cycle( &fan5, duty_value );
log_printf( &logger, " Duty value: %d \r\n", ( uint16_t ) duty_value );
Delay_ms( 5000 );
fan5_get_rpm1( &fan5, &speed);
log_printf( &logger, " SPEED: %d RPM \r\n", speed );
Delay_ms( 500 );
}
#endif
}

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.Fan5

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.


fan5_get_status_flags
err_t fan5_get_status_flags(fan5_t *ctx, uint8_t *status_data)
Fan 5 get status flags.
FAN5_100_PER_DUTY
#define FAN5_100_PER_DUTY
Definition: fan5.h:133
fan5_set_duty_cycle
err_t fan5_set_duty_cycle(fan5_t *ctx, uint8_t duty_cycle)
Fan 5 set duty cycle.
fan5_init
err_t fan5_init(fan5_t *ctx, fan5_cfg_t *cfg)
Fan 5 initialization function.
fan5_turn_on_fans
err_t fan5_turn_on_fans(fan5_t *ctx)
Fan 5 turn on fans.
fan5_set_fan_fault1
err_t fan5_set_fan_fault1(fan5_t *ctx, uint16_t fault1_value)
Fan 5 set FAN1 fault threshold.
fan5_t
Fan 5 Click context object.
Definition: fan5.h:171
application_task
void application_task(void)
Definition: main.c:83
FAN5_MAP_MIKROBUS
#define FAN5_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: fan5.h:158
fan5_get_fault_state
err_t fan5_get_fault_state(fan5_t *ctx)
Fan 5 get fault state.
FAN5_30_PER_DUTY
#define FAN5_30_PER_DUTY
Fan 5 duty cycle setting.
Definition: fan5.h:118
FAN5_F1F_FLAG
#define FAN5_F1F_FLAG
Definition: fan5.h:112
fan5_cfg_t
Fan 5 Click configuration object.
Definition: fan5.h:188
fan5_get_rpm1
err_t fan5_get_rpm1(fan5_t *ctx, uint16_t *fan1_speed)
Fan 5 get speed of FAN1.
fan5_cfg_setup
void fan5_cfg_setup(fan5_cfg_t *cfg)
Fan 5 configuration object setup function.
fan5_get_mfr_id
err_t fan5_get_mfr_id(fan5_t *ctx, uint8_t *mfr_id)
Fan 5 read manufacturer identification.
fan5_default_cfg
err_t fan5_default_cfg(fan5_t *ctx)
Fan 5 default configuration function.
application_init
void application_init(void)
Definition: main.c:34
FAN5_ERROR
@ FAN5_ERROR
Definition: fan5.h:206
fan5_turn_off_fans
err_t fan5_turn_off_fans(fan5_t *ctx)
Fan 5 turn off fans.
FAN5_FAULT
@ FAN5_FAULT
Definition: fan5.h:207