Skip to content

Commit

Permalink
Zählerauslesung durch Abtastung - ohne Interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert committed Dec 5, 2023
1 parent 2e26ede commit 14940c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
48 changes: 18 additions & 30 deletions avr/Node/Node.ino
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ boolean display_on = true;
RF24 radio(RADIO_CE_PIN,RADIO_CSN_PIN);
#endif

#if defined (ZAEHLERINTERRUPT)
#if defined (ZAEHLERINTERRUPTXXX)
void intZaehler_ISR() {
#ifdef DEBUG_STATUSLED_INT
digitalWrite(STATUSLED,! digitalRead(INTPIN));
Expand Down Expand Up @@ -907,7 +907,7 @@ void setup(void) {
#endif
intSumSleepTime = 0;
intStatusStack = 0;
attachInterrupt(digitalPinToInterrupt(INTPIN), intZaehler_ISR, CHANGE);
// attachInterrupt(digitalPinToInterrupt(INTPIN), intZaehler_ISR, CHANGE);
#endif

// Init EEPROM
Expand Down Expand Up @@ -1838,34 +1838,6 @@ void loop(void) {
#if defined(DISPLAY_ALL)
display_refresh();
#endif
#ifdef ZAEHLERINTERRUPT
/*
* Sonderbehandlung für Interruptbasierte Zähler
*/
intStatusStack = (intStatusStack << 1) | (digitalRead(INTPIN)? 0b00000001:0b00000000);
if ( (intStatusStack & 0b00000111) == 0b00000111 ) {
intSumSleepTime = 0;
while (intSumSleepTime < eeprom.sleeptime) {
SLEEPTYPE(1000); //sleep 1s
intSumSleepTime += 1;
#ifdef DEBUG_SERIAL
Serial.print("Loop: "); Serial.print(loopcount); Serial.print(" intSumSleepTime: "); Serial.println(intSumSleepTime);
#endif
#ifdef DEBUG_DISPLAY
lcd.print("L "); lcd.print(loopcount); lcd.print(" PortH "); lcd.println(intSumSleepTime);
#endif
}
} else {
SLEEPTYPE(61); //sleep 60ms
if (loopcount > 0) loopcount--;
#ifdef DEBUG_DISPLAY
lcd.print("L "); lcd.print(loopcount); lcd.print(" PortL "); lcd.println(intSumSleepTime);
#endif
}
#else
/*
* Behandlung normale Nodes
*/
long int tempsleeptime = eeprom.sleeptime; // regelmaessige Schlafzeit in Sek.
if (low_voltage_flag) tempsleeptime = eeprom.sleeptime_lv;
tempsleeptime += sleeptime_kor; // einmalige Korrektur in Sek.
Expand All @@ -1882,6 +1854,22 @@ void loop(void) {
//delay(tempsleeptime);
} else {
#endif
#ifdef ZAEHLERINTERRUPT
while (intSumSleepTime < tempsleeptime) {
bool pinstate = digitalRead(INTPIN);
if ( (intStatusStack & 0b00001111) == 0b00001111 && (pinstate == LOW) ) {
intZaehlerUI++;
intZaehlerF = (float)intZaehlerUI / 100;
}
intStatusStack = (intStatusStack << 1) | (pinstate? 0b00000001:0b00000000);
SLEEPTYPE(61); //sleep 60ms
intSumSleepTime += 60;
}
intSumSleepTime = 0;
#else
/*
* Behandlung normale Nodes
*/
SLEEPTYPE(tempsleeptime);
#if defined(DISCHARGE1)
}
Expand Down
4 changes: 2 additions & 2 deletions avr/Node/Node_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
#if defined(GASZAEHLERNODE)
//#define DEBUG_STATUSLED_RADIO_TX
#define RF24NODE 111
#define EEPROM_VERSION 3
#define EEPROM_VERSION 9
#define ZAEHLERINTERRUPT
#define ZAEHLER_LO_CHANNEL 11
#define ZAEHLER_HI_CHANNEL 12
Expand All @@ -236,7 +236,7 @@
#define SLEEPTIME 60
#define EMPTYLOOPS 1
#define LOW_VOLT_LEVEL 2.0
#define ZAEHLERSTART 286710
#define ZAEHLERSTART 287255
#define SLEEPTYPE sleep4ms
#endif
//-----------------------------------------------------
Expand Down

0 comments on commit 14940c8

Please sign in to comment.