board hang

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

board hang

Post by 10der »

Hi!

this sketch will live above one minute. after board dies!
ha-ha!

Code: Select all

#include "ZUNO_OLED_I2C.h"

OLED oled;

void setup() {
  // put your setup code here, to run once:
  oled.begin();
  oled.clrscr();

}

void ShowOLED() {

  long secsUp = millis() / 1000;

  long Day = 0;
  int Hour = 0;
  int Minute = 0;
  int Second = 0;

  Second = secsUp % 60;
  Minute = (secsUp / 60) % 60;
  Hour = (secsUp / (60 * 60)) % 24;
  Day = (secsUp / (60 * 60 * 24));

  oled.gotoXY(15, 0);

  oled.print (Day);
  oled.print ("d, ");
  if (Hour < 10) {
    oled.print ("0");
  }
  oled.print (Hour);
  oled.print (":");
  if (Minute < 10) {
    oled.print ("0");
  }
  oled.print (Minute);
  oled.print (":");
  if (Second < 10) {
    oled.print ("0");
  }
  oled.print (Second);
}

void loop() {
  // put your main code here, to run repeatedly:
  ShowOLED();
  delay(200);  // wait at least 200 ms
}
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: board hang

Post by 10der »

hang
Image
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: board hang

Post by 10der »

aaaaaaaaaaa (panic)

...
// Day = (secsUp / (60 * 60 * 24));
...

not hang!

What the hell?! :evil:
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: board hang

Post by p0lyg0n1 »

Looks like stack overflow. Move some variables(long first) to global area.
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: board hang

Post by 10der »

OK!

what I should move here?!

Code: Select all

void ShowTicker() {
  
  oled.gotoXY(0, 0);
  
  if ((((millis() / 1000) % 60) % 2) == 0) {
    oled.print("*");
  } else {
    oled.print(" ");
  }
}

void loop() {
 ShowTicker();
}
this sketch works on the order of 3-4h after Z-UNO hang (green service LED always on)!
droll
Posts: 48
Joined: 20 Dec 2013 01:37

Re: board hang

Post by droll »

Your original code requires 43 bytes of stack (+ additional bytes for the system calls like gptrget, divlong, etc). This should not really be a problem, usually I started to observe problems related to stack overflow only for programs that use 65 bytes of stack or more. However it is still worth checking if the issue can be resolved by declaring the local variables ShowOLED function globally.

By doing so only 36 bytes of stack are required (+ additional bytes for system calls).

The updated code is:

Code: Select all

#include "ZUNO_OLED_I2C.h"

OLED oled;

long secsUp, Day;
int Hour, Minute, Second;

void setup() {
  oled.begin();
  oled.clrscr();
}

void ShowOLED() {
  secsUp = millis() / 1000;
  Second = secsUp % 60;
  Minute = (secsUp / 60) % 60;
  Hour = (secsUp / (60 * 60)) % 24;
  Day = (secsUp / (60 * 60 * 24));

  oled.gotoXY(15, 0);

  oled.print (Day);
  oled.print ("d, ");
  if (Hour < 10) {
    oled.print ("0");
  }
  oled.print (Hour);
  oled.print (":");
  if (Minute < 10) {
    oled.print ("0");
  }
  oled.print (Minute);
  oled.print (":");
  if (Second < 10) {
    oled.print ("0");
  }
  oled.print (Second);
}

void loop() {
  ShowOLED();
  delay(200);  // wait at least 200 ms
}
Please try this code ...

PS: You can analyze the stack usage of your program with the following python script: https://forum.z-wave.me/download/file.php?id=1118
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: board hang

Post by 10der »

kk!

but please answer my second question with the simplest sketch above (blink ticker)
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: board hang

Post by 10der »

droll wrote:Your original code requires 43 bytes of stack
btw, what about sizing ZUNO_OLED_I2C lib?
how ZUNO relocate memory for declaring byte SmallFont[] var?
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: board hang

Post by p0lyg0n1 »

All arrays will be located in user segment of xram(2kb).
Stack always located for 8051 in the idata (140 bytes only). When you create local variable (not an array) it places at the top of stack.
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: board hang

Post by 10der »

thank you so much for replying

can I ask noob question? thanks.

Code: Select all

long secsUp = 21600;
long x = (secsUp / (60 * 60 * 24));  // (60 * 60 * 24) 86400 int 
x = 1; why?
should I declare (60 * 60 * 24) as (60 * 60 * 24)L ?
Post Reply