Habe nochmal etwas weiter experimentiert.
1 | uint16_t readADC(char sensor){
|
2 | const byte DAT[8] = {0x84,0xE4,0xF4,0xD4,0xA4,0xE4,0xB4,0xF4}; // Just using the first byte for the moment
|
3 |
|
4 | byte highbyte, lowbyte;
|
5 |
|
6 | Wire.beginTransmission(ADC7828E_I2C_Adress);
|
7 | Wire.write(DAT[sensor]);
|
8 | delay(1);
|
9 | if (Wire.endTransmission() == 0){
|
10 | //LOG("ADS7828E recognized");
|
11 | } else {
|
12 | ERR("Failed to recognize ADS7828E");
|
13 | }
|
14 | delay(1);
|
15 |
|
16 | uint16_t value;
|
17 |
|
18 | Wire.requestFrom(ADC7828E_I2C_Adress, 2);
|
19 | while(Wire.available())
|
20 | {
|
21 |
|
22 | highbyte = Wire.read();
|
23 | lowbyte = Wire.read();
|
24 | value= ((int)((highbyte<<8) + lowbyte));
|
25 | }
|
26 | return(value);
|
27 | }
|
ausgelesen wird nur der erste Kanal, mit externer Referenz.
So lese ich ihn aus:
1 | uint16_t adcvalue =0;
|
2 | for (int i=0; i<1; i++){
|
3 | adcvalue +=(readADC(0));
|
4 | }
|
5 | Serial.print("single read FOR:");
|
6 | Serial.println(adcvalue);
|
7 | Serial.print("single read ADC:");
|
8 | Serial.println(readADC(0));
|
Ich bekomme andere ergebnisse je nachdem, wie ich die funktion aufrufe,
entweder direkt oder in der FOR schleife (die nur einmal durchläuft)
1 | single read ADC:1283
|
2 | single read FOR:1250
|
3 | single read ADC:1283
|
4 | single read FOR:1244
|
5 | single read ADC:1285
|
6 | single read FOR:1255
|
7 | single read ADC:1289
|
8 | single read FOR:1254
|
mit oversampling sieht es dann jedoch völlig anders aus!
1 | uint16_t adcvalue =0;
|
2 | for (int i=0; i<10; i++){
|
3 | adcvalue +=(readADC(0));
|
4 | }
|
5 | Serial.print("oversampling read FOR:");
|
6 | Serial.println(adcvalue/10);
|
1 | oversampling read FOR:1328
|
2 | single read ADC:1346
|
3 | oversampling read FOR:1329
|
4 | single read ADC:1345
|
5 | oversampling read FOR:1327
|
6 | single read ADC:1342
|
Das beste ist noch, wenn ich zweimal die selbe FOR Schleife einfach
untereinander packe, erhalte ich auch unterschiedlich ergebnisse!
1 | Serial.print("first oversampling ADC Value: ");
|
2 | uint16_t adcvalue =0;
|
3 | for (int i=0; i<10; i++){
|
4 | adcvalue +=(readADC(0));
|
5 | }
|
6 | Serial.println(adcvalue/10);
|
7 |
|
8 |
|
9 | uint16_t adcvalueuncorr =0;
|
10 | for (int i=0; i<10; i++){
|
11 | adcvalueuncorr +=(readADC(0));
|
12 | }
|
13 | Serial.print("second oversampling ADC Value:");
|
14 | Serial.println(adcvalueuncorr/10);
|
1 | first oversampling ADC Value: 1319
|
2 | second oversampling ADC Value:1342
|
3 | first oversampling ADC Value: 1319
|
4 | second oversampling ADC Value:1341
|
5 | first oversampling ADC Value: 1318
|
6 | second oversampling ADC Value:1341
|
7 | first oversampling ADC Value: 1319
|
8 | second oversampling ADC Value:1342
|
9 | first oversampling ADC Value: 1319
|
10 | second oversampling ADC Value:1342
|
11 | first oversampling ADC Value: 1319
|
12 | second oversampling ADC Value:1341
|
Wie kann man dieses (für mich jedenfalls) Phänomen erklären, bzw. wie
macht man es denn richtig? Es ist immerhin ein IC für knapp 8€... Wenn
das ganze nichts bringt, werde ich wohl den ADC wechseln müssen.