Mittelwertbildung C++

OP #4564160
Lesenswert?
• ▲
▼
Hallo Zusammen,

kann mir jemand auf die Sprünge helfen was ich hier falsch mache:
1
unsigned int cell_voltage[2][26] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
2
unsigned long cell_current[2][6] = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
3

4

5

6
                    cell_current[j][0] = ADC_Read(j+2);
7
                    cell_current[j][1] = ADC_Read(j+2);
8
                    cell_current[j][2] = ADC_Read(j+2);
9
                    cell_current[j][3] = ADC_Read(j+2);
10
                    cell_current[j][4] = ADC_Read(j+2);
11

12
                    cell_current[j][5] = cell_current[j][0] + cell_current[j][1] + cell_current[j][2] + cell_current[j][3] + cell_current[j][4];
13
                    cell_current[j][5] = (cell_current[j][5] / 4) & 0xFFFF;
14

15
                    cell_voltage[j][24] = cell_current[j][5] & 0xFF;                  //Module current lowbyte
16
                    cell_voltage[j][25] = (cell_current[j][5] >> 8) & 0xFF;           //Module current highbyte

Eigentlich sollte ich in cell_voltage[j][24-25] einen digitalen Rohwert 
um die 2050 bekommen, es kommen aber ca. 2560 raus. So schwer kann das 
doch nicht sein :/ ?

VG und Danke!
Gast #4564235
Lesenswert?
• ▲
▼
Noch als Tipp. ich habe so etwas ähnliches mal gemacht. hab das 
folgendermassen gelösst:
1
#define N_SAMPLES 5  // geht natürlich auch mit einer Variable...
2

3
unsigned int cell_voltage[2][26] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
4
unsigned long cell_current[2] = {0, 0};
5

6
        for (int i = 0 ; i < N_SAMPLES; i++ ) {
7
                    cell_current[j] += ADC_Read(j+2);
8
        }
9
        
10
        cell_current[j] = ( cell_current[j] / N_SAMPLES )  & 0xFFFF;
11
               
12
                cell_voltage[j][24] = cell_current[j] & 0xFF;                  //Module current lowbyte
13
                cell_voltage[j][25] = (cell_current[j] >> 8) & 0xFF;           //Module current highbyte

Dabei muss beachtet werden, das die Variable cell_current so gross ist, 
das sie die Summe natürlich aufnehmen kann (stichwort int16, int32, etc)

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren