indexcounter 2.0.0.0
Main Page

Index Counter click

Index Counter Click is a simple prototyping high precision Hall-Effect switch solution with direction detection.

click Product page


Click library

  • Author : MikroE Team
  • Date : May 2020.
  • Type : GPIO type

Software Support

We provide a library for the IndexCounter 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

‍This library contains API for IndexCounter Click driver.

Standard key functions :

Example key functions :

  • This function returns a state of the direction DIR ( AN ) pin.

    ‍uint8_t indexcounter_get_dir ( indexcounter_t *ctx );

    - This function returns a state of the speed SPD ( RST ) pin.

    ‍uint8_t indexcounter_get_speed ( indexcounter_t *ctx );

    Examples Description

‍This application enables usage of Index counter click board which can be used to measure rotational speed.

The demo application is composed of two sections :

Application Init

‍Initilaziation of GPIO and write log.

void application_init ( void )
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info(&logger, "---- Application Init ----");
// Click initialization.
INDEXCOUNTER_MAP_MIKROBUS( cfg, MIKROBUS_1 );
indexcounter_init( &indexcounter, &cfg );
}
#define INDEXCOUNTER_MAP_MIKROBUS(cfg, mikrobus)
Definition indexcounter.h:65
void indexcounter_cfg_setup(indexcounter_cfg_t *cfg)
Config Object Initialization function.
INDEXCOUNTER_RETVAL indexcounter_init(indexcounter_t *ctx, indexcounter_cfg_t *cfg)
Initialization function.
void application_init(void)
Definition main.c:80
Click configuration structure definition.
Definition indexcounter.h:112

Application Task

‍This is an example which demonstrates the use of the Index Counter click board. This example shows the direction of movement, Rotations Per Minute ( RPM or speed ) of the three pairs of rotating poles positioned in the sensor operating range. Results are being sent to the Usart Terminal where you can track their changes.

void application_task ( void )
{
// Task implementation.
speed_state = indexcounter_get_speed( &indexcounter );
dir_state = indexcounter_get_dir( &indexcounter );
{
}
if ( ( !enable_speed ) && ( !speed_state ) )
{
}
Delay_1ms();
}
#define INDEXCOUNTER_SPEED_DISABLE
Definition indexcounter.h:84
#define INDEXCOUNTER_SPEED_ENABLE
Definition indexcounter.h:83
#define INDEXCOUNTER_ONE_MIN_CONV_MS
Definition indexcounter.h:86
uint8_t indexcounter_get_speed(indexcounter_t *ctx)
Get state of the speed pin function.
uint8_t indexcounter_get_dir(indexcounter_t *ctx)
Get state of the direction pin function.
uint8_t dir_state
Definition main.c:39
void application_task(void)
Definition main.c:105
float speed_rpm
Definition main.c:46
uint8_t enable_speed
Definition main.c:41
void log_display(float rpm_val)
Definition main.c:50
uint8_t speed_state
Definition main.c:40
uint32_t start_timer
Definition main.c:45
uint8_t n_pole_pairs
Definition main.c:42
uint32_t time_cnt
Definition main.c:43
uint32_t pulse_ms
Definition main.c:44

Note

‍Additional Functions :

  • void log_display ( float rpm_val ) - The function displays all results and a float value with a comma with two decimal places.

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.IndexCounter

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.