vreg2  2.0.0.0
Main Page

VREG 2 click

VREG 2 click is a voltage regulator click, with outstanding performances.

click Product page


Click library

  • Author : MikroE Team
  • Date : Jan 2020.
  • Type : PWM type

Software Support

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

Standard key functions :

  • Config Object Initialization function.

    void vreg2_cfg_setup ( vreg2_cfg_t *cfg );

  • Initialization function.

    VREG2_RETVAL vreg2_init ( vreg2_t *ctx, vreg2_cfg_t *cfg );

  • Click Default Configuration function.

    void vreg2_default_cfg ( vreg2_t *ctx );

Example key functions :

  • This function starts PWM module.

    void vreg2_pwm_start ( vreg2_t *ctx );

  • This function stops PWM module.

    void vreg2_pwm_stop ( vreg2_t *ctx );

  • This function sets the PWM duty cycle.

    void vreg2_set_duty_cycle ( vreg2_t *ctx, pwm_data_t duty_cycle );

Examples Description

This application enables voltage regulation.

The demo application is composed of two sections :

Application Init

Initializes the GPIO driver and configures the PWM peripheral for controlling VREG2 voltage output.

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.
vreg2_cfg_setup( &cfg );
cfg.pwm = (0x3C) ; cfg.an = (0x03) ;
vreg2_init( &vreg2, &cfg );
vreg2_set_duty_cycle( &vreg2, duty_cycle );
vreg2_pwm_start( &vreg2 );
}

Application Task

Based on the data received from the uart the voltage output will be increased or decreased.

void application_task ( void )
{
// Task implementation.
switch ( ctrl_flag )
{
case 0:
{
duty_cycle = (uint32_t)vreg2.pwm_period * 20 / 100;
log_printf( &logger, "Volatage set to : %d %%\r\n", duty_cycle );
ctrl_pre_flag = ctrl_flag;
ctrl_flag = 1;
break;
}
case 1:
{
duty_cycle = (uint32_t)vreg2.pwm_period * 50 / 100;
log_printf( &logger, "Volatage set to : %d %%\r\n", duty_cycle );
if ( ctrl_pre_flag == 0 )
{
ctrl_pre_flag = ctrl_flag;
ctrl_flag = 2;
}
else if ( ctrl_pre_flag == 2 )
{
ctrl_pre_flag = ctrl_flag;
ctrl_flag = 0;
}
break;
}
case 2:
{
duty_cycle = (uint32_t)vreg2.pwm_period * 70 / 100;
log_printf( &logger, "Volatage set to : %d %%\r\n", duty_cycle );
if ( ctrl_pre_flag == 1 )
{
ctrl_pre_flag = ctrl_flag;
ctrl_flag = 3;
}
else if ( ctrl_pre_flag == 3 )
{
ctrl_pre_flag = ctrl_flag;
ctrl_flag = 1;
}
break;
}
case 3:
{
duty_cycle = (uint32_t)vreg2.pwm_period * 95 / 100;
log_printf( &logger, "Volatage set to : %d %%\r\n", duty_cycle );
ctrl_pre_flag = ctrl_flag;
ctrl_flag = 2;
break;
}
default:
{
log_printf( &logger, "Something broke\r\n");
}
}
vreg2_set_duty_cycle( &vreg2, duty_cycle );
Delay_ms( 1500 );
Delay_100ms();
}

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

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.


vreg2_init
VREG2_RETVAL vreg2_init(vreg2_t *ctx, vreg2_cfg_t *cfg)
Initialization function.
vreg2_cfg_t::an
pin_name_t an
Definition: vreg2.h:112
vreg2_cfg_t::pwm
pin_name_t pwm
Definition: vreg2.h:108
application_task
void application_task(void)
Definition: main.c:65
vreg2_set_duty_cycle
void vreg2_set_duty_cycle(vreg2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
application_init
void application_init(void)
Definition: main.c:38
vreg2_pwm_start
void vreg2_pwm_start(vreg2_t *ctx)
Start PWM module.
vreg2_cfg_t
Click configuration structure definition.
Definition: vreg2.h:104
vreg2_cfg_setup
void vreg2_cfg_setup(vreg2_cfg_t *cfg)
Config Object Initialization function.