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] wrong voltage on adc in atmega 8!

Status
Not open for further replies.

samna_asadi

Junior Member level 3
Junior Member level 3
Joined
Mar 19, 2011
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,519
hi
i have written a program to read lm35 temp sensor from adc4 on atmega8.
i`ve already set the DDRC to 0x00 but its giving me wrong number.i tried to manually measure the voltage on lm35 and atmega`s pin , on lm35 side it was 0.34 that was good but on the atmega it was 1.2 or 3 and when i connect lm35 to adc4 pin the voltage change to something else that is not right!
i`ve connected lm35 straight to atmega.
what can i do with it , what`s the problem?
tnx
 
Last edited:

ok tnx for reply...

Code:
#define  F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include "d:\D\e\electronic\library\lcdlibv20\lcd.c"


void screen();

int main(void)
{
	_delay_ms(1000);
	
	
	
	
	
	DDRC=239;
	DDRB=254;
	DDRD=31;
	PORTD=248;
	PORTB=255;
	ADMUX=0b00000100;
	ADCSRA=0b10100110;
	

	LCDInit(0);
	LCDCmd(12);

	ADCSRA |= 64;
	
   while(1)
   {
	screen();
	 _delay_ms(1000);  
   }
   
}


void screen()
{
		
	LCDWriteStringXY(10,1,"      ");
	LCDWriteIntXY(10,1,(ADCL+(ADCH>>8)/2),-1);
	
	
}

it just show 4 or 5 on the screen.
tnx.
 
Last edited:

lowbyte is 8-bit waid, adcres is 16-bit wide. ADCL is stored in lowbyte. ADCH is stored in adcres and shifted 8 bits so that ADCH will be in the high byte of adcres. adcres is ored with lowbyte. result is adcres.

eg: lowbyte = 0xAB, ADCH = 0xDE.

adcres = 0xDE
adcres = 0xDE00
adcres = 0xDEAB
 

tnx for for the replay.that right shift was my mistake but the problem still exist.its my first time for using adc, and i don`t know how its gonna be but the adc4 is on 1.295 volt and when lm35 with 0.34 volt connect to this pin its 1.293 volt and adc doesn`t get the right result!!
i don`t know whats wrong if u could help!
 

sadasdasd.jpg
Code:
#define  F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util\delay.h>
#include "d:\D\e\electronic\library\lcdlibv20\lcd.c"


void screen();

int main(void)
{
	_delay_ms(1000);
	
	
	
	
	
	DDRC=239;
	DDRB=254;
	DDRD=31;
	PORTD=248;
	PORTB=255;
	ADMUX=0b00000100;
	ADCSRA=0b10100110;
	

	LCDInit(0);
	LCDCmd(12);

	ADCSRA |= 64;
	
	while(1)
	{
		screen();
		_delay_ms(1000);
	}
	
}


void screen()
{
	
	LCDWriteStringXY(10,1,"      ");
	LCDWriteIntXY(10,1,((ADCL | (ADCH<<8))/2),-1);
	
	
}
 

You should comment your code so that we know what you are trying to do
code like
Code:
DDRC=239;
	DDRB=254;
	DDRD=31;
	PORTD=248;
	PORTB=255;
	ADMUX=0b00000100;
	ADCSRA=0b10100110;

doesn't make any sense unless you use a calculator to convert decimal to binary for the ports and check the datasheet for the function of each bit of the ADC registers.

You are using an LCD library, are you sure it is not messing up the pin direction of the PC4 pin?
 

You are using an LCD library, are you sure it is not messing up the pin direction of the PC4 pin?


i was going to say that "i`ve already check the header file" but i figured maybe there is something wrong with the micro and there was, i changed the micro and problem solved, maybe it was some power leakage...
tnx any way for giving me your time.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top