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
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>
#include <adc.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=adc_read(5);
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=adc_read(5);
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=adc_read(5);
b=b*449;
lcd_goto(1,0);
lcd_stringwrite(" V=");
lcd_nowrite(b);
}
}
}