Discussion in "AVR Discussion Forum" started by    sammy mutua    May 11, 2009.
Thu May 14 2009, 07:12 pm
#11
have defined r16 as rmp and r17 as tmp .
Thu May 14 2009, 07:20 pm
#12
hmm.. try using r15 instead of r17 then try..
 sammy mutua like this.
Fri May 15 2009, 01:51 pm
#13
hi, the problem is still the same even when i use the higher registers.
Sun May 17 2009, 08:14 pm
#14
any body with a working adc assembly code for atmega 168 please help. :mad
Mon May 18 2009, 03:37 pm
#15
well ok i will help you writing it.
Lets setup ADCMUX, i am assuming Aref is AVcc with cap at Aref pin.
so REFS1:REFS0 = 01
assuming channel to be 0
so Mux3:Mux0 = 0

so ADMUX will be 0b01000000 = 0x40

now setup ADCSRA reg.
here we will enable ADC, Disable Auto Trigger, No ADC Interrupts, ADC clock pre-scalar to 0.
so ADCSRA = 0b10000000 = 0x80

Now ADC is enabled and setup is complete..

we will start a conversion and read it.

to start a conversion, Make ADSC bit 1.
monitor this bit coz it will remain high till the conversion is in process. as soon as it goes low, conversion completes.

once the conversion is compelete, you can read ADCL and ADCH register. remember that we have used ADLAR = 0 in ADCSRA register. so ADCH will contain higher two bits and lower 8 bits will be stored in ADCL.

Can you try writing a code now?
 sammy mutua like this.
Mon May 25 2009, 06:02 pm
#16
hi, i also found out that the ATtiny45 code i had posted above could work with ATmega168 but only if the instructions IN and OUT are replaced with LDS and STS instructions, this is because in ATmega168 the ADC registers are above 0x70 but the instructions IN and OUT can only access up to 0x3F in i/o space.

this is the code;

.include "m168def.inc"
.def rmp = R16
.def tmp = R17

ldi rmp, 0b00000000
sts ADMUX, rmp
ldi rmp, 0b11001111
sts ADCSRA, rmp

ad:
lds tmp, ADCSRA
ldi rmp, 1<<ADSC
or tmp, rmp
sts ADCSRA, tmp
ad_loop:
lds rmp, ADCSRA
andi rmp, 1<<ADIF
ldi tmp, 1<<ADIF
cpse rmp, tmp
breq ad_loop
ret


thank you all for your help.
 ajay_bhargav like this.
Wed May 27 2009, 04:22 pm
#17
cool thank you too.. came to know something new...
 sammy mutua like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am