Calculating with millis() The following code works fine until I turn the if (tijd - action &gt;= 500) into if (tijd - action &gt;= 1000)

I wonder why this fails.

If I just loop and print the tijd - action it has no problem with it and runs well beyond 1000.

The Logic Analyzer on the software serial only returns '255' when it fails, I also wonder what that means.

The core I use is this one
The chip I use is an ATtiny85
I run this using the Arduino IDE 1.8.2  

[update]

with "start"

Sketch uses 3070 bytes (37%) of program storage space. Maximum is 8192 bytes.
Global variables use 146 bytes (28%) of dynamic memory, leaving 366 bytes for local variables. Maximum is 512 bytes.


with "starting"

Sketch uses 3072 bytes (37%) of program storage space. Maximum is 8192 bytes.
Global variables use 148 bytes (28%) of dynamic memory, leaving 364 bytes for local variables. Maximum is 512 bytes.


script

#include &lt;SoftwareSerial.h&gt;
#include &lt;avr/sleep.h&gt;
#include &lt;avr/wdt.h&gt;

#define TX_PIN 4
#define RX_PIN -1

#ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &amp;= ~_BV(bit))
#endif
#ifndef sbi
  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

SoftwareSerial mySerial(RX_PIN, TX_PIN);

unsigned long tijd;
unsigned long action = 0;

volatile boolean f_wdt = 1;
ISR(WDT_vect) {
  f_wdt=1;
}

void system_sleep() {
  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();

  sleep_mode();                        // System sleeps here

  sleep_disable();                     // System continues execution here when watchdog timed out
  sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
}

void setup_watchdog(int ii) {
  byte bb;
  int ww;
  if (ii &gt; 9 ) ii=9;
  bb=ii &amp; 7;
  if (ii &gt; 7) bb|= (1&lt;&lt;5);
  bb|= (1&lt;&lt;WDCE);
  ww=bb;

  MCUSR &amp;= ~(1&lt;&lt;WDRF);
  // start timed sequence
  WDTCR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);
  // set new watchdog timeout value
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}

void setup() {
  mySerial.begin(2400);
  mySerial.print("Starting..");
  setup_watchdog(8);
  pinMode(0, OUTPUT);
}

int zie = 0;

void loop() {
  if (f_wdt==1) { 
    digitalWrite(0, HIGH);
    tijd = millis();
    mySerial.print(".");
    mySerial.print(tijd - action);
    zie+=1;
    if (tijd - action &gt;= 500) { // fails when set to 1000
      digitalWrite(0, LOW);
      action = tijd;
      mySerial.print("z");
      mySerial.print(zie);
      mySerial.print(".");
      system_sleep();
    }
  }
}
if I change the string "Starting.." to "Start" it will run fine! This probably has something to do with filling up the RAM of the Tiny, right?


That symptom does suggest RAM overflow, in spite of the relatively low RAM use (28%) reported during compilation.

To reduce memory use slightly more, you can move the string "Starting.." to PROGMEM by changing from line 1 below to line 2.

  mySerial.print("Starting..");     // line 1
  mySerial.print(F("Starting.."));  // line 2


To save another handful of RAM bytes, change lines like mySerial.print("."); and mySerial.print("z"); to mySerial.print('.'); and mySerial.print('z');.  That is, you are printing single-character strings; each string has a null terminating byte; instead just print single characters.

References and discussion of the F() macro include 1, 2, 3, 4, 5 and also see  How do I squeeze code to fit onto an ATTiny.  Also, there are some really compact software serial libraries targeted for ATtinies, which may save hundreds of bytes of flash and dozens of bytes of RAM.