Hallo Leute,
irgendwie bin ich wieder mal am Verzweifeln.
Ich bekomme den ADC des ATmega16a einfach nicht anständig zum laufen!
Ich bin am Verzweifeln. Ich bin mir mittlerweile garnicht mehr sicher ob
ich nicht sogar den µC geschrottet habe.
Vielleicht kann einer einen Blick auf folgenden Quelltext werfen. Ich
wäre echt ziemlich dankbar :)
1 | void adcInit()
|
2 | {
|
3 |
|
4 | SBIT(SFIOR, ADTS0)=0;
|
5 | SBIT(SFIOR, ADTS1)=0;
|
6 | SBIT(SFIOR, ADTS2)=0;
|
7 |
|
8 | SBIT(ADCSRA,ADPS0) = 0;
|
9 | SBIT(ADCSRA,ADPS1) = 0;
|
10 | SBIT(ADCSRA,ADPS2) = 0;
|
11 |
|
12 | SBIT(ADMUX,REFS0)=0; //an AREF liegen 5V an
|
13 | SBIT(ADMUX,REFS1)=0;
|
14 |
|
15 | SBIT(ADMUX,MUX0)=1;
|
16 | SBIT(ADMUX,MUX1)=1;
|
17 | SBIT(ADMUX,MUX2)=1;
|
18 |
|
19 | SBIT(ADCSRA,ADEN) = 1;
|
20 | SBIT(ADCSRA,ADSC) = 1;
|
21 | }
|
22 |
|
23 | unsigned short adcRead(void)
|
24 | {static unsigned short adcValue;unsigned char adcValue1,adcValue0;
|
25 | if(SBIT(ADCSRA,ADIF))
|
26 | {
|
27 | adcValue0 = ADCL;
|
28 | adcValue1 = ADCH;
|
29 | //adcValue = (adcValue1<<7)|adcValue0; //funktioniert aus irgendeinem grund auch nicht wirklich!!
|
30 | adcValue = (adcValue1*255)+adcValue0;
|
31 | SBIT(ADCSRA,ADSC) = 1;
|
32 | SBIT(ADCSRA,ADIF) = 1;
|
33 | };
|
34 |
|
35 | return adcValue;
|
36 | }
|
37 |
|
38 | void adcTest(void)
|
39 | {static unsigned short adc1,adc2;
|
40 | adcInit();
|
41 | while(1)
|
42 | {
|
43 | adc1 = adcRead();
|
44 | adc2 = adc1;
|
45 | };
|
46 |
|
47 | }
|
Das Problem ist:
Sobald ich an den PA7 0V anlege, steht in meinem ergebnis: 0x01FF (hier
erwarte ich 0x0000 oder irgendetwas kleines!)
Sobald ich an den PA7 ca. 2,7V anlege, steht in meinem ergebnis: 0x037C