Go to Post [This year's game manual contains] 46 new pages of pictures displaying how to attach bumpers, assuring at least 15% of teams almost get it right this time. - PayneTrain [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 08-02-2004, 21:09
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
How to measure execution time? And code size?

Can someone describe a simple way to measure how much of the 26 ms time budget is being used? As I add code I would like to know how close I am coming to the limit.

Also, how do I know how close I am to the memory limits for code and data?

Thanks all,
Norm
  #2   Spotlight this post!  
Unread 09-02-2004, 04:03
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: How to measure execution time? And code size?

Add a breakpoint at the top of process_data_from_master_uP and at the bottom. Then use the simulator and the stopwatch to calculate the time different between the 2 breakpoints.

For the memory thing, use the simulator and just look at the memory map of program and data memory.
  #3   Spotlight this post!  
Unread 09-02-2004, 07:32
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: How to measure execution time? And code size?

What simulator? I tried one in mplab, and it got stuck in one of the transmission loops!
  #4   Spotlight this post!  
Unread 09-02-2004, 08:54
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: How to measure execution time? And code size?

Quote:
Originally Posted by gnormhurst
Can someone describe a simple way to measure how much of the 26 ms time budget is being used? As I add code I would like to know how close I am coming to the limit.

Also, how do I know how close I am to the memory limits for code and data?

Thanks all,
Norm
To measure the time, you should toggle a digital I/O pin every cycle. Then, hook an oscilliscope up to that pin. Using the scope, you can measure your timing very accurately.

Some example code (place this at the very beginning of your code):

static char TimingFlag;

if (TimingFlag)
TimingFlag = 0;
else
TimingFlag = 1;

Then immediately set the digital I/O pin equal to TimingFlag.

This code will produce a square wave on the scope. The time that the wave is high (or low) is your cycle time. I hope this helps.

-Chris
__________________
-
An ounce of perception is worth a pound of obscure.
  #5   Spotlight this post!  
Unread 09-02-2004, 09:01
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,856
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: How to measure execution time? And code size?

Quote:
Originally Posted by gnormhurst
Can someone describe a simple way to measure how much of the 26 ms time budget is being used? As I add code I would like to know how close I am coming to the limit.

Also, how do I know how close I am to the memory limits for code and data?

Thanks all,
Norm
For the timing I set an internal timer and initialize the timer at the start and read it when it comes around again. You can use clock ticks or convert it to ms. I wouldn't use the MPLAB SIM for this.
For the default code you get 112,840 to 112,892 loops per second or ~42 (THE_ANSWER) ticks per loop for the basic default program (results may vary).

There are a couple of ways to check memory utilization.
1) When you open the .hex file in the IFI_Loader there is a text string at the bottom of the IFI_Loader window that tells you how much space the .hex file uses. For instance, the FRC default code will show:
"Total Bytes 2C90, Erase Size B5, Flash 800-3510, MemSize 2D10"

2)A memory map can be generated by MPLAB whenever you compile your code. You have to turn it on by going to Project -> Build Options... -> Project then click on the "MPLINK Linker" tab, then click on "Generater map file". After you build your project look in the project directory for a text file ending in ".map" just a little way down the file it will have a section that looks like:
Code:
                              Program Memory Usage 
                               Start         End      
                           ---------   ---------      
                            0x000800    0x000837      
                            0x0008d4    0x0033d8      
                            0x0033da    0x003511      
                            0x300000    0x30000d      
            11395 out of 33816 program addresses used, program memory utilization is 33%
This gives you the program or rom space used. For the data or ram space it's a little harder. After the section above all space used will be listed by address. You'll see your familiar variables listed. You have to check the maximum addresses used by the data portion of your code.
Code:
e.g.,
    I   0x0007b7       data     static C:\mcc18\Projects\FrcCode\FrcCode\ifi_library.c
count   0x0007b8       data     static C:\mcc18\Projects\FrcCode\FrcCode\ifi_library.c
 temp   0x0007b9       data     static C:\mcc18\Projects\FrcCode\FrcCode\ifi_library.c
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 09-02-2004 at 11:17.
  #6   Spotlight this post!  
Unread 09-02-2004, 09:44
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: How to measure execution time? And code size?

Quote:
Originally Posted by gnormhurst
Also, how do I know how close I am to the memory limits for code and data?
The loader reports some information on program size. I'm not sure what it all means, but it's there.
  #7   Spotlight this post!  
Unread 09-02-2004, 10:49
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: How to measure execution time? And code size?

Quote:
Originally Posted by Astronouth7303
What simulator? I tried one in mplab, and it got stuck in one of the transmission loops!
Yeah, the simulator they have is fairly worthless.
__________________

  #8   Spotlight this post!  
Unread 09-02-2004, 10:56
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
Re: How to measure execution time? And code size?

measureing timeing on the simulator wont tell you what you want to know, because the SW will be running on your PC, not on the target system (the RC) which is what really matters.
  #9   Spotlight this post!  
Unread 09-02-2004, 11:10
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: How to measure execution time? And code size?

Quote:
Originally Posted by KenWittlief
measureing timeing on the simulator wont tell you what you want to know, because the SW will be running on your PC, not on the target system (the RC) which is what really matters.
I don't know squat about the Simulator, but I think Mr. Lundy may have been saying that the Simulator is "clock speed-aware". It may know, or can be told, what the processor's clock rate is. I guess if the code doesn't use interrupts, that would be enough to determine the number of processor clock cycles between two points in the code.

realExecutionTime = simulatedClockCycles * realClockPeriod

I'll have to have a closer look at the simulator. At this point I feel like I don't have time to go up another learning curve. But I should probably do it anyway...
  #10   Spotlight this post!  
Unread 09-02-2004, 11:33
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: How to measure execution time? And code size?

Quote:
Originally Posted by Chris Hibner
To measure the time, you should toggle a digital I/O pin every cycle. Then, hook an oscilliscope up to that pin. Using the scope, you can measure your timing very accurately.

Some example code (place this at the very beginning of your code):

static char TimingFlag;

if (TimingFlag)
TimingFlag = 0;
else
TimingFlag = 1;

Then immediately set the digital I/O pin equal to TimingFlag.

This code will produce a square wave on the scope. The time that the wave is high (or low) is your cycle time. I hope this helps.

-Chris
Oh yeah, I forgot one thing.

My first post only works if you're running the loop time as fast as possible. It doesn't work if you're setting your loop time with an interrupt. To measure this way do the following:

1) At the VERY BEGINNING of your loop, set a digital I/O pin high.
2) At the VERY END of your loop, set the same digital I/O pin low.
3) Measure the pin voltage on a scope.

The amount of the the pin stays high is the amount of time that your code takes to run.

(By the way, this is how code time is usually measured in industry.)
__________________
-
An ounce of perception is worth a pound of obscure.
  #11   Spotlight this post!  
Unread 09-02-2004, 11:34
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: How to measure execution time? And code size?

Quote:
Originally Posted by Chris Hibner
To measure the time, you should toggle a digital I/O pin every cycle. Then, hook an oscilliscope up to that pin. Using the scope, you can measure your timing very accurately.

Ooo, I like the idea of using a scope. Technology that I understand!

But I think the code you suggest may not give me what I want. I think the code you suggest would toggle a pin with every 26 ms cycle of the code, so the high and low portions of each square wave cycle would each be 26 ms, regardless of how long my code was taking.

Your code was:

Code:
static char TimingFlag;

if (TimingFlag)
    TimingFlag = 0;
else
    TimingFlag = 1;

// Then immediately set the digital I/O pin equal to TimingFlag.

How about this instead, in main.c. Note the two lines with ***:
Code:
  while (1)   /* This loop will repeat indefinitely. */
  {

    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {                                 /* I'm slow!  I only execute every 26.2ms because */
                                      /* that's how fast the Master uP gives me data. */
      rc_dig_out01 = 1;  // *** look at this on a scope to see when loop starts
      Process_Data_From_Master_uP();  /* You edit this in user_routines.c */

      if (autonomous_mode)            /* DO NOT CHANGE! */
      {
        User_Autonomous_Code();        /* You edit this in user_routines_fast.c */
      }
    }
    Process_Data_From_Local_IO();     /* You edit this in user_routines_fast.c */
                                      /* I'm fast!  I execute during every loop.*/
    rc_dig_out01 = 0;  // *** look on scope to see how long it took!
  } /* while (1) */
  #12   Spotlight this post!  
Unread 09-02-2004, 12:32
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: How to measure execution time? And code size?

Quote:
Originally Posted by Astronouth7303
What simulator? I tried one in mplab, and it got stuck in one of the transmission loops!
remember that you have to have the constant "_SIMULATOR" defined while compiling code for the simulator - this keeps the program from bogging down in the transmission loop.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #13   Spotlight this post!  
Unread 09-02-2004, 13:02
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: How to measure execution time? And code size?

Yeah I didn't mean an actual stopwatch, there is a function in the simulator that keeps track of time based on chip speed. It's called the "stopwatch".

But the oscilloscope idea sounds easier (assuming you have an oscilloscope you can use).

[EDIT]Oops...

Last edited by Jay Lundy : 10-02-2004 at 01:50.
  #14   Spotlight this post!  
Unread 09-02-2004, 14:00
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: How to measure execution time? And code size?

Quote:
Originally Posted by Jay Lundy
oscillator
i'm guessing you mean "oscilloscope".
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #15   Spotlight this post!  
Unread 09-02-2004, 16:03
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
Re: How to measure execution time? And code size?

engineers have to learn to listen to what people mean, not what they say
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
Interrupt timer, executing code asap? SeanCassidy Programming 10 07-03-2004 01:47
Actual execution time measurement Dan Technical Discussion 5 24-03-2003 11:36
Autonomous Code From Experience EbonySeraphim Programming 7 14-03-2003 21:56
Ok one problem cantwell03 Programming 3 13-02-2003 07:28
Solution to Timing Loops Steven Carmain Programming 39 10-02-2003 13:33


All times are GMT -5. The time now is 00:02.

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