Forum: Mikrocontroller und Digitale Elektronik ADC Tutorial keine Messwerte.


von Daniel L. (grorkef)


Angehängte Dateien:

Lesenswert?

Hallo,

ich bins mal wieder :) ich hab mich gerade mit dem Beispiel aus dem ADC 
Tutorial 
beschäftigt(http://www.mikrocontroller.net/articles/AVR-Tutorial:_ADC#Ausgabe_als_ADC-Wert), 
aber ich komm da einfach nicht weiter...

Ich hab das so angeschlossen wie auf dem Schaltbild und wenn ich starte 
dann bekomm ich nur 000 angezeigt :(
1
.include "m8def.inc"
2
3
.def temp1     = r16
4
.def temp2    = r17
5
.def temp3    = r18
6
.def temp4    = r19
7
.def adlow    = r20
8
.def adhigh    = r21
9
.def messungen  = r22
10
.def ztausend  = r23
11
.def tausend  = r24
12
.def hundert  = r25
13
.def zehner    = r26
14
.def zeichen  = r27
15
16
.equ F_CPU = 4000000
17
.equ BAUD = 9600
18
19
.equ UBRR_VAL  = ((F_CPU+BAUD*8)/(BAUD*16)-1)
20
.equ BAUD_REAL  = (F_CPU/(16*(UBRR_VAL+1)))
21
.equ BAUD_ERROR = ((BAUD_REAL*1000)/BAUD-1000)
22
23
.if ((BAUD_ERROR>10) || (BAUD_ERROR<-10))
24
  .error "Systematischer Fehler der Baudrate grösser 1 Prozent und damit zu hoch!"
25
.endif
26
27
; Stackpointer Initalisierung
28
29
  ldi temp1, LOW(RAMEND)
30
  out SPL, temp1
31
  ldi temp1, HIGH(RAMEND)
32
  out SPH, temp1
33
34
; UART Initalsierung
35
36
  ldi temp1, LOW(UBRR_VAL)
37
  out UBRRL, temp1
38
  ldi temp1, HIGH(UBRR_VAL)
39
  out UBRRH, temp1
40
41
  sbi UCSRB, TXEN
42
43
; ADC initialiesieren: Single Conversion, Vorteiler 128
44
45
  ldi  temp1, (1<<REFS0)
46
  out  ADMUX, temp1
47
  ldi temp1, (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0)
48
  out ADCSRA, temp1
49
50
Main:
51
  clr temp1
52
  clr temp2
53
  clr temp3
54
  clr temp4
55
56
  ldi messungen, 0
57
58
59
sample_adc:
60
  sbi ADCSRA, ADSC
61
62
wait_adc:
63
  sbic ADCSRA, ADSC
64
  rjmp wait_adc
65
66
  in adlow, ADCL
67
  in adhigh, ADCH
68
69
  add temp2, adlow
70
  add temp3, adhigh
71
  add temp4, temp1
72
  dec messungen
73
  brne sample_adc
74
75
  cpi temp2, 128
76
  brlo no_round
77
78
  subi temp3, low(-1)
79
  sbci temp4, high(-1)
80
81
no_round:
82
  mov  adlow, temp3
83
  mov adhigh, temp4
84
85
  ldi ztausend, '0'-1
86
87
Z_ztausend:
88
  inc ztausend
89
  subi adlow, low(10000)
90
  sbci adhigh, high(10000)
91
  brcc Z_ztausend
92
93
  subi adlow, low(-10000)
94
  sbci adhigh, high(-10000)
95
96
  ldi tausend, '0'-1
97
98
Z_tausend:
99
  inc tausend
100
  subi adlow, low(1000)
101
  sbci adhigh, high(1000)
102
  brcc Z_tausend
103
104
  subi adlow, low(-1000)
105
  sbci adhigh, high(-1000)
106
107
  ldi hundert, '0'-1
108
109
Z_hundert:
110
  inc hundert
111
  subi adlow, low(100)
112
  sbci adhigh, high(100)
113
  brcc Z_hundert
114
115
  subi adlow, low(-100)
116
  sbci adhigh, high(-100)
117
118
  ldi zehner, '0'-1
119
120
Z_zehner:
121
  inc zehner
122
  subi adlow, low(10)
123
  sbci adhigh, high(10)
124
  brcc Z_zehner
125
126
  subi adlow, low(-10)
127
  sbci adhigh, high(-10)
128
129
  subi adlow, -'0'
130
131
  mov  zeichen, ztausend
132
  rcall transmit
133
  mov zeichen, tausend
134
  rcall transmit
135
  mov zeichen, hundert
136
  rcall transmit
137
  mov zeichen, zehner
138
  rcall transmit
139
  ldi zeichen, 13
140
  rcall transmit
141
  ldi zeichen, 10
142
  rcall transmit
143
144
  rjmp Main
145
146
transmit:
147
  sbis UCSRA, UDRE
148
  rjmp transmit
149
  out UDR, zeichen
150
  ret

Ich hab leider keinen Fehler gefunden :( ich hoffe ihr könnt mir da 
weiter helfen.

MFG Daniel L.

von spess53 (Gast)


Lesenswert?

Hi

>  add temp2, adlow
>  add temp3, adhigh
>  add temp4, temp1

ist falsch, richtig:

  add temp2, adlow
  adc temp3, adhigh
  adc temp4, temp1

MfG Spess

von Daniel L. (grorkef)


Lesenswert?

Danke Spess :) was so ein doofer kleiner Buchstabe ausmacht :( aber nun 
funktionierts ^^ bekomm bei 0V in HTerm 0000 und bei 5V 0102 :)

MFG Daniel L.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.