In this blog post, I will show you how to use the Vreg click from MikroElektronika with an Arduino Uno, using one Arduino Uno click shield from MikroElektronika.

With this click board we can make a variable power supply, capable of delivering an output voltage between 1.25V and 17V, for an input voltage of maximum 20V. Rough and fine adjustments of the output voltage have been implemented, and we can also choose some preset voltages. Output can be turned on or off in the Arduino code.

Vreg click from MikroElektronika

First, we will take a look on the hardware, focusing on the operating principle and on some calculations regarding the use of DAC and ADC to control the LM317 regulator. Then, a code example for Arduino IDE is provided. Finally, some extra explanations and conclusions are given.

## Working principle

To understand how the Vreg click works it pays off to draw the schematic of the power stage in a different way:

Vreg click: power stage

Now things look different. The op-amp is part of the LM317’s feedback loop. Its output will change in such way that Vsense matches Vset. Vsense is also applied to one of the A/D channels of the MCP3204, so it can be checked in software, too.

The only missing thing, in my opinion, is a lowpass filter between the op-amp output and the ADJ pin. Without this filter, oscillation is possible, with a negative impact on the output jitter.

## Maximum and minimum voltages

The VREG click documentation specifies a maximum input voltage of 20V. The maximum voltage that we can get depends on the dropout over the LM317. While the datasheet doesn’t give an explicit value for the dropout voltage, on page 4 we find a minimum value of 3V for the “Input-to-output differential voltage”. Considering this, we can calculate the maximum output voltage as:

$Vout_{max}=Vin&space;-&space;3V&space;=&space;20V&space;-&space;3V&space;=&space;17V$

Back to our schematic. When the output voltage is 17V, the value of the SENSE voltage is:

$Vsense_{max}&space;=&space;Vout_{max}&space;\cdot&space;\left&space;(\frac{R9}{R9+R8}&space;\right&space;)&space;=&space;17V&space;\cdot&space;\left&space;(&space;\frac{470\Omega&space;}{470\Omega&space;+4700\Omega&space;}&space;\right&space;)$

thus,

$Vsense_{max}&space;=&space;1.5454&space;V$

Let’s take a closer look at the MCP4921 DAC, and we start by computing the LSB voltage, which is the ideal voltage between two successive codes. The gain will be set to 1, as this is the only setting that will work when the click board is powered from 3.3V. If we switch the power jumper into the 5V position, then we will be able to use gain x2. My choice is to set the gain to 1, as it allows for a better use of the dynamic range of the MCP4921.

$V_{LSB}&space;=&space;\frac{V_{REF}}{2^{12}}&space;=&space;\frac{2.048V}{4096}&space;=&space;0.5mV$

The value to be written to the DAC to achieve an output of 1.5454V is:

$DAC&space;digital&space;code_{max}&space;=&space;\frac{Vsense_{max}}{V_{LSB}}&space;=&space;\frac{1.5454V}{0.5V}&space;=&space;3090$

A similar computation must be made for the minimum output voltage. The minimum voltage is 1.25V, for which we calculate a value of:

$Vsense_{min}&space;=&space;Vout_{min}&space;\cdot&space;\left&space;(\frac{R9}{R9+R8}&space;\right&space;)&space;=&space;1.25V&space;\cdot&space;\left&space;(&space;\frac{470\Omega&space;}{470\Omega&space;+4700\Omega&space;}&space;\right&space;)$

$Vsense_{min}&space;=&space;Vout_{min}&space;\cdot&space;\left&space;(\frac{R9}{R9+R8}&space;\right&space;)&space;=&space;0.113V$

The lowest value to be written to the DAC to obtain this output value is:

$DAC&space;digital&space;code_{min}&space;=&space;\frac{0.1136V}{5mV}&space;=&space;227$

## MCP3204: voltage sensing

The MCP3204 is a four channel, 12 bit ADC. In this click board it is used to read the input voltage, the output voltage and the sense voltage applied to the inverting input of the LM358. The schematic is as follows:

Vreg click: voltage sensing

From the MCP3204 datasheet we have:

$Digital&space;output&space;code&space;=&space;\frac{4096&space;\cdot&space;V_{ADC}}&space;{V_{ref}}$

where $V_{ADC}$ is the voltage applied to one channel of the MCP3204 and $V_{ref}&space;=&space;2.048V$ is the reference voltage. Thus, we have:

$V_{ADC}=&space;ADC&space;output&space;code&space;\cdot&space;\frac{V_{ref}}{4096}&space;=&space;\frac{ADC&space;output&space;code}{2000}$

Let’s assume we want to measure Vin, which is applied to channel2, via a voltage divider made by R3 and R4. In this case, we have:

$V_{ADC}&space;=&space;V_{in}&space;\cdot&space;\frac{R3}{R4+R3}$

$V_{in}&space;=&space;V_{ADC}\cdot&space;\frac{R3+R4}{R3}&space;=&space;V_{ADC}\cdot&space;\frac{4700\Omega&space;+470\Omega&space;}{470\Omega&space;}&space;=&space;V_{ADC}\cdot&space;11$

$V_{in}&space;=&space;\frac{ADC&space;output&space;code}{2}\cdot&space;11&space;=&space;ADC&space;output&space;code&space;\cdot&space;0.0055$

The same computation can be made for the other channels, as all the voltage dividers in the sensing circuits have identical values.

There’s an artificial load implemented with the other half of the LM358 used as a comparator. Note that the implementation is as a simple comparator, with no hysteresis. I would expect to have that load to jiggle between on and off states when the voltage is close to the threshold.

For a reference voltage of 2.048V, and considering the voltage divider made of R18 and R17, the threshold voltage to switch on the load is:

$Vout_{load}&space;=&space;V_{ref}&space;\cdot&space;\left&space;(&space;\frac{R17+R18}{R17}&space;\right&space;)&space;=&space;2.048V&space;\cdot&space;\frac{1500\Omega+4700\Omega}{1500\Omega}&space;=&space;8.465V$

## Output switch

The output of the Vreg click can be switched on and off via the PWM signal on the mikroBUS socket. Put the PWM pin low to disable output, put it high (or just leave it floating, R15 will pull it high).

1 2 3
Share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.