View Single Post
  #12   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) */