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. For this project reader should have knowledge of how to start with AVR and interface LCD with AVR.
Components Required
7. 16 x 2 LCD Board
Circuit Design
Fig. 1: Circuit Diagram of LM317 IC based Variable Power Supply
Fig. 2: Circuit Diagram of Voltage Divider Circuit for power output
Here R1 and R2 are the resistors and Vin is the input voltage. The output voltage Vout is given as:
Vout = Vin 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
R1:R2 = 5 : 1
So we can take R1= 5kOhm and R2=1k Ohm
Code Explanation
Conversion Process Example
Fig. 3: Block Diagram of AVR ATMega16 based Variable Power Supply
How we display decimals:
Step 1: Multiply ‘val’ with 100
I = a / 100 = 2493 / 100 = 24 (Integer)
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
Project Source Code
### LCD.H #ifndef LCD_H_ #define LCD_H_ #define rs PA7 #define rw PA6 #define en PA4 void lcd_init(); void dis_cmd(char); void dis_data(char); void lcdcmd(char); void lcddata(char); void clrscr(); void gotoxy(char,char); void LCD_write_string(const char *); void lcd_write_int(int,unsigned int); #endif Variable.C /* * VARIABLE.c * * Created: 5/29/2014 3:53:39 PM * Author: GANESH SELVARAJ */ #define F_CPU 16000000UL #include <avr/io.h> #include <util/delay.h> #include "lcd.h" void SetADC() { ADMUX|=(1<<REFS0); ADCSRA=(1<<ADEN)|(7<<ADPS0); } uint16_t ReadADC(uint8_t ch) { //Select ADC Channel ch must be 0-7 ch=ch&0b00000111; ADMUX&=0b11100000; ADMUX|=ch; //Start Single conversion ADCSRA|=(1<<ADSC); //Wait for conversion to complete while(!(ADCSRA & (1<<ADIF))); //Clear ADIF by writing one to it ADCSRA|=(1<<ADIF); return(ADC); } void Waiting(int j) // simple delay function { uint8_t i; for(i=0;i<j;i++) _delay_ms(200); } int main(void) { int v; _delay_ms(50); // delay of 50 milliseconds SetADC(); lcd_init(); LCD_write_string("Adj Power Supply"); while(1) { gotoxy(1,1); LCD_write_string("Voltage:"); v=((ReadADC(0)/1024.00)*3000.00); lcd_write_int((v/100),2); dis_data('.'); lcd_write_int((v%100),2); dis_data('V'); dis_data(' '); Waiting(2); } } LCD.H /* * EG_LCD.c * * Created: 2/9/2014 10:49:54 PM * Author: stranger */ #include<avr/io.h> #include<util/delay.h> #include<inttypes.h> #include "lcd.h" void LCD_write_string(const char *str) //store address value of the string in pointer *str { int i=0; while(str[i]!='