Jump to content
ELFORUM - Forumul Electronistilor
Sign in to follow this  
Guest xmecus

Conversia A/D la ATMEGA8535

Recommended Posts

Guest xmecus

Salut! Cine ma ajuta si pe mine cu un program in asm ca sa realizez conversia A/N folosind convertorul din microcontroler(scrie ceva in datasheet, dar cad scriu in avrstudio comenzile alea, imi da erori: ca nu recunoaste registrii-ADMUX,ADCSRA, - invalid register :drinkers: Sper sa se inteleaga ce-am scris.

Share this post


Link to post
Share on other sites

Salut

Ai scris la inceputul programului liniile astea?Pt ca altfel nu stie de registrele alea.

.nolist.include "m8535def.inc".list
uite o portiune de cod care initializeaza si apoi intreruperea in acre se citesc valorile

E un exemplu prost de stil; de scriere pt ca in loc sa scrii ADMUX=0x60 e de preferat sa scrii ADMUX = 1<

 

.equ inceputRAM = SRAM_START + 64;64 bytes pt stiva;LASA MAI MULT LOC DACA AI NEVOIE DE STIVA;ultima valoare a convertsiei ADC + canalul de pe care s-a citit.equ ult_ADC	 = inceputRAM+5.equ canal_ADC	 = inceputRAM+6;***ADC;initeor tmp0,tmp0sts ult_ADC, tmp0ser tmp0sts canal_ADC, tmp0;255=conversie invalidaldi tmp0, 0x60out ADMUX,tmp0;aden=1, adsc=0, adate=1, adie=1, prescaler=4ldi tmp0, 0xBAout ADCSRA, tmp0sei;start adcsbi ADCSRA, ADSC
Sa nu iei direct valorile cu care am initializat eu registrele ADMUX ADCSRA etc pt ca probabil nu e ceea ce vrei cel mai bine te uiti in datasheet

 

din pacate subrutina de intrerupere care citea valoarea conversiei nu am mai scris-o (am trecut la programarea in C intre timp) Dar nu e mare lucru trebuie citit si stocat ADCL si ADCH

 

Bafta

Share this post


Link to post
Share on other sites
Guest xmecus

ASTA E PROGRAMUL SCRIS IN AVRSTUDIO:.include "m8535def.inc";PROGRAM PRINCIPAL ;INITIALIZARE STIVARESET: ldi R16,low(RAMEND) out SPL,R16 ldi R16,high(RAMEND) out SPH,R16 ;seteaza ADLAR=1; selecteza canalul ADC0ldi R16,$20 out ADMUX,R16;ADEN=1; ADATE=1;prescaler=2(oricum nu prea stiu ce face prescalerul asta)ldi R17,$A2 out ADCSRA,R17inceput:sbi ADCSRA, ADSCldi R19, ADCHldi R20,$FF ;initializez portb de iesire(am niste leduri acolo)out DDRB,R20out PORTB,R19rjmp inceputAVCC, si AREF i-am legat la Vcc=5V deci cand selectez referinta pun REFS1 si REFS0 in 0(Internal Vref turned off), pun ADLAR in 1 pt ca rezultatul il vreau aliniat la stanga(citesc rezult doar din registrul ADCH), conversie dpar pe 8biti. Apoi, dau enable la convertor, AutoTriger ala banuiesc ca declanseaza automat conversia cand simte semnal(aici nu prea pricep), si-l pun in 1, apoi setez ceasul pt convertor la o patrime din frecventa XTAL-ului(care la mine e de 14MHz).Cu ce gresesc? :smt009

Share this post


Link to post
Share on other sites
Guest costas

Nu ai nevoie de free running mode decat daca lucrezi cu intreruperi. setezi conversie, astepti sa se termine, citesti ADH si gata_____________________________________________________ldi R17,$82out ADCSRA,R17inceput:sbi ADCSRA, ADSCloop:sbis ADCSRA, ADIFrjmp loopsbi ADCSRA, ADIF; clear by writing one ldi R19, ADCHldi R20,$FF ;initializez portb de iesire(am niste leduri acolo)out DDRB,R20out PORTB,R19sbi ADCSRA, ADIFrjmp inceput ______________________________________________________________spor.

Share this post


Link to post
Share on other sites
Guest xmecus

va multumesc. am rezolvat problema.include "m8535def.inc";************************************************************;* PROGRAM PRINCIPAL *;************************************************************;-----------INITIALIZARE STIVA-------------------------------------------------RESET: ldi R16,low(RAMEND) out SPL,R16 ldi R16,high(RAMEND) out SPH,R16 ;seteaza ADLAR=1; selecteza canalul ADC0 ldi R16,$20 out ADMUX,R16 ser R20 out DDRB,R20 ;inializare portb de iesire ldi R17,$C0;--------------Inceputul conversiei-----------------------------------------------start_conv: out ADCSRA,R17 ;ADEN=1; ADATE=1;convertor CLK=2 wait: sbic ADCSRA,ADSC ;testeaza daca ADSC=0(s-a terminat conversia) rjmp wait in R20,ADCH out PORTB,R20 rjmp start_conv

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.