Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
serendipity
PostPosted: May 19, 2010 - 05:31 PM
Newbie


Joined: May 17, 2010
Posts: 4


Hello to the AVR community.

I have written a code that take analog values from my hardware and through a bluetooth working in serial port profile displays data on the hyperterminal.I am using an atmega168 processor.

I successfully, after a lot of struggle was able to transmit data over the UART and was able to display float values but the values that I get are incorrect.

I am posting my code below....any help or suggestions as to why I get a constant stream of -64's for all my analog values would be really helpful.


Code:

uint16_t readADC(int pin)
{
   uint8_t low, high;
   uint16_t sample;
ADMUX =(1<<ADLAR)|(0<<REFS1)|(0<<REFS0)|(pin & 0x0F);
 ADCSRA|=(1<<ADEN)| (1<<ADIF)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
        //  start conversion
        ADCSRA|= (1<<ADSC);
   // ADSC is cleared when the conversion finishes
   while (bit_is_set(ADCSRA, ADSC));
low = ADCL;
   high = ADCH;

   // combine the two bytes
   sample = (high << 8) | (low & 0xFF);
   return sample;
}



Result :

Vout=-64 Vbias=-64 X=-64 Y=-64 Z=-64, Number:295
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: May 19, 2010 - 09:19 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13848
Location: Vancouver, BC

Quote:
1<<ADLAR
Why are you doing this when you are using the entire value? You will end up with all the readings multiplied by 64.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
vishal4a3
PostPosted: Nov 03, 2011 - 04:09 AM
Newbie


Joined: Oct 21, 2011
Posts: 2


hi i am facing problem with atmega8.while reading Analog battery voltage.(i.e. i am displaying the voltages of battery while charging a cellphone through it.

some times ADC is reading very low values . i.e even though the battery voltage is 13V it showing it has 12V.


please help me in solving this issue

Regards
vishal
 
 View user's profile Send private message  
Reply with quote Back to top
indianajones11
PostPosted: Nov 03, 2011 - 06:09 AM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

Vishal don't hijack other people's threads ( we don't multitask on unrelated problems with > 1 poster in a given thread ). Start your own thread for this problem .

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits