Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Maximite Timer function
Author | Message | ||||
merlin66 Newbie Joined: 04/02/2013 Location: ThailandPosts: 6 |
My Maximite: Monochrom, Version 3.2A running. The Maximite controls a hot water solar system, everything built by my own. It runs perfectly since 6 month without an unexpected stop. The program contains now 409 lines. But this time only the basic function is finished and not all of the plant function is covered yet. I will extend it some time later with comfort functions as "save statistical values", "automatic water pressure regulation", "System malfunction detection and display" etc. Generally the Maximite is a great thing and is easy to maintain and to program. But something look strange to me, the Timer function. I use the Timer to calculate and display the runtime of some different subroutines, just for my information, not for process dependent functions. At the beginning after program start all looks well. But some days later (I don't remenmeber how many) the values become unreliable. It has most probably to do with overflow or misalignment of variables, too see in the results table. Wrong values are a multiple of power of 2, like cut off somewhere some least significant bits. To trace down the bug I wrote some lines of code to test the timer in a similar manner I use it in my program. ' Timertest ' Timer = 1000000 R = 0 ' Loop number Do Start = Timer For a = 1 To 10000 ' Task 1 a = a+1 Next a Part1 = Timer - Start ' Calculate runtime ' For b = 1 To 5000 ' Task 2 b = b+1 Next b Part2 = Timer - Start - Part1 ' For c = 1 To 13000 c = c+1 Next c Part3 = Timer - Start - Part1 - Part2 ' For d = 1 To 4000 d = d+1 Next d Part4 = Timer - Start - Part1 - Part2 - Part3 ' R = R+1 Print "Loop: "R,"All Part- and Overall Time:"Part1;Part2;Part3;Part4;Timer-Start" ' Timer = Timer + 10000000 ' Get biger values in short time Loop The results show about this: From loop 1 to 15 some small fluctuations what is normal due to internal basic interpreter and timing function. At loop 15 is a small change to see what is kept until loop 27, still minor fluctuations. Then again a small change, kept until loop 54. From loop 55 onwards are only stepping changes but no more fluctuations. Loop 109 gives a big change and further values are exactly the same each loop until the program terminates after loop 215 with ERROR: Stop at line: Timer = timer + ...., Number too large for an integer, this is clear too me and not part of the question. Here some output lines: Loop: 1 All Part- and Overall time: 304 155 407 127 1000 ... values here with some small fluctuations Loop: 14 All Part- and Overall time: 304 155 407 127 1000 Loop: 15 All Part- and Overall time: 304 160 400 128 992 ... values here with some small fluctuations Loop: 27 All Part- and Overall time: 304 160 400 128 992 Loop: 28 All Part- and Overall time: 320 128 416 128 992 ... values here with some small fluctuations Loop: 54 All Part- and Overall time: 320 128 416 128 992 Loop: 55 All Part- and Overall time: 320 128 448 128 1024 ... here the same stable values like frozen Loop: 108 All Part- and Overall time: 320 128 448 128 1024 Loop: 109 All Part- and Overall time: 256 256 384 128 1024 ... here the same stable values like frozen Loop: 215 All Part- and Overall time: 256 256 384 128 1024 Stop with ERROR (as expected) As I understand the numeric variables are all in float format, and more exactly explained by Geoff as "single precision IEEE-754 floating-point format" somewhere in a thread here. On page 16 of the newest MMBasic manual is also to read about Integers: "The range of integers (whole numbers) that can be manipulated without loss of accuracy is ±16777100". 1.What does this mean to the programmer when all variables are float by default? 2.What kind of variable is Timer? Integer (16777100 max) gives not a range of 49 days, floating (3.40282347E+38 max) gives a far bigger range than 49 days. 3.How should I store the value when read the Timer? To solve my problem in the program I can reset the timer every day to keep the value small. But I am still interested to learn where the above explaind effect comes from. And a big thank to Geoff for all the work on the Maximite, it's a graet thing. merlin66 |
||||
James_From_Canb Senior Member Joined: 19/06/2011 Location: AustraliaPosts: 265 |
Ignore this. Edited out incorrect answer. James My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention. Hedley Lamarr, Blazing Saddles (1974) |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6099 |
Timer is internally 32 bit integer which would give you 49 days. However, externally (in our programs) we are limited to 32 bit floats or 16777100 before loss of accuracy. Strange things do happen when you start trying to add small numbers to 16777100 and greater. The only way is to keep the timer value small with regular resets. One way is: value=timer
if value > 1000000 then timer= value-1000000 overflow=overflow+1 One day, we might see 32 integers available for use. Jim VK7JH MMedit  MMBasic Help |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
it would be a nice enhancement if Geoff made the timer function roll over to zero exactly every 48 days, and when it does set a flag called something like 'timer_overflow' to true. |
||||
merlin66 Newbie Joined: 04/02/2013 Location: ThailandPosts: 6 |
Thanks, everything clear now, can handle this in my program. There should be a Note about this in the MMBasic manual. merlin66 |
||||
MaxUserBill Newbie Joined: 13/04/2013 Location: United StatesPosts: 4 |
This greatly helps me in my belief the Maximite will make for a GREAT robot controller using TIMER for co-operative multitasking. Nice! Please allow me to "stray" away from the TIMER topic just long enough to say what I want to attempt. A smaller board than the CGCOLORMAX2 might be nice for smaller robots, but one of my ideas is to use the VGA output with a small LCD display to show a simple robot "face" that can express a minimum of emotions. "Help me! I am stuck in a corner and I can't get free!" (Having the ability to hook up a keyboard and do some "on-site" debugging will also be a very nice option.) The way I code, quick debugging is a must! |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
The CGMMSTICK is small enough for a robot. Micromites and Maximites! - Beginning Maximite |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
And have a little speaker on board that can sob appropriately using the MOD function. Greg |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Jim, that's a succinct handy bit of info. I reckon it would be a good idea to have somewhere permanent (a section of the library maybe) where these little gems (info &/or code snippets, links) that aren't in Geoff's manual can be deposited. Doing it from the forum is probably a better idea too than people just putting things straight into say, somewhere on Geoff's website. This way Geoff can still see what's being discussed immediately, let others correct or otherwise any mis-information to take some load off him, and there would be a record for him to later modify the manual as he likes and for others to access for further info. What do you think? - errr...what does Hugh think too? Greg |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
I might make a "Tips/Tricks" section for Beginning Maximite. Micromites and Maximites! - Beginning Maximite |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
That would be a good idea CG and to some extent it might mean you wouldn't need to update some sections of the "Beginning Maximite" manual as often, if or when Geoff updated the MMBasic Manual with that info. You'd still have to change BM though as Geoff adds or changes commands and capabilities. The size of BM would be expanding again mind you. I still think you need a "live" location for it though to make it easy for people to get at the info and it seems to me the logical place would be the library. There's a lot of info back through the forum that's not that easy to find now because searches on "topics" frequently miss useful info in the threads and searches on "content" frequently bring up either too many hits or marginally useful hits. That stuff could gradually be located and added and when it's added the "topic" or effectively "keywords" can be improved or formalised a bit. Greg |
||||
Print this page |