![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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 I see the Edit box disappears after a while. Last edited by Daniek; 26th June 2008 at 03:16 PM. | |
| |
| | (permalink) |
| Your problem is that most people around here are also new to Atmels. You may get a better response over at AVR Freaks. Mike. | |
| |
| | (permalink) |
| Okay. Thanks Pommie. Just made a thread at AVRfreaks. Hope I get an answer there. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Atmega48 | svtiss | General Electronics Chat | 2 | 22nd May 2007 09:10 PM |