Go to Post Successful teams - in almost any aspect of life (i.e. not just robotics) - don't make excuses and assign blame when something goes wrong. They improvise. They adapt. They overcome. They correct the problem and move on. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Technical Discussion
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-03-2003, 13:29
Dan's Avatar
Dan Dan is offline
Registered User
#0267 (Demolition Squad)
 
Join Date: Feb 2002
Location: Boca Raton, Fl
Posts: 7
Dan is an unknown quantity at this point
Send a message via Yahoo to Dan
Actual execution time measurement

Is there a way to externally measure the execution time of our code?

I'm interested in the actual time from the serin command to the serout command. We have a scope, etc.

I understand the 26ms cycle, that's not what I'm interested in.
  #2   Spotlight this post!  
Unread 16-03-2003, 14:10
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
We did some timing measurements like this early in the build season. We used an old robot controller that was out of warranty and took the cover off. We hooked up a logic analyzer probe to the lead of the BASIC Run LED and then toggled this at certain times in software. The BASIC Run LED doesn't go through the input or output processors so it changes as soon as you set it in the BASIC code (this is unlike all other outputs which only change when the output processor decides to change them, which as we discovered can be up to something like 16 milliseconds AFTER the serout command by the Stamp!).

If you have a controller you don't mind taking apart you should be able to recreate this easily, although measuring it with a scope will probably be a little more difficult than with a logic analyzer. If you don't have a controller that you're willing to take apart, you could always hook up a phototransistor or something similar and just tape it down over the LED on the outside of the controller.
  #3   Spotlight this post!  
Unread 17-03-2003, 13:05
DKolberg DKolberg is offline
Mentor Iron Giants
AKA: David Kolberg
FRC #5069 (Iron Giants)
Team Role: Mentor
 
Join Date: May 2002
Rookie Year: 2000
Location: South Bend
Posts: 44
DKolberg has a spectacular aura aboutDKolberg has a spectacular aura about
Another method is to develop a delay routine that can be called a number of times. You can change the code to the simple serial in and out with nothing else, set up a loop to call the delay n times. Monitor the delay_t value and keep increasing n until a one is picked up in the delay_t. Now you can calculate the time of the delay routine by taking the inverse of 38*n. From this you can just check how much time is remaining in your code by adding a loop after the serial out to delay n times and up n until the delay_t goes to 1. This will tell you how much room you have left. Just remember to comment out the loop before competition.
  #4   Spotlight this post!  
Unread 18-03-2003, 13:33
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
I put a line in the code right after the RUN LED toggle line to set a relay output = the inverse of itself

and put a digital scope on the (middle ?) pin of the relay output.

I was surprized to see the period of the resulting toggling signal is about 20 Hz (goes high, goes low)

BUT the duty cycle is NOT 50% - the HI and LOW times were something like 16.6mS and 33.4mS - very consistantly

so the average cycle frequency for 2 cycles is 40 Hz, but individual passes through the code happen at a rate of 60Hz and 30Hz.

I have no idea why this is.

I also have noticed, if you program a toggle switch on the robot switch inputs to control an LED on the operator interface - there is a NOTICABLE delay from when you throw the switch until the LED goes on.

I did not measure it with a scope -but Im guessing its a quarter second at least. If this is true the other way too - that it takes a quarter second for inputs at the operator interface to reach the relay or PWM outputs on the robot, that would be interesting.

It would mean the robot doesnt respond very quickly to operator commands. I will test this 'system propagation delay' with the digital scope sometime when Im not swamped with other tasks.
  #5   Spotlight this post!  
Unread 18-03-2003, 14:41
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
We did a lot of this kind of testing and our results match what Ken is seeing. The first thing that we figured out is that the RC outputs do NOT change at the moment that the Stamp sends the serout command. We determined that the outputs change at 16ms intervals (independent of when the Stamp executes a serout), just as Ken found. What we believe is happening is that there is a timer inside the RC that changes the outputs every 16ms. Since the Stamp only sends new outputs every 26ms, you get the situation described above. Because of the different I/O frequencies (40Hz versus 60Hz), sometimes the RC changes the outputs once between serouts and sometimes it's able to change them twice. If the RC changes the outputs twice in between serouts, it doesn't actually have new output values so it keeps them all the same. This is where the 33ms interval comes from.

Anyway, the bottom line is that from the point at which the Stamp executes a serin to read the state of the joysticks and RC inputs, there can be a delay of up to 42 milliseconds before the outputs respond! It's very likely that a similar situation exists on the OI side, which could easily double the total delay in the system which brings it up near 1/10 of a second, which is where the delay starts to get noticeable.
  #6   Spotlight this post!  
Unread 24-03-2003, 11:36
kmcclary's Avatar
kmcclary kmcclary is offline
Founder 830/1015;Mentor 66/470/1502
FRC #0470 (Alpha Omega Robotics)
Team Role: Engineer
 
Join Date: Aug 2001
Rookie Year: 1994
Location: Ann Arbor, MI
Posts: 491
kmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond reputekmcclary has a reputation beyond repute
Re: Actual execution time measurement

Quote:
Originally posted by Dan
Is there a way to externally measure the execution time of our code?

I'm interested in the actual time from the serin command to the serout command. We have a scope, etc. I understand the 26ms cycle, that's not what I'm interested in.
Hi! I'm an embedded microprocessor development Engineer.

Well, knowing the loop rate is one thing, but in reality you still have to deal with the numerous I/O processor latency steps as well...

One problem is the RC's Stamp is not running the I/O lines. A slave PIC is doing that job asynchronously. The Stamp SERIN and SEROUT statements in the default program talk to this I/O processor, which then updates the outputs some time later.

(Actually, I think someone said there are TWO PICs in the RC, to deal with both I/O and RF modem issues, but I haven't looked under the hood yet to confirm that...)

I did talk to IFI about this. They said the I/O pic is pretty fast at getting the outputs out there (WAY below "one loop time"). However, you COULD have an additional "I/O processor input scan loop" delay added to the loop time if the new inputs weren't ready to go when the SERIN handshake came in, so keep that in mind when totaling up your "control stick/switch wiggle input to output PWM reflection" time calculation.

Worst case, for operator controls you have the sum of:
1) The OI's I/O processor input scan maximum time
2) The OI's Modem PIC processor loop time
3) The EWave modems RF data transfer link latency
4) The RC's Modem PIC processor loop time
5) The RC SERIN start through SEROUT done loop time (user program)
6) The RC I/O PIC processor output maximum time

For RC sensor to output calculations you have the sum of:
1) The RC I/O PIC input scan loop maximum time
2) The RC SERIN start through SEROUT done loop time (program)
3) The RC I/O PIC processor maximum output time

As ALL of these are asynchronous, they're often tough to TRULY measure, without getting some PIC performance data from IFI. I *think* IFI said the IO PICs are fairly fast, and run their scanning loops on the order of tens of microseconds. Not too bad! However, I've NO clue as to the maximum latency of the EWave modem link on a congested channel. (That's something I wish to find out some day from EWave.)

Anyway... Given that there are other latencies, I'd advise simply toggling two output I/O bits that are unused in your user code as follows: one before the SERIN, and another one after the SEROUT. Watch them BOTH on a dual trace scope. This width will oscillate as you catch the various IO PICs at different times in their scanning cycles. The MINIMUM width is a good "first approximation" of the loop time. Subtracting that time off of the MAXIMUM width you see gives you a good approximation of the PIC I/O processor's output loop time.

Next: Tie one of those toggling output bits to an unused RC digital input bit, and have yet ANOTHER unused output bit "follow" it. Watching the latency (and compensating for the above times) now allows you to characterize a "typical" PIC *input* scanning loop time.

If you're truly interested in measuring the Stamp Loop Time at a FINER level (the original question):

Unfortunately, I don't see a simple way to measure the true loop time that wouldn't involve cracking the case. You can't do this with the current year's RC... Not only does that ruin the warranty, it makes your RC illegal for the contest.

Instead, for development work crack the case of LAST YEAR'S RC (that is out of warranty and won't be used for the current contest), and tap ITS Stamp with a clip-on logic probe. Now use IT as a development platform. Warning: If the RC has changed too much from the previous year, you'll have to buy an additional new "sacrificial" RC for this job. Luckily, if the RC hardware hasn't changed from the previous year, IFI *will* for a much smaller price upgrade your old RC's firmware to the current contest year (but then you may find you'll have to send in your old OI in as well for a firmware upgrade to continue using your OLD robot for team demos and driver practice, or risk orphaning the old OI out <sigh>).

Assuming you ARE cracking the RC's case, the constants COMA, COMB, COMC, and USERCPU in the default code show that the serial I/O and handshakes to/from the slave processor(s) run off of Stamp pins 1-4. Look up the SERIN/SEROUT statements in the PBASIC manual to see how those instructions work at the hardware level. Comparing that to the default code tells you which pins to use, and how to set your scope sync slope.

Now, using a dual trace scope, trigger on the SERIN handshake "request to send" assertion. Compare that time until the SEROUT handshake is completed on the other scope channel, and you're done!

DISCLAIMER: As I'm busy starting up rookie teams (this is my second rookie in two years I've started), I've never had an "old RC" yet to work with! (DARN!) Therefore, though I'm highly curious, I have NOT cracked open an RC's case yet, since *I* am not getting us in trouble for the contest itself! . Therefore, I don't know how accessible the Stamp is on the PCB for probe clips. However, I've developed embedded micro applications for years, and simply can tell these pins definitions are correct, by looking at the RC default code.

Once the warranties are ALL out though, I DO plan on checking out some of the IFI hardware "under the hood" to allow me to create finer resolution "FIRST control system system architecture overview diagram" training materials for our students than IFI gives us... (Of course if some team near Ann Arbor already has old hardware cracked open and/or documented, **PLEASE*** drop me a line and we'll go through it together!)

I hope this helps! If you have any other embedded micro development questions, please feel free to ask.

Good luck, and please send me the numbers you come up with!

- Keith
__________________
Keith McClary - Organizer/Mentor/Sponsor - Ann Arbor MI area FIRST teams
ACTI - Automation Computer Technologies, Inc. (Sponsoring FIRST teams since 2001!)
MI Robot Club (Trainer) / GO-Tech Maker's Club / RepRap-Michigan) / SEMI CNC Club
"Certifiably Insane": Started FIVE FRC teams & many robot clubs (so far)!
2002: 830 "Rat Pack" | 2003-5;14: 1015;1076 "Pi Hi Samurai" | 2005-6: 1549 "Washtenuts"/"Fire Traxx"
2005-(on): 1502 "Technical Difficulties" | 2006-(on): FIRST Volunteer!
2009-(on): 470 "Alpha Omega" | WAFL | Sponsor & "Floating Engineer" for MI Dist 13 (Washtenaw Cnty)
2011: 3638 "Tigertrons" | 2013-(on): 4395 "ViBots" | 2014-(on) 66 "Grizzlies"
"Home" Teams: 66, 470, 1076, 1502, 4395
Local FIRST alumni at or coming to Ann Arbor (UM/EMU/WCC/Cleary)?
...We Want YOU as a Mentor! Please email me for info!
Support CDF Reputation - If a posting helped, thank 'em with rep points!
"It must be FRC build season when your spouse and children become 'Action Items 8 & 9'..."
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
time change David Kelly Chit-Chat 14 06-04-2003 23:10
Solution to Timing Loops Steven Carmain Programming 39 10-02-2003 13:33
How long should production time be??? archiver 1999 4 23-06-2002 23:16
Nationals accomodations, etc Caliostro Championship Event 21 21-12-2001 14:31
need help with time zone! Ken Leung General Forum 6 25-06-2001 12:44


All times are GMT -5. The time now is 17:43.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi