Current Limit 4 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
- Author : Nenad Filipovic
- Date : Aug 2023.
- Type : ADC/I2C type
This library contains API for the Current Limit 4 Click driver for the current limiting to a certain value and displays the sources a current proportional to the load current [A].
- MikroSDK.Board
- MikroSDK.Log
- Click.CurrentLimit4
currentlimit4_cfg_setupConfig Object Initialization function.
void currentlimit4_cfg_setup ( currentlimit4_cfg_t *cfg );currentlimit4_initInitialization function.
err_t currentlimit4_init ( currentlimit4_t *ctx, currentlimit4_cfg_t *cfg );currentlimit4_default_cfgClick Default Configuration function.
err_t currentlimit4_default_cfg ( currentlimit4_t *ctx );currentlimit4_set_limitCurrent Limit 4 set current limit function.
err_t currentlimit4_set_limit ( currentlimit4_t *ctx, currentlimit4_limit_t current_limit );currentlimit4_get_currentCurrent Limit 4 get current function.
err_t currentlimit4_get_current ( currentlimit4_t *ctx, float *current );currentlimit4_get_power_goodCurrent Limit 4 power good indication function.
uint8_t currentlimit4_get_power_good ( currentlimit4_t *ctx );Initialization of I2C and ADC module and log UART. After driver initialization, the app executes a default configuration and set the minimum current limit threshold to 1.0 [A].
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
currentlimit4_cfg_t currentlimit4_cfg; /**< Click config object. */
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
currentlimit4_cfg_setup( ¤tlimit4_cfg );
CURRENTLIMIT4_MAP_MIKROBUS( currentlimit4_cfg, MIKROBUS_POSITION_CURRENTLIMIT4 );
err_t init_flag = currentlimit4_init( ¤tlimit4, ¤tlimit4_cfg );
if ( ( ADC_ERROR == init_flag ) || ( I2C_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( CURRENTLIMIT4_ERROR == currentlimit4_default_cfg ( ¤tlimit4 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
Delay_ms ( 100 );
}This example demonstrates the use of the Current Limit 4 Click board™. The demo application displays the source current proportional to the load current and an appropriate message when the current reaches the limit. Results are being sent to the UART Terminal, where you can track their changes.
void application_task ( void )
{
static float current = 0;
if ( CURRENTLIMIT4_OK == currentlimit4_get_current( ¤tlimit4, ¤t ) )
{
if ( CURRENTLIMIT4_POWER_GOOD == currentlimit4_get_power_good( ¤tlimit4 ) )
{
log_printf( &logger, " Current : %.3f [A]\r\n", current );
}
else
{
log_printf( &logger, " Input voltage is lower then undervoltage protection threshold.\r\n" );
}
Delay_ms ( 1000 );
}
}This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.