10der
Posts: 80 Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA
Post
by 10der » 11 Mar 2017 01:01
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
}
10der
Posts: 80 Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA
Post
by 10der » 11 Mar 2017 01:13
hang
10der
Posts: 80 Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA
Post
by 10der » 11 Mar 2017 01:40
aaaaaaaaaaa (panic)
...
// Day = (secsUp / (60 * 60 * 24));
...
not hang!
What the hell?!
p0lyg0n1
Posts: 242 Joined: 04 Aug 2016 07:14
Post
by p0lyg0n1 » 11 Mar 2017 13:36
Looks like stack overflow. Move some variables(long first) to global area.
10der
Posts: 80 Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA
Post
by 10der » 11 Mar 2017 15:25
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
Post
by droll » 11 Mar 2017 16:37
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
10der
Posts: 80 Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA
Post
by 10der » 11 Mar 2017 16:40
kk!
but please answer my second question with the simplest sketch above (blink ticker)
10der
Posts: 80 Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA
Post
by 10der » 11 Mar 2017 16:46
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
Post
by p0lyg0n1 » 11 Mar 2017 22:26
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.
10der
Posts: 80 Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA
Post
by 10der » 11 Mar 2017 22:30
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 ?