CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Measuring MIPS with Output instructions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mickent



Joined: 18 Feb 2007
Posts: 22
Location: TN, USA

View user's profile Send private message

Measuring MIPS with Output instructions
PostPosted: Wed Jun 08, 2011 11:48 pm     Reply with quote

I need to know the MIPS that my PIC33 is running at because my DAC is running at half speed so I made a tight loop in main:

while 1,
output high;
output low;

This runs at 3.7 Mhz

Would this be 3 instructions so the MIPS is 11.1 MIPS?

Thanks, Mick
_________________
Mick
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 5:37 am     Reply with quote

MIPS usually refers to machine or assembly instructions, not lines of C code. Look at your program .lst file to see how many assembly instructions are there.
_________________
The search for better is endless. Instead simply find very good and get the job done.
mkent



Joined: 09 Sep 2003
Posts: 37
Location: TN, USA

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 12:53 pm     Reply with quote

Thanks SherpaDoug,
This is the list file:

Code:
154:               // Main Code
155:                   while (1)
156:                  {
157:                  output_high(PIN_B13);
  0330  A9A2C9     bclr.b 0x02c9,#5
  0332  A8A2CD     bset.b 0x02cd,#5
158:                  output_low(PIN_B13);
  0334  A9A2C9     bclr.b 0x02c9,#5
  0336  A9A2CD     bclr.b 0x02cd,#5
159:               /*
160:                  MotorCntlLeft= 0xfff0;
161:                  MotorCntlRight = 0xfff0;
162:                  AuxCntlWord = 0xfff0;
163:               
164:                  if(!input(PIN_B5))
165:                     {
166:                     Rover_Control_Xmit();
167:                     }
168:               */
169:                  }
  0338  37FFFB     bra 0x000330
  033A  37FFFF     bra 0x00033a


I'm still not sure how to count instructions? Does the "while" loop take clock cycles?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 1:15 pm     Reply with quote

How to use the MPLAB stopwatch feature to count instruction cycles:
http://www.ccsinfo.com/forum/viewtopic.php?t=38351
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 1:42 pm     Reply with quote

Just open up the databook for you PIC and go to the instruction set chapter. Every instruction will have the number of machine cycles it takes to executes. Bit clear, bit set are 1 cycle each, branches are 2 cycles.
So in your case 6 machine cycles. How long that takes depends on the crystal running the PIC and any divider you might have chosen...
mkent



Joined: 09 Sep 2003
Posts: 37
Location: TN, USA

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 3:06 pm     Reply with quote

Thanks for the replies.
PCM the stopwatch won't work above 20 Mhz.

My only question now is about clock cycles vs instruction cycles. The PIC33 has 2 clock cycles for each instruction cycle.
So 6 x 3.68 Mhz = 22.08 Mhz This is the MIPS (Fcy) that I expect. My clock is 44.2 Mhz.

So why does the DAC run at half speed?
Fvco = 176 Mhz,
Aux clock divider is 8 so Aclk = 22 Mhz / 256 = 86 Khz and I measure 43 Khz.
I made it work by reducing my sine array from 72 values to 36 but this bugs me.
Any ideas?

Mick
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 3:17 pm     Reply with quote

The stopwatch works at the frequency you put in as the PIC operating frequency. Defaults to 20MHz, but runs happily at 100M+...

Look at the data sheet. Oscillator section. Where does 'Fp' come from (peripheral clock used by stuff like the ADC)?. It is _not_Fosc....

Best Wishes
mkent



Joined: 09 Sep 2003
Posts: 37
Location: TN, USA

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 4:17 pm     Reply with quote

Ttelmah, I get this error when I try to use the stopwatch with a MIPS of 22 Mhz.

ADC-W0007: Cannot meet full accuracy with RC clock source and Frequency > 20Mhz

I am going to start a new thread to discuss my DAC problem for the sake of the search engine.

Mick
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 4:29 am     Reply with quote

Look carefully at your fuse settings. Just ran MPLAB up with a PIC33 selected, and clock rate of 120MHz from the internal oscillator/PLL, and no such complaint.
Happily took 0.01667uSec for an instruction....

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 10:27 am     Reply with quote

mkent wrote:
Thanks SherpaDoug,
This is the list file:

Code:
154:               // Main Code
155:                   while (1)
156:                  {
157:                  output_high(PIN_B13);
  0330  A9A2C9     bclr.b 0x02c9,#5
  0332  A8A2CD     bset.b 0x02cd,#5
158:                  output_low(PIN_B13);
  0334  A9A2C9     bclr.b 0x02c9,#5
  0336  A9A2CD     bclr.b 0x02cd,#5
159:               /*
160:                  MotorCntlLeft= 0xfff0;
161:                  MotorCntlRight = 0xfff0;
162:                  AuxCntlWord = 0xfff0;
163:               
164:                  if(!input(PIN_B5))
165:                     {
166:                     Rover_Control_Xmit();
167:                     }
168:               */
169:                  }
  0338  37FFFB     bra 0x000330
  033A  37FFFF     bra 0x00033a


I'm still not sure how to count instructions? Does the "while" loop take clock cycles?


If you use #use fast_io, you can eliminate the direction register settings in your loop, BUT YOU NEED TO MAKE SURE to do it before the while loop starts.

And yes, the while loop is essentially the BRA 0x000330 command that you must have to keep the loop going.

The BRA following is essentially to keep the PIC in a known state (rather than run off into memory) in case you DIDN'T have something in main to keep control of the process.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
eoinoc



Joined: 30 Apr 2009
Posts: 16

View user's profile Send private message

PostPosted: Mon Jun 13, 2011 6:17 am     Reply with quote

To measure you instruction speed use the repeat instruction
Code:

while(true)
{
#asm
repeat #0x3fff
btg .....
#endasm

}

This will give you a good burst of pin toggle at your instruction speed, of course there will be a small glitch at the end of the while true loop.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group