Discussion in "AVR Discussion Forum" started by    vijay    Mar 21, 2013.
Thu Mar 21 2013, 05:14 pm
#1
My code for adc work properly in protyus...But not run properly on actual hardware...Its give high state to PORTB and PORTD pins(actually it has to show digital data converted by ADC )..Plz look at my code..give me correction
Thu Mar 21 2013, 05:15 pm
#2

Attachment
Fri Mar 22 2013, 04:07 am
#3
while (ADCSRA & (0<<ADSC));/


does not look right !


[ Edited Fri Mar 22 2013, 04:12 am ]
Fri Mar 22 2013, 11:28 am
#4
can you explain that Vijay? what are you trying to check in that loop?
Sat Apr 13 2013, 05:16 pm
#5
Actually i am trying to send converted data to port like PORTD=ADCL..... when i apply input to adc channel greater than 3 volt all the LED is going to blink(PORTD=0xff PORTB=0x03;(total 10 led)) which means input voltage is nearer to 4.99 volt....Can u tell me why this happen???.....Also for some voltage like 2.64 volt all LED is go high...

Some other readings that i had taken....input v output v
2.43 2.49
0.31 0.36
0.09 0.15

Attachment
Sun Apr 14 2013, 12:49 pm
#6
@vijay.parmar1992

Agreed with ExperimenterUK...

It's while(!(ADCSRA & (1<<ADIF))); // waits till conversion completes

replace the above line in ur code..
Sun Apr 14 2013, 03:10 pm
#7
I am now using while((ADCSRA & (1<<ADSC))!=0){ }; Is it ok???
Sun Apr 14 2013, 07:28 pm
#8
connection that i am using for atmmega 8
vcc=avcc=avref=5v(approximately 5.4v)
gnd=agnd=0(gnd)

using internal 8mhz clcok..
i am not using any capacitor between aref and gnd ??is it require..
Mon Apr 15 2013, 06:10 pm
#9
This is fine.. if you get a non zero value means bit is still set, if its zero then while loop will exit.
while(!(ADCSRA & (1<<ADIF)));

capacitor is not mandatory.


[ Edited Mon Apr 15 2013, 06:11 pm ]
Mon Apr 15 2013, 11:39 pm
#10


I am now using

 while((ADCSRA & (1<<ADSC))!=0){ }; 

Is it ok???

vijay.parmar1992



It's getting complicated

As I see it...
 while((ADCSRA & (1<<ADSC))!=0){ };  

Will wait until the ADSC bit goes low.
you could just say
 while((ADCSRA & (1<<ADSC))){ };  



 while(!(ADCSRA & (1<<ADIF))); 

I believe will wait until the ADSC bit goes high.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

gtaletrzua
Fri May 03 2024, 10:55 am
Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am