Atmega48 ADC

Status
Not open for further replies.

Daniek

New Member
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
 
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:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…