Page 1 of 2
board hang
Posted: 11 Mar 2017 01:01
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
}
Re: board hang
Posted: 11 Mar 2017 01:13
by 10der
hang

Re: board hang
Posted: 11 Mar 2017 01:40
by 10der
aaaaaaaaaaa (panic)
...
// Day = (secsUp / (60 * 60 * 24));
...
not hang!
What the hell?!

Re: board hang
Posted: 11 Mar 2017 13:36
by p0lyg0n1
Looks like stack overflow. Move some variables(long first) to global area.
Re: board hang
Posted: 11 Mar 2017 15:25
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)!
Re: board hang
Posted: 11 Mar 2017 16:37
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
Re: board hang
Posted: 11 Mar 2017 16:40
by 10der
kk!
but please answer my second question with the simplest sketch above (blink ticker)
Re: board hang
Posted: 11 Mar 2017 16:46
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?
Re: board hang
Posted: 11 Mar 2017 22:26
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.
Re: board hang
Posted: 11 Mar 2017 22:30
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 ?