Liebe Kollegen,
ich bin nicht so versiert wie alle anderen in diesem Forum, weil die
Programmierung von MC's "nur" ein Hobby von mir ist. Deshalb wäre ich
dankbar für einen zielführenden Tipp !
Ich habe folgendes Problem:
Ich initialisiere einen hwTimer mit
1 | hw_timer_t *timer = NULL;
|
2 | portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
3 | volatile int interruptCounter;
|
4 | volatile int totalInterruptCounter;
|
5 | void IRAM_ATTR onTimer();
|
im Setup
1 | // Timer
|
2 | timer = timerBegin(0, 80, true); // Teiler 80MHz / 80 = 1MHz
|
3 | timerLed = timerBegin(1, 800, true); // Teiler 80MHz / 80 = 100kHz
|
4 | timerAttachInterrupt(timerLed, &onTimerLed, true);
|
5 | timerAlarmWrite(timerLed, 20000, true);
|
6 | timerAlarmEnable(timerLed);
|
die Interruptroutine
1 | void IRAM_ATTR onTimer() {
|
2 | portENTER_CRITICAL_ISR(&timerMux);
|
3 | interruptCounter++;
|
4 | totalInterruptCounter++;
|
5 | portEXIT_CRITICAL_ISR(&timerMux);
|
6 | }
|
und in der Loop
1 | if (stateCounter == 4) {
|
2 | stateCounter = 5;
|
3 | LedState = 0;
|
4 |
|
5 | display.clearDisplay();
|
6 | display.setCursor(0,0);
|
7 | display.println("measuring... ");
|
8 | display.display();
|
9 |
|
10 | myFile = SD.open(fileString, FILE_WRITE);
|
11 | if(!myFile){
|
12 | DEBUG_PRINTLN("file dose not exist");
|
13 | } else {
|
14 | myFile.println(dataString);
|
15 | }
|
16 |
|
17 | runtime = 0;
|
18 | timestamp = 0;
|
19 | interruptCounter = 0;
|
20 | totalInterruptCounter = 0;
|
21 | timerAttachInterrupt(timer, &onTimer, true);
|
22 | timerAlarmWrite(timer, 5000, true);
|
23 | timerAlarmEnable(timer);
|
24 | millisTimer = millis();
|
25 |
|
26 | } // end of measuring
|
27 |
|
28 | // Interrupt completed 25 Jan 2021
|
29 | if (interruptCounter > 0) {
|
30 | portENTER_CRITICAL(&timerMux);
|
31 | int sensorWert = 0;
|
32 | timestamp += 0.005;
|
33 |
|
34 | dataString = String(timestamp, 3) + ","; // drei Dezimalstellen
|
35 | // read sensors and append to the string:
|
36 | for (byte i = 0; i < AnalogInAnzahl - 1; i++) {
|
37 | sensorWert = analogRead(AnalogIn[i]) - AnalogInInit[i];
|
38 | dataString += String(sensorWert, DEC) + ",";
|
39 | }
|
40 | sensorWert = analogRead(AnalogIn[AnalogInAnzahl - 1]) - AnalogInInit[AnalogInAnzahl - 1];
|
41 | dataString += String(sensorWert, DEC); // the last data without komma
|
42 |
|
43 | if (myFile) {
|
44 | myFile.println(dataString);
|
45 | } else {
|
46 | SDerror("error opening filestring");
|
47 | }
|
48 |
|
49 | if (totalInterruptCounter >= 1201) {
|
50 | timerAlarmDisable(timer);
|
51 | runtime = millis() - millisTimer;
|
52 | if (myFile) {
|
53 | myFile.close();
|
54 | }
|
55 | DEBUG_PRINT("Messdauer [ms]: ");
|
56 | DEBUG_PRINTLN(runtime);
|
57 | LedState = 1;
|
58 | stateCounter = 6;
|
59 | }
|
60 | interruptCounter--;
|
61 | portEXIT_CRITICAL(&timerMux);
|
62 | }
|
wenn ich nun in der Loop
1 | //myFile.println(dataString);
|
ausblende erhalte ich eine runtime von richtigerweise genau 6000ms.
Wenn ich aber die Daten (ca. 40Byte pro String) auf die SD Karte
schreibe ergibt sich eine runtime (unterschiedlich) von ca. 6600ms !
Zuerst habe ich gedacht die SD Routine schafft das nicht in 5ms pro
Datensatz und habe es mit 10ms versucht, aber mit dem selben ungenauen
Ergebnis ?
Bitte bitte woran kann das liegen, was verstehe ich dabei nicht ?
Vielen Dank im Voraus !!!