Arduino Command - millis();
John Board
Posts: 371
Hi everyone,
I've just been doing quite a bit of exciting stuff with my robot - the robot is now looking like it might be able to get finished on schedule :P It's following lines well using the QTI Sensors. So, now it comes to my problem, I've been trying to figure out what things I should have turned on while my robot is follow a like - i.e. should I have info debugging to the LCD? These are a few questions that are pretty much directly related to the speed of the code - if my LCD takes too long to display things while running the line following, my robot will skip over the line because the motors couldn't update fast enough. So, basically, I need a way of finding out how long each main loop cycle took. I was thinking along the lines of this:
(Psudo Code)
Not perfect.. but you get the picture. Only problem is, I'm not sure if that's quite how I should do it, and also that the result will probably not be in milliseconds. Also, I have no idea how to convert the result into MS. Also the cnt seems to be all over the place :blank: Any help is appreciated!
P.S. This is kind of based of the arduino's "Millis" function: http://arduino.cc/en/Reference/Millis
-John
I've just been doing quite a bit of exciting stuff with my robot - the robot is now looking like it might be able to get finished on schedule :P It's following lines well using the QTI Sensors. So, now it comes to my problem, I've been trying to figure out what things I should have turned on while my robot is follow a like - i.e. should I have info debugging to the LCD? These are a few questions that are pretty much directly related to the speed of the code - if my LCD takes too long to display things while running the line following, my robot will skip over the line because the motors couldn't update fast enough. So, basically, I need a way of finding out how long each main loop cycle took. I was thinking along the lines of this:
(Psudo Code)
PUB Main | oldtime, newtime repeat newtime := cnt LCD.Dec(newtime-oldtime) oldtime := cnt
Not perfect.. but you get the picture. Only problem is, I'm not sure if that's quite how I should do it, and also that the result will probably not be in milliseconds. Also, I have no idea how to convert the result into MS. Also the cnt seems to be all over the place :blank: Any help is appreciated!
P.S. This is kind of based of the arduino's "Millis" function: http://arduino.cc/en/Reference/Millis
-John
Comments
This displays the code duration in ticks and in milliseconds. If you get 0 milliseconds then divide clkfreq by 1_000_000 to get microseconds.
I tend to start a new cog just for spitting debug info to a screen or LCD so that the time required to do that does not interfere with other processes. It's quite easy to do.
-John
What you fail to understand is that the setup for waitcnt takes time. What you also fail to understand is that putting the timing calculation inside your reporting statement is also artificially adding time. The -544 section in my code snippet actually corrects for the setup of the Spin statements in front of and just after the test code; with no test code the program will report 0 ticks.
It's not perfect because you fouled it up!
Sorry, I did put it a bit odly, and I can see how you would get anoyed at my remark - what I meant is, it is good code, but I need to tweak it slightly to put it into my robot - sorry for putting it like that. Well anyway, I'll put it in the robot today, and it should be a good adition to it
Sorry again,
-John
Thanks! I got it working! Sorry about me mixing my words up a bit earlier - this code will be perfect for what I need
-John