Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 26th June 2008, 01:18 PM   (permalink)
Default Atmega48 ADC

Hello.


I'm trying to use the adc on my atmega48, but I'm having a little difficulties.

Why can't I load anything into the ADC registers like ADMUX and ADCSRA?
I've tried using LDI and MOVW and MOV, but AVRstudio tells me its an invalid register or that oprand 2 is out of range.


here is the current code:



.include "m48def.inc"

.def temp =r16 ;definer variabler
.def temp2 =r20
.def delay =r17
.def delay2 =r18
.def delay3 =r19


What am I doing wrong?



init:
bclr PRADC ;Skru på ADC
bset ADEN ;
bset REFS1 ;Referanse =AVCC
bset ADLAr ;resultatet er venstrejustert
bset ADPS2 ;
bset ADPS1 ;prescaler =1/128
bset ADPS0 ;
ser temp ;temp=0xff
out DDRB,temp ;PORTB er utganger
clr temp ;temp=0x00
out DDRC,temp ;PORTC er innganger

loop:

bset adsc
adloop:
sbrc ADCSRA,ADSC
rjmp adloop
movw temp,ADCH
out portb,temp
rjmp loop
Daniek is offline  
Old 26th June 2008, 03:14 PM   (permalink)
Default

Hey

Sorry I forgot about the box...

Shouldn't there be an "edit" box somewhere?

Anyway I also get an error message for the "sbrc ADCSRA,ADSC" line, why can't i test this bit? I think the error message is "operand 2 is out of range"

The other part I was wondering about was how I'm supposed to copy the ADCH register, I can't figure out which instruction to use.

I'm new to Atmel devices as you can probably tell.


Code:
 

.include	"m48def.inc"

.def	temp	=r16	;define variables
.def	temp2	=r20
.def	delay	=r17
.def	delay2	=r18
.def	delay3	=r19


init:
	bclr	pradc		;Skru på ADC
	bset	aden		;
	bset	refs1		;Referanse =AVCC
	bset	adlar		;resultatet er venstrejustert
	bset	adps2		;
	bset	adps1		;prescaler =1/128
	bset	adps0		;
	ser	temp		;temp=0xff
	out	DDRB,temp	;PORTB er utganger
	clr	temp		;temp=0x00
	out	DDRC,temp	;PORTC er innganger

loop:

	bset	ADSC                ;start conversion
adloop:	
	sbrc	ADCSRA,ADSC   ;conversion done?
	rjmp	adloop             ;if not, go back to adloop
	movw	temp,ADCH       ;put ad result in temp register
	out	PORTB,temp      ;put temp in portb		
	rjmp	loop	           ;loop forever
Edit

I see the Edit box disappears after a while.

Last edited by Daniek; 26th June 2008 at 03:16 PM.
Daniek is offline  
Old 26th June 2008, 03:28 PM   (permalink)
Default

Quote:
Originally Posted by Daniek View Post
I'm new to Atmel devices as you can probably tell.
Your problem is that most people around here are also new to Atmels. You may get a better response over at AVR Freaks.

Mike.
Pommie is online now  
Old 26th June 2008, 05:08 PM   (permalink)
Default

Okay.

Thanks Pommie.

Just made a thread at AVRfreaks. Hope I get an answer there.
Daniek is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Atmega48 svtiss General Electronics Chat 2 22nd May 2007 09:10 PM



All times are GMT. The time now is 09:06 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker