fan9 2.1.0.0
Main Page

Fan 9 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Ilic
  • Date : Jan 2024.
  • Type : I2C type

Software Support

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

Standard key functions :

  • fan9_cfg_setup Config Object Initialization function.
    void fan9_cfg_setup ( fan9_cfg_t *cfg );
    void fan9_cfg_setup(fan9_cfg_t *cfg)
    Fan 9 configuration object setup function.
    Fan 9 Click configuration object.
    Definition: fan9.h:242
  • fan9_init Initialization function.
    err_t fan9_init ( fan9_t *ctx, fan9_cfg_t *cfg );
    err_t fan9_init(fan9_t *ctx, fan9_cfg_t *cfg)
    Fan 9 initialization function.
    Fan 9 Click context object.
    Definition: fan9.h:219
  • fan9_default_cfg Click Default Configuration function.
    err_t fan9_default_cfg ( fan9_t *ctx );
    err_t fan9_default_cfg(fan9_t *ctx)
    Fan 9 default configuration function.

Example key functions :

  • fan9_set_direction This function is used to set direction of Fan 9 click board.
    void fan9_set_direction ( fan9_t *ctx, uint8_t dir );
    void fan9_set_direction(fan9_t *ctx, uint8_t dir)
    Fan 9 set direction function.
  • fan9_write_reg This function reads a data bytes from the selected register by using I2C serial interface.
    err_t fan9_write_reg ( fan9_t *ctx, uint8_t reg, uint16_t data_in );
    err_t fan9_write_reg(fan9_t *ctx, uint8_t reg, uint16_t data_in)
    Fan 9 register writing function.
  • fan9_set_pwm This function is used to get PWM value of Fan 9 click board.
    err_t fan9_set_pwm ( fan9_t *ctx, uint8_t pwm_val );
    err_t fan9_set_pwm(fan9_t *ctx, uint8_t pwm_val)
    Fan 9 set PWM value function.

Example Description

This example demonstrates the use of FAN 9 click board, by changing speed of the fan from 0 to 100 percent, then decreasing it back to 0.

The demo application is composed of two sections :

Application Init

Initializes the driver and performs the click default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
fan9_cfg_t fan9_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
fan9_cfg_setup( &fan9_cfg );
FAN9_MAP_MIKROBUS( fan9_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == fan9_init( &fan9, &fan9_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( FAN9_ERROR == fan9_default_cfg ( &fan9 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
fan9_set_pwm( &fan9, 10 );
// Waiting for motor to start.
while ( 0 == fan9_get_rd_pin( &fan9 ) );
log_info( &logger, " Application Task " );
}
@ FAN9_ERROR
Definition: fan9.h:263
#define FAN9_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: fan9.h:203
uint8_t fan9_get_rd_pin(fan9_t *ctx)
Fan 9 get RD pin state function.
void application_init(void)
Definition: main.c:29

Application Task

Changes the speed of fans by changing the PWM duty cycle.

The results are being displayed via USB UART where you can track their changes.

void application_task ( void )
{
static int8_t duty_cnt = 10;
static int8_t duty_inc = 10;
uint8_t direction = FAN9_DIRECTION_CW;
fan9_set_pwm( &fan9, duty_cnt );
log_printf( &logger, " Set PWM: %d%% \r\n", ( uint16_t ) duty_cnt );
if ( 100 == duty_cnt )
{
duty_inc = -10;
}
else if ( 0 == duty_cnt )
{
duty_inc = 10;
}
duty_cnt += duty_inc;
Delay_ms( 2000 );
}
#define FAN9_DIRECTION_CW
Fan 9 direction setting.
Definition: fan9.h:162
void application_task(void)
Definition: main.c:69

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

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.