Pages: 1 [2]   Go Down
Author Topic: Scheduler and U8glib on DUE  (Read 2888 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Edison Member
*
Karma: 133
Posts: 1444
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your feedback. I have created an issue: http://code.google.com/p/u8glib/issues/detail?id=155

Oliver
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


It would be better if the initialization code is placed into a begin() function.
Many arduino libraries does it this way, you know exactly when the initialization is done,
and avoids you to hit the "C++ static initialization order fiasco".

http://www.parashift.com/c++-faq/static-init-order.html

Logged

C.

Germany
Offline Offline
Edison Member
*
Karma: 133
Posts: 1444
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, yes, and indeed the modification of u8g_Delay() is more a workaround (or hack) instead of a good solution. To excause the current situation a little bit: I never read in the Arduino documentation that some of the procedures are not valid to be called during constructor time. And on the ATMEGA it was never a problem to call digitalWrite() or delay() in the constructor.

For the port to the Arduino Due i also had to deal with this problem because of some other conflicts. U8glib already has a begin() procedure. But u8glib has not been completly redesigned for it. So to say, i am on the half way of a complete redesign of the internal architecture without changing much of the existing API.

So to conclude this:
I was not aware of this problem in the past, but now i do my very best to update U8glib.

My suggestion to the Arduino Project: Please clearly state that delay() and digitalWrite() must not be used in any construtor calls.

Oliver


Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Well, yes, and indeed the modification of u8g_Delay() is more a workaround (or hack) instead of a good solution. To excause the current situation a little bit: I never read in the Arduino documentation that some of the procedures are not valid to be called during constructor time. And on the ATMEGA it was never a problem to call digitalWrite() or delay() in the constructor.

olikraus,
you don't need to justify, initializations (with digitalWrite and delays) in the constructors should be legal.

The issue here is that delay() didn't work until the Arduino initialization is done in main() and C++ starts constructors of static objects before the main! I got some problems with the LiquidCrystal library because of that:

https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp#L27

and the solution was:

https://github.com/arduino/Arduino/commit/d994e48c5565a0c7aea54384a1b15a19623fe209

but for some reason the scheduler has still some interactions I didn't considered that should be looked into.

So, in the end, consider my previous post just a hint to workaround these troubles... smiley

Logged

C.

Germany
Offline Offline
Edison Member
*
Karma: 133
Posts: 1444
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi cmaglie

Regarding your link to the LiquidCrystal lib: I had a similar problem with init of the display within u8glib.
After constructor calls, the Arduino Due will reset all I/O pins. This problem still exists in 1.5.2.

Oliver

 
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.

I'm trying to implement the scheduler in my project, but the behaviour is not what I was expecting.

Due runs a lot of times the main loop, and sometimes the second loop.

But when it does, there isn't a consistent number of runs.

What I has expecting, was it to run main loop, then 2nd loop, then main loop, then 2nd loop, and so on.

What I get from the debug is this: ( number is the corresponding runtime in millis for the loop)

"
loop1   1
loop1   1
loop1   0
loop1   1
loop   135
loop   125
loop   125
loop   126
loop   125
loop   125
loop   126
loop   125
loop   125
loop   125
loop   125
loop   126
loop   125
loop   125
loop   126
loop   125
loop1   0
loop1   1
loop1   0
loop1   1
loop   130
loop   125
loop   125
loop   125
loop   125
loop   126
loop   125
loop   125
loop   126
loop   125
loop   125
loop   125
loop   125
loop   126
loop   125
loop   125
loop1   1
loop1   0
loop1   1
loop1   1
loop   135
loop   126
loop   125
loop   125
loop   167
loop   125
loop   125
loop   125
loop   126
loop   125
loop   125
loop   126
loop   125
loop   125
loop   125
loop   125
loop1   1
loop1   0
loop1   1
loop   130
loop   125
loop   125
loop   125
loop   125
loop   126
loop   125
loop   125
loop   126
loop   125
loop   126
loop   125
loop   125
loop   126
loop   125
loop   125
loop1   1
loop1   1
loop1   0
loop1   1
loop   135
loop   125
loop   125
loop   167
loop   125
loop   126
loop   125
loop   125
loop   125
loop   125
loop   126
loop   125
loop   125
loop   126
loop   125
loop   125
loop1   1
loop1   1
"

Am I missing something here?
Logged


Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Am I missing something here?

The Scheduler is used for cooperative multitasking and not a preemptive one as you was expecting. Read here about the differences: http://en.wikipedia.org/wiki/Computer_multitasking
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you Pylon for pointing me in right direction. I think its clear now, but I'll read it again.

To solve my problem, I've built a scheduler with a switch. With this I run only one time consuming function per loop.

I've dropped the loop time from 120millis to 10 millis average.

Regards

Joao
Logged


Pages: 1 [2]   Go Up
Jump to: