Are you an electronic hobbyist? Then an **adjustable power supply** is a must for your various needs. This project explains **how to make a LM317 based adjustable power supply unit with a digital display.**

__Components Required__

1. LM317 IC

2. Resistor – 240 Ohms

3. Capacitors – 0.1uF, 10uF

4. Potentiometer – 5k

5. 30V/1A Adapter (or a transformer + Bridge wave rectifier IC)

6. ATMega16 Developments Board

7. 16 x 2 LCD

7. 16 x 2 LCD Board

__Circuit Design__

Well the power supply circuit is very simple and can be found in the datasheet of LM317 itself.

*Fig. 1: Circuit Diagram of LM317 IC based Variable Power Supply*

The output voltage is given by the equation,

**Vout = 1.25 (1+ R2/R1) + Iadj x R2**

What we need to design is the additional voltmeter kind of arrangements using a microcontroller in order to display the output voltage value accurately. For this, we use the ADC feature of the microcontroller.

But the problem is that ATmega16 can only take up to 5V. Input voltage more than that can fry up the controller.

Solution: A Voltage divider circuit!

*Fig. 2: Circuit Diagram of Voltage Divider Circuit for power output*

Here R1 and R2 are the resistors and V_{in }is the input voltage. The output voltage V_{out }is given as:

**V**_{out }= V_{in} X R2/(R1 + R2) . . . . . . . . . . . . . . . (1)

We choose the resistor values based on our requirements. Like, say now our maximum voltage to be measured is 30V but we can only give up to 5V to our controller.

So here maximum Vin = 30V and maximum Vout = 5V

Substituting in equation (1) and on solving, we get

R1:R2 = 5 : 1

So we can take R1= 5kOhm and R2=1k Ohm

## Code Explanation

- Initialize the 16 bit ADC mode of the controller.

- Initialize the LCD function.

- Enter an infinite loop.

- Read the voltage level at ADC1, convert it into a 16-bit discreet value (0 to 1023) and store it in a variable “val”.

- Divide the value at “val” by 1024 and then multiply it with 30. This gives you the original applied voltage value.

- Now display this value in the LCD.

__Conversion Process Example__

• Let us say that we applied some input voltage Vin= 24V to the system

• Now from the design equation, the output voltage of voltage divider circuit can be calculated. Here the output would be 4V, which is the input to the ADC pin of microcontroller.

• The controller would covert the analog value (0-5V) into a discreet value of range, 0-1023. In this case the value would be around 819.

• Next, this discreet value is again converted into the original input voltage range which is 0-30V through programming. Here the value obtained would be 23.99, which is almost equal to 24V!

*Fig. 3: Block Diagram of AVR ATMega16 based Variable Power Supply*

__How we display decimals:__

Let us say we got a value val = 24.93

Now “lcd_write_int()” function only accepts whole numbers and no decimal part.

So what we do is,

__Step 1: Multiply ‘val’ with 100__

Val x 100 = 24.93 x 100 = 2493 (say we name it ‘a’)

__Step 2: Obtain integer part by using ‘/ ’operator__

I = a / 100 = 2493 / 100 = 24 (Integer)

__Step 3: Obtain decimal part as another integer using ‘%’ operator__

D = a % 100 = 2493 % 100 = 93

__Step 4: __

First display the integer part followed by ‘.’ and then the decimal part.

Example: display(I+’.’+D) à I.D

*Fig. 4: Representational image of display panel for AVR ATMega16 based Adjustable Power Supply*

.

## Comments

## hi i want to program for

hi i want to program for varibale power supply( -5 to +5 ) to be displayed and i want to calibrate it through the pushbuttons,

i.e for +5v it must show +5v on one time and the same +5 to be showed when i give +2.5v after i calibrate it for span value of 0 to +2.5v(without change in circuitary).

Please guide me.

## Very nice