Notifications
Clear all

Multiple Timer Library

35 Posts
2 Users
1 Likes
6,472 Views
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Good job!
What is the next enhancement? 🙂

Stopwatch?

Cheers!


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

Stopwatch?

Maybe, but I don't think so! That is something for a sketch.

But it reminded me of experiments during physics classes, with a ball bearing suspended under an electromagnet, a couple of feet above a trap door, to prove Newton was right. And that was before SI units had been officially introduced into schools in the UK. That came in 1968!

 

And I just put a LiPo in a charger backwards! Apart from the smoke, I discovered it had completely desoldered an SMD. ? ? 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

Stopwatch?

Maybe, but I don't think so! That is something for a sketch.

I'll show you an interesting stopwatch... I'll have to dig it out from one of my archives.

What goes up, must come down 😀


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

I have put the old code back (timestamp comparison) in the .cpp file and have just started running the microseconds until rollover, to see if it does make any difference, I'll let you know tomorrow


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Ok, interesting to see what happens... the 2020 bug!

Cheers 🙂


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

You were right, the rollover problem did not occur when comparing timestamps. Nevertheless, I was surprised to find that "long unsigned" integers rollover too.

When I ran this code I was expecting a runtime error:

void setup() {
  // starts the serial monitor interface and shows sketch details
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long myInt = 4294964295;
  unsigned long myInt1 = 10000;
  unsigned long result = myInt + myInt1;
  Serial.println(result);
  while(1); 
}

But the result variable returned 6999.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

You were right, the rollover problem did not occur when comparing timestamps. Nevertheless, I was surprised to find that "long unsigned" integers rollover too.

Yeah, I thought it should be ok, as we're only comparing the difference between counts... not actual timestamps.  Either way, I prefer the last version anyway, as I think it's cleaner code.

As for overflow... it is of course an error when the size of the type cannot support a greater number, but should it matter if it was signed or unsigned?


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

And when I added another zero to the variable "myInt" the code was still compiled, but "result" returned 4294947286!


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

I did see a discussion about using <uint_64> and incrementing the higher 32 bits at each rollover. This would, with millis(), then rollover at about every half a billion years!

But I don't intend to test that theory ? ? ? 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

From memory, unsigned overflow is well defined in the C++ standard... but I don't recall the exact answer off the top of my head - I'll have to pull it out and see if I can find the relevant section!

Cheers!


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

but I don't recall the exact answer off the top of my head 

42


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

The meaning of life! ? 


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

The meaning of life! ? 

Doesn't everything boil down to that?

But it does surprise me that the compiler doesn't tell me that the number 42949642950 is too big to handle!


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Yep! 🙂

Unfortunately, Arduino doesn't implement the full C++ standard library due to size limitations, therefore exceptions are left out, as well as a host of excellent container classes and features that we can only dream were available.


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

What goes up, must come down ?

Have finally joined the dots! The Alan Parsons Project is the answer!

An Arduino Pyramid Monitoring Program. With uint_64 you could measure how many milliseconds it would take for a pyramid to turn back to dust. Now that's what I call a timer! ? ? ? 


   
ReplyQuote
Page 2 / 3