Discussion in "AVR Discussion Forum" started by    sammy mutua    May 11, 2009.
Mon May 11 2009, 02:36 PM
#1
can somebody help me with a program code in assembly language for ADC conversion using atmega168 controller, i will appreciate, thank you. have already done it in c language but i want to do it in assembly language.
Tue May 12 2009, 08:49 AM
#2
if you've done it in C then assembly wont be difficult. I just want you to go through chapter 21 of datasheet of ATmega168.

It has got all the information of registers you are going to set for ADC conversions.
Write something, will help you as you go on.

[Topic moved to AVR Discussion forum]
Tue May 12 2009, 09:28 AM
#3
thank you very much Ajay for the reply, i am going to read the data sheet and mean while i have also found the following code for at tiny 45 adc conversion,
ad_init:
ldi rmp, 0b00000000
out ADMUX, rmp
ldi rmp, 0b11001111
out ADCSRA, rmp

ad_init_done:
ret

ad:
in tmp, ADCSRA
ldi rmp, 1<<ADSC
or tmp, rmp
out ADCSRA, tmp


ad_loop:
in rmp, ADCSRA
andi rmp, 1<<ADIF
ldi tmp, 1<<ADIF
cpse rmp, tmp
breq ad_loop

ad_done:
ret

will the code for atmega168 ressemble this one or what changes need to be adjusted in the code?
Tue May 12 2009, 02:22 PM
#4
AVR has mostly same set of registers in use. you can find codes online but its always good to practice on your own, its one time investment that will help u for lifetime
 sammy mutua like this.
Wed May 13 2009, 01:24 PM
#5
dear Ajay,
Thank you very much for the reply, i have read the data sheet and using the example for attiny 45 i have followed up to enabling the conversion and indicated my understanding using the comments as follows.



ad_init:
ldi rmp, 0b00000000 ;selecting the reference voltage, the right adjustment of the
out ADMUX, rmp ; result and the input channels i.e. ADC0
ldi rmp, 0b11001111 ; select to enable the ADC, to start conversion, for auto
out ADCSRA, rmp ;triggering, for complete conversion interrupt through SREG i-bit
; and for prescaler factor i.e. 128



However, i am not able to understand the rest of the code for conversion specifically where we have 1<<ADSC please help.
Thu May 14 2009, 08:36 AM
#6
in that code, he is using interrupts for ADC, where as you wont need it as far as i know. so change the value being loaded to ADCSRA register.

by default ADCSRB register is 0x00 so your ADC will be running in free running mode.

now once the ADC is enabled, you need to wait for ADIF flag to go high which indicates the conversion is complete and then read the ADC registers for converted value.

you can also set DIDR0 register to disable Digital input buffer which reduces the power loss.

Dont bother about what he/she wrote in attiny code, coz i told you every write for his own requirements
 sammy mutua like this.
Thu May 14 2009, 12:32 PM
#7
Thank you for the help. i also noticed that with studio 416 which am using, it is not possible to load registers such as ADCSRA, ADMUX even through other registers otherwise they require you deal with their internal bit registers as follows:
setting the ADMUX register;
cbi REFS1,sensor ;selecting the reference voltage
cbi REFS0,sensor ;ie AREF in this case
cbi ADLAR,sensor ;for right adjusting the result
cbi MUX3,sensor ;selecting the input channel i.e. ADC0
cbi MUX2,sensor
cbi MUX1,sensor
cbi MUX0,sensor
and setting ADCSRA register;
sbi ADEN, sensor ; select to enable the ADC
sbi ADSC,sensor ;to start conversion
cbi ADATE,sensor;for auto triggering
cbi ADIF, sensor ; for conversion complete interrupt
sbi ADIE,sensor ; through SREG i-bit
sbi ADPS2,sensor ; prescaler factor i.e. 128
sbi ADPS1,sensor
sbi ADPS0,sensor

Is there any other method of doing it?
Thu May 14 2009, 12:47 PM
#8
well whats the prob in the prev code? i dont find any..

use r16 for reading and writing.. make sure you have defined rmp and tmp before writing that code. you can take a look at AVR tutorial once to know what basic stuff is needed before dealing with AVR.
Thu May 14 2009, 01:13 PM
#9
i checked the tutorial and ofcourse have defined the two registers but the instructions out ADMUX, rmp and in tmp, ADCSRA indicates an error -register out of range ie 0*7a. so i tried setting each register in the two registers and it indicated no error.
Thu May 14 2009, 01:33 PM
#10
out of range.. hmm.. strange..

what have u defined as rmp and tmp?

Get Social

Information

Powered by e107 Forum System

Conversation

poojab51296
Sun Aug 20 2017, 10:23 AM
i am intending to interface sd card with STM32F4 and want to write a file in sd card using SPI protocol but using HAL only. Can anyone help me PLEASE!!!!
poojab51296
Sun Aug 20 2017, 10:22 AM
hello
rawat742
Fri Aug 18 2017, 11:37 AM
hi @ angel patel i will attach a file i hope it will be helpfull for you
ExperimenterUK
Mon Aug 14 2017, 09:57 PM
@ angel patel... just log in and post your problem
Mon Aug 14 2017, 01:45 PM
angel patel
hey any one help to make the led scrolling display
desuza6
Sat Jul 29 2017, 07:09 AM
I see the code for step motor h l 298 to rotate 45 degree, but all delay time, if I want to input sensor to h the pulses to stepmotor
rammichael
Thu Jul 27 2017, 12:05 PM
okay fine
ExperimenterUK
Wed Jul 26 2017, 07:51 PM
Please post questions in the forum, the chat box is for chat
msd007
Wed Jul 26 2017, 11:27 AM
i need code if any one have aduc706 interfacing lcd 16*2
msd007
Wed Jul 26 2017, 11:26 AM
pl help me how to write code of interfacing ADuc7026 controlleo lcd pl any one help me hoe to initializend configure the direction

Downloads

Comments

abdullah6484
Tue Aug 22 2017, 10:21 PM
crank.tp
Mon Aug 21 2017, 02:17 PM
poojab51296
Sun Aug 20 2017, 10:18 AM
kira113
Sat Aug 19 2017, 08:40 AM
Pirateak
Thu Aug 17 2017, 02:02 PM
sathishksk71
Wed Aug 16 2017, 04:47 AM
rawat742
Sun Aug 13 2017, 05:49 PM
alparslanbagriyanik
Fri Aug 11 2017, 08:10 AM

Online

Guests: 76, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37882
Newest member: abdullah6484
Forum Activity
rawat742 Avatar
Posted By rawat742
Mon Aug 21 2017, 09:13 PM
Dear sir, I want purchase a debugger for 8051 , p...
rawat742 Avatar
Posted By rawat742
Mon Aug 21 2017, 09:09 PM
Dear Sir, I want to programe for de...
rawat742 Avatar
Posted By rawat742
Mon Aug 21 2017, 09:06 PM
Dear Sir, thanks now I have done almost my pro...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Aug 20 2017, 08:31 PM
"when i compile the program using keil ide i got s...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Aug 20 2017, 08:15 PM
You will probably get better results from a specia...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Aug 20 2017, 06:42 PM
Your data is retained in the simulation.Write data...
rawat742 Avatar
Posted By rawat742
Sun Aug 20 2017, 01:23 PM
Dear sir , I face a error mostly *** WARNING L1...
rawat742 Avatar
Posted By rawat742
Sun Aug 20 2017, 11:21 AM
Dear Sir, thanks I have done Acc to you now I am...
poojab51296 Avatar
Posted By poojab51296
Sun Aug 20 2017, 10:29 AM
Sir/Ma'am,I am trying to interface Sd card with ST...
kira113 Avatar
Posted By kira113
Sat Aug 19 2017, 08:52 AM
hello everyone i write a simple program using c la...