Ticker seems to be broken from v160-

21 Feb 2018

Hi,

I've been keeping track of time using

void inc_sec(void)
{
    __disable_irq() ; // Disable Interrupts
    edge_time++ ;
    __enable_irq() ; // Enable Interrupts
}

void init_timer(void)
{
    tokei = new Ticker() ;
    tokei->attach(inc_sec, 1.0) ;
}

And it has been working till v157.
But from v158, time flies like a banana.

The "supposed to be" 1 second is more than 10 times shorter now.
And it made my program run like a hell.

Although I can survive with v157 for the time being,
I really hope mbed will fix this very soon.

moto

Note: I made mistake of reading version, the version 160 in the title meant 161:aa528, which is v159.

26 Feb 2018

Hi,

Since no one cared about this, I wrote a simple test program for this issue.

When compiled with mbed lib v157, count and edge_time go together.

But when compiled with mbed lib v160 (current version), up to 22 count and edge_time agrees,
then time begins fly like a banana, at count 22 the time is 4317!
and at count 78, the time is over 30000...

main.cpp

#include "mbed.h"
Ticker *tokei ;
uint32_t edge_time = 0 ;

void inc_sec(void)
{
    __disable_irq() ; // Disable Interrupts
    edge_time++ ;
    __enable_irq() ; // Enable Interrupts
}

void init_timer(void)
{
    tokei = new Ticker() ;
    tokei->attach(inc_sec, 1.0) ;
}

int main() {
    uint32_t count = 0 ;
    init_timer() ;
    
    printf("Ticker test program\n") ;
    while(1) {
        printf("%d: %d\n", count++, edge_time) ;
        wait(1.0) ;
    }
}

When I compiled this program with mbed lib v157, the output was

Ticker test program
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15
16: 16
17: 17
18: 18
19: 19
20: 20
21: 21
22: 22
23: 23
24: 24
25: 25
26: 26
27: 27
28: 28
29: 29
30: 30
31: 31
32: 32
33: 33
34: 34
35: 35
36: 36
37: 37
38: 38
39: 39
40: 40
41: 41
42: 42
43: 43
44: 44
45: 45
46: 46
47: 47
48: 48
49: 49
50: 50
51: 51
52: 52
53: 53
54: 54
55: 55
56: 56
57: 57
58: 58
59: 59
60: 60
61: 61
62: 62
63: 63
64: 64
65: 65
66: 66
67: 67
68: 68
69: 69
70: 70
71: 71
72: 72
73: 73
74: 74
75: 75
76: 76
77: 77
78: 78
79: 79
80: 80
81: 81
82: 82
83: 83
84: 84
85: 85
86: 86
87: 87
88: 88
89: 89
90: 90
91: 91
92: 92
93: 93
94: 94
95: 95
96: 96
97: 97
98: 98
99: 99
100: 100
101: 101
102: 102
103: 103
104: 104
105: 105
106: 106
107: 107
108: 108
109: 109
110: 110

But when I compiled the program with mbed v160 (current version)

Ticker test program
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15
16: 16
17: 17
18: 18
19: 19
20: 20
21: 21
22: 4317
23: 4318
24: 4319
25: 4320
26: 4321
27: 4322
28: 4323
29: 4324
30: 4325
31: 4326
32: 4327
33: 4328
34: 4329
35: 4330
36: 4331
37: 4332
38: 4333
39: 4334
40: 4335
41: 4336
42: 4337
43: 4338
44: 4339
45: 4340
46: 4341
47: 4342
48: 4343
49: 8639
50: 8640
51: 8641
52: 8642
53: 8643
54: 8644
55: 12940
56: 12941
57: 12942
58: 12943
59: 17239
60: 17240
61: 17241
62: 17242
63: 17243
64: 17244
65: 17245
66: 17246
67: 17247
68: 17248
69: 17249
70: 17250
71: 17251
72: 17252
73: 21548
74: 25844
75: 25845
76: 25846
77: 25847
78: 30143
79: 30144
80: 30145
81: 30146
82: 30147
83: 30148
84: 30149
85: 34445
86: 38741
87: 38742
88: 38743

moto

27 Feb 2018

I have confirmed Motoo-san's program.
I could re-produced same BUG on Nucleo-L152RE, Nucleo-F446RE and TY51822r3 Mbed boards.
I'm trying the same program on mbed-os-5.7.6 and mbed-dev rev.181(version 159) but nothing happen over 30 minutes (works well).
This means that
(1) not specific board but common behavior and
(2) only on mbed rev.160. bug.

I also tried changing interval as follows.
0.1 sec ->jump 42958
0.5 sec ->jump 21477
1sec ->jump 4218
2sec ->jump 2148
10sec ->jump 430
This number of interrupts is actually occurring during big change the number!
Revision up includes new method to use frequency calculation.
It seems relation for it but I'm not a specialist and need to wait Mbed team effort.

To Mbed team
This is very serious problem.
I hope you can fix the bug ASAP.

28 Feb 2018

Hello Motoo-san and Kenji,

I am trying to reproduce and having trouble duplicating your results. I am seeing the ticker acting as expected.

I am using a Nucleo-L476RG because I had one at hand. I will look around and see if I can find one of the boards you were using.

Also, could you share your development specifics? (compiler, version, os, et al)

thanks, Earl Manning

12 Mar 2018

Dear Earl-san,

I'm sorry for this slow response, may be my ticker is also screwed.

Anyway, I've just published my test program.
https://os.mbed.com/users/Rhyme/code/ticker_test_180226/

And as I re-tested with version of mbed libs, the symptom is more interesting this time.
with 157, 1 sec seems to be one sec.
with 158, 1 sec starts getting faster after 22 secs or so.
with 159, assertation failed: ... whatever it means...

with version 157 (159:7130f322cb7e)

version 157 (159:7130f322cb7e)
Ticker test program
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15
16: 16
17: 17
18: 18
19: 19
20: 20
21: 21
22: 22
23: 23
24: 24
25: 25

with version 158 (160:5571c4f)

version 158 (160:5571c4f)
Ticker test program
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15
16: 16
17: 17
18: 18
19: 19
20: 20
21: 21
22: 4317
23: 4318
24: 4319
25: 4320
26: 4321

with version 159 (161:aa5281f)

・icker test program
0: 0
mbed assertation failed: interrupts_disabled, file: /home/arm/mbed_jenkins/workspace/bm_wrap/1673/mbed-os/platform/mbed_criticaG0

moto