Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Atmega8 voltmeter hang-up somewhere

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,381
As my part of a project , An Atmega8 based AC 230 voltmeter made ,and works normally .
but some times it hangup or stuck {stuck the LCD display],especially
when toggles [rapidaly connect and disconnect] the input .
what may be the problem .
I am providing some information of the voltmeter

AVCC ---> VCC
Vref connected to capacitor 104 [.1uf]
230 volt ac stepdowned to 6 volt with bridge rectifre ,filtred with 1uf capacitor and finally given to a voltage divider

Some code
Code:
int main(void)  
{   
  
     int adc_value1=0;	
	 LCD_Init(2,16);     
    adc_init();
    
     LCD_Clear();
	 LCD_GoToXY(0,0);    
	 LCD_DisplayString("  G-Electron");
	 _delay_ms(1000);
	 
	 //
 	
	while(1)	
	{ 	
       adc_value1 =  volt_read_disply();
	   LCD_GoToLine(1);	 
	   LCD_DisplayString(" Volt : ");  
	   LCD_Printf("%d",adc_value1);
	   LCD_DisplayString("V");  
	   _delay_ms(1300);
	} 
}


int volt_read_disply()
{   int i,adc_value[40]={0}; int temp =0, adc=0;
	
	adc_init();
	  for(i=0; i<=40;i++)                        // samples taking from 41 times 9.4milli second taken about on complte half cycle
	  { 
		 adc_value[i] = read_adc(0);  // reading voltage 		  	  	  
	 }
	  
	 temp = adc_value[0];	 
	for(i=0; i<=40; i++)
	{
		if(temp<adc_value[i])
		temp=adc_value[i];
	}
	adc=temp;			 
		  
      return (adc*0.224828935);	
   
}
 

variable adc is int type and you are multiplying int value with float value without cating the int value to float or double. You will get 0 readings.
 
variable adc is int type and you are multiplying int value with float value without cating the int value to float or double. You will get 0 readings.

Is it correct
Code:
 return ((int)temp*0.224828935);
 

Additionally:
Code:
int volt_read_disply()
specifies the "volt_read_disply" function returns a value of type 'int' so whatever the result of the fractional multiplication will be lost.

Brian.
 
Additionally:
Code:
int volt_read_disply()
specifies the "volt_read_disply" function returns a value of type 'int' so whatever the result of the fractional multiplication will be lost.

Brian.
Sir are you mean that ,may i need to change the function as Double volt_read_disply() ?
 
Last edited:

Change return type from int to double and read the adc value into a double type variable and convert it to string and print it on lcd.
 
Yes, when you prefix a function with a data type, like the 'int' in "int volt_read_disply()" you tell the compiler that it will return an integer value. The compiler then prepares suitable memory storage to carry the value back to where the function was called. If the storage size doesn't match the data you put in it, some will be lost or residual bits will be included.

Depending on the compiler, it should show an error but even if it didn't the value returned from the function would be truncated or misinterpreted.

So answering your question, yes, you should change the function type to double or float.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top