hw timer
Posted: Tue Jan 26, 2021 8:35 pm
Dear colleagues,
I'm not as savvy as everyone else on this forum because of that
Programming MC's is "just" a hobby of mine. That's why I would be
grateful for a useful tip!
I have the following problem:
I initialize a hwTimer with:
the Setup
the interrupt routine
and the loop
if I now fade out in the loop,I get a runtime of exactly 6000ms.
But if I transfer the data (approx. 40Byte per string) to the SD card
write results in a runtime (different) of approx. 6600ms!
At first I thought the SD routine couldn't do that in 5ms per
Record and tried 10ms, but inaccurate with the same
Result ?
Please please what can be the reason, what do I not understand?
Thanks in advance !!!
I'm not as savvy as everyone else on this forum because of that
Programming MC's is "just" a hobby of mine. That's why I would be
grateful for a useful tip!
I have the following problem:
I initialize a hwTimer with:
- hw_timer_t *timer = NULL;
- portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
- volatile int interruptCounter;
- volatile int totalInterruptCounter;
- void IRAM_ATTR onTimer();
- // Timer
- timer = timerBegin(0, 80, true); // Teiler 80MHz / 80 = 1MHz
- timerLed = timerBegin(1, 800, true); // Teiler 80MHz / 80 = 100kHz
- timerAttachInterrupt(timerLed, &onTimerLed, true);
- timerAlarmWrite(timerLed, 20000, true);
- timerAlarmEnable(timerLed);
- void IRAM_ATTR onTimer() {
- portENTER_CRITICAL_ISR(&timerMux);
- interruptCounter++;
- totalInterruptCounter++;
- portEXIT_CRITICAL_ISR(&timerMux);
- }
- if (stateCounter == 4) {
- stateCounter = 5;
- LedState = 0;
- display.clearDisplay();
- display.setCursor(0,0);
- display.println("measuring... ");
- display.display();
- myFile = SD.open(fileString, FILE_WRITE);
- if(!myFile){
- DEBUG_PRINTLN("file dose not exist");
- } else {
- myFile.println(dataString);
- }
- runtime = 0;
- timestamp = 0;
- interruptCounter = 0;
- totalInterruptCounter = 0;
- timerAttachInterrupt(timer, &onTimer, true);
- timerAlarmWrite(timer, 5000, true);
- timerAlarmEnable(timer);
- millisTimer = millis();
- } // end of measuring
- // Interrupt completed 25 Jan 2021
- if (interruptCounter > 0) {
- portENTER_CRITICAL(&timerMux);
- int sensorWert = 0;
- timestamp += 0.005;
- dataString = String(timestamp, 3) + ","; // drei Dezimalstellen
- // read sensors and append to the string:
- for (byte i = 0; i < AnalogInAnzahl - 1; i++) {
- sensorWert = analogRead(AnalogIn[i]) - AnalogInInit[i];
- dataString += String(sensorWert, DEC) + ",";
- }
- sensorWert = analogRead(AnalogIn[AnalogInAnzahl - 1]) - AnalogInInit[AnalogInAnzahl - 1];
- dataString += String(sensorWert, DEC); // the last data without komma
- if (myFile) {
- myFile.println(dataString);
- } else {
- SDerror("error opening filestring");
- }
- if (totalInterruptCounter >= 1201) {
- timerAlarmDisable(timer);
- runtime = millis() - millisTimer;
- if (myFile) {
- myFile.close();
- }
- DEBUG_PRINT("Messdauer [ms]: ");
- DEBUG_PRINTLN(runtime);
- LedState = 1;
- stateCounter = 6;
- }
- interruptCounter--;
- portEXIT_CRITICAL(&timerMux);
- }
if I now fade out in the loop,
- //myFile.println(dataString);
But if I transfer the data (approx. 40Byte per string) to the SD card
write results in a runtime (different) of approx. 6600ms!
At first I thought the SD routine couldn't do that in 5ms per
Record and tried 10ms, but inaccurate with the same
Result ?
Please please what can be the reason, what do I not understand?
Thanks in advance !!!