speedsense  2.1.0.0
Main Page

Speed Sense click

Speed Sense Click is a compact add-on board that allows you to measure the speed and rotation of a spinning object. This board features the A17501, a dual output differential speed and direction sensor from Allegro Microsystems. It has a high-speed switching bandwidth of up to 40kHz for two different signals. The sensor has two independent output channels with options for high-resolution XOR speed, pulse, and direction protocol.

click Product page


Click library

  • Author : Nenad Filipovic
  • Date : Oct 2023.
  • Type : GPIO type

Software Support

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

Standard key functions :

Example key functions :

Example Description

This library contains the API for the Speed Sense Click driver for the speed and direction signal state detection for every magnetic pole pair.

The demo application is composed of two sections :

Application Init

Initialization of GPIO and log UART.

void application_init ( void )
{
log_cfg_t log_cfg;
speedsense_cfg_t speedsense_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
speedsense_cfg_setup( &speedsense_cfg );
SPEEDSENSE_MAP_MIKROBUS( speedsense_cfg, MIKROBUS_1 );
if ( DIGITAL_OUT_UNSUPPORTED_PIN == speedsense_init( &speedsense, &speedsense_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
log_printf( &logger, "-----------------------\r\n" );
}

Application Task

This example demonstrates the use of the Speed Sense Click board. The demo application displays the direction of movement and rotation speed (rotations per minute) of the ring magnet with three pairs of rotating poles positioned in the sensor operating range.

void application_task ( void )
{
uint8_t direction = 0, speed = 0;
speed = speedsense_get_speed( &speedsense );
direction = speedsense_get_direction( &speedsense );
if ( start_measure & speed )
{
if ( SPEEDSENSE_DIR_STATE_FWD == direction )
{
log_printf( &logger, " Direction: Forward\r\n" );
}
else
{
log_printf( &logger, " Direction: Reverse\r\n" );
}
log_printf( &logger, " Speed: %.2f rpm\r\n", SPEEDSENSE_CALC_RMP / signal_duration );
log_printf( &logger, " Duration: %lu ms\r\n", signal_duration );
log_printf( &logger, " Time: %lu ms\r\n", time_cnt );
log_printf( &logger, "-----------------------\r\n" );
}
else if ( ( !start_measure ) & ( !speed ) )
{
}
Delay_ms( 1 );
}

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

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.


time_cnt
uint32_t time_cnt
Definition: main.c:32
signal_duration
uint32_t signal_duration
Definition: main.c:33
speedsense_t
Speed Sense Click context object.
Definition: speedsense.h:109
SPEEDSENSE_MAP_MIKROBUS
#define SPEEDSENSE_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: speedsense.h:97
speedsense_init
err_t speedsense_init(speedsense_t *ctx, speedsense_cfg_t *cfg)
Speed Sense initialization function.
speedsense_cfg_t
Speed Sense Click configuration object.
Definition: speedsense.h:120
speedsense_get_speed
uint8_t speedsense_get_speed(speedsense_t *ctx)
Speed Sense CHA pin reading function.
start_timer
uint32_t start_timer
Definition: main.c:34
application_task
void application_task(void)
Definition: main.c:70
SPEEDSENSE_START_NEW_MEASURE
#define SPEEDSENSE_START_NEW_MEASURE
Definition: speedsense.h:79
SPEEDSENSE_STOP_MEASURE
#define SPEEDSENSE_STOP_MEASURE
Speed Sense measurement state data values.
Definition: speedsense.h:78
application_init
void application_init(void)
Definition: main.c:39
speedsense_cfg_setup
void speedsense_cfg_setup(speedsense_cfg_t *cfg)
Speed Sense configuration object setup function.
SPEEDSENSE_CALC_RMP
#define SPEEDSENSE_CALC_RMP
Definition: main.c:29
speedsense_get_direction
uint8_t speedsense_get_direction(speedsense_t *ctx)
Speed Sense CHB pin reading function.
SPEEDSENSE_DIR_STATE_FWD
#define SPEEDSENSE_DIR_STATE_FWD
Speed Sense output signal states data value.
Definition: speedsense.h:69
start_measure
uint8_t start_measure
Definition: main.c:31