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

Wed Nov 08 2017, 01:35 PM
Anirudh jain
I want to burn code in atmel 89s51 24pc 0329 but cannot get the connection with the burner. Can somebody provide me with the circuit diagram for connecting controller to burner. I'm using usb burner
Thu Nov 02 2017, 11:44 AM
karpal
write a program to exchange the content of b register with external RAM address 02CFH help me
Wed Nov 01 2017, 05:47 PM
sanae
i am using the DHT11 but i'm getting some errors in the simulate the programe in proteus 8 professional,: 1)cannot find model file 'DHTXX.MDF'.2)simulation failed due to netlist linker error(s).
Fri Sep 29 2017, 02:45 AM
Maaz
i am doing the same project on verilog please contact me [email protected]
Wed Sep 20 2017, 12:36 AM
Ted
In a missing pulse detector using a 555 timer connected as a monostable vibrator with a PNP transistor,how does the positve input pulse turn on the PNP transistor?
Sun Sep 03 2017, 02:29 PM
martymarty
How do I connect an <NOKIA 1100 LCD > to an atmega328P ?
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

Downloads

Comments

PANDIKOTESWARARAO
Mon Nov 20 2017, 07:40 PM
Hemantika
Sun Nov 19 2017, 07:34 PM
Wed Nov 15 2017, 10:46 AM
Ansh12
Sat Nov 11 2017, 03:43 AM
AngelGT93
Fri Nov 10 2017, 06:53 AM
JardCrocker
Wed Nov 08 2017, 05:27 PM
vivitern
Tue Nov 07 2017, 09:08 AM
catrons
Sat Nov 04 2017, 10:46 PM

Online

Guests: 55, Members: 0 ...

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

Members: 37918
Newest member: PANDIKOTESWARARAO
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 20 2017, 10:18 PM
Here is a version of the tutorial that reads a key...
Ansh12 Avatar
Posted By Ansh12
Mon Nov 20 2017, 02:15 AM
As a starting point, can you tell us how much of t...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Nov 19 2017, 08:35 PM
As a starting point, can you tell us how much of t...
Ansh12 Avatar
Posted By Ansh12
Fri Nov 17 2017, 04:07 AM
I am looking keypad interfacing program. I was rea...
JardCrocker Avatar
Posted By JardCrocker
Wed Nov 08 2017, 05:29 PM
Hi...i am a new user here. I was also facing the s...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 07 2017, 07:13 PM
> It employs a fairly advanced technique to detect...
vivitern Avatar
Posted By vivitern
Tue Nov 07 2017, 09:33 AM
I own a used Clavia ddrum4 SE drum module. It empl...
bvdb Avatar
Posted By bvdb
Wed Oct 18 2017, 01:50 AM
I purchased the RKitL51 8051 C compiler from Raiso...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Oct 16 2017, 11:44 PM
That looks complicated.Is 8051_BLK a standard 80...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 15 2017, 07:29 PM
According to this, gmail should support POP3.https...