# [SOLVED]building a voltage regulator

Status
Not open for further replies.

#### Deexith Hasan

##### Advanced Member level 4
i'm designing a voltage regulator that allows only voltage range between 200-250v ac 50hz to the output and blocks all other voltages....
i'm designing this with help of atmega8......

my problem is the adc of mcu or the total system of mcu samples the input at every 21 ms but my input signal is 50hz is it normal........
i tried to increase the crystal frequency(20MHZ->40Mhz) but got little difference in sampling rate of 19ms....

- - - Updated - - -

i have attached the code and proteus simulation

Code:
#include <avr/io.h>
#include <util/delay.h>
#include <lcd_4bit.h>

#define F_CPU 20000000

void delay()
{
unsigned char i;
for(i=0;i<10;i++)
{
lcd_cmdwrite(0xC0);
lcd_datawrite((0x30+i));
PORTD=~(PORTD|0b01111111);
_delay_ms(800);

}
}

void main(void)
{
unsigned char u=0;
unsigned long b;
lcd_reset();

lcd_install();
DDRD=0XFB;

while(1)
{

if(u==0)
{
lcd_cmdwrite(0X01);
lcd_goto(0,0);

lcd_stringwrite("ON DELAY");
delay();

u=1;

lcd_cmdwrite(0x01);
b=b*449;
lcd_goto(1,0);
lcd_goto(1,0);
lcd_stringwrite(" V=");
lcd_nowrite(b);
if (b>210000&&b<250000)
{
while((PIND&0B00000100)==0);

lcd_goto(0,0);
lcd_stringwrite("PERFECT");
PORTD=PORTD|0B00000001;
}
}

while(b>210000&&b<250000)
{
b=b*449;
lcd_goto(1,0);
lcd_stringwrite(" V=");
lcd_nowrite(b);
lcd_goto(0,0);
lcd_stringwrite("PERFECT");
PORTD=PORTD|0B00000001;
PORTD=~(PORTD|0b01111111);

}
PORTD=PORTD&0B11111110;
lcd_cmdwrite(0x01);

while(!(b>210000&&b<250000))
{
PORTD=PORTD&0B11111110;

lcd_goto(0,0);

lcd_stringwrite("CHECK VOLTAGE");
u=0;
b=b*449;
lcd_goto(1,0);
lcd_stringwrite(" V=");
lcd_nowrite(b);
}

}

}

#### Easyrider83

##### Advanced Member level 5
Hard to say anything without schematics. What should your atmega do? It can be done by only one comparator.

#### srizbf

##### Advanced Member level 5
one of the reasons for such execessive delay is :
some part of your c code is eating up the time.

for a 20mhz atmega , it have lot of time for this application(of finding the voltage range and displaying)

one solution is , write your code in atmega assembly language . this will not have the problem you have faced.

another , if you are not familiar with assembly, find that part of the c code which eats up the time and rewrite.

#### Easyrider83

##### Advanced Member level 5
Just make a conversion and compare on interrupts. It will be able to catch value every 1ms and even less.

#### srizbf

##### Advanced Member level 5
what is the range of input (minm to maximum)given to adc ?
usable range ?
8 or 10bits ?

#### Surender Reddy

##### Full Member level 2
Connect your input source to a relay circuit and control the relay with Atmega

So you are getting ADC values, check what are the ADC values for the input of 200-250v.
Depending on the min and max values ON/OFF the relay.

So

#### Deexith Hasan

##### Advanced Member level 4
after rectification i'm getting 16v for 230v ac i/p and made 2.5v using voltage divider and measured using ADC of mcu.........i need to place this setup in mains which handles 40 amps can i use 40 amp relay kt-909 or contactor relay??

#### srizbf

##### Advanced Member level 5
better to use a contactor for this.

Deexith Hasan

Points: 2