How to measure the Fcy of a PIC with oscilloscope?

Thread Starter

richiechen

Joined Jan 1, 2012
93
Hi everyone

I am using a dsPIC33EP. And I have configured the dsPIC in the 60MIPS mode. However, how can I check to see if the PIC is actually working under 60MIPS?

I wrote a simple code:
while(1) { _LATB5=~_LATB5; }

And on the oscilloscope it shows a square wave of around 1us. However, I dont understand the relation between the sample code and the Fcy.
Is it possible that two runs of the while loop will take 30 cycles?

Could anyone help me?

Thank you very much.

Best regards
Richie CHEN
 

ErnieM

Joined Apr 24, 2011
8,377
That's one of the first things I also do with a new design: verify it is running as fast as I think it's running. I skipped over PIC33's and went from PIC18 to PIC32, but I believe they are similar to what I've done.

Are you working inside MPLAB? If so, enable any debugger you like (MPLAB sim if you're new to this) and drop a breakpoint at your code. Run the code till it stops, and pick View | Disassembly listing from the menu. Now you see how many basic instructions your code is actually taking.

Any jump in a PIC (excepting PIC32's) takes 2 instruction cycles, so the minimum number of cycles your code has is 3 per half cycle. I usually do something like this:

Typically directly setting a port pin will just take C 1 cycle, so I do this (and check the disassembly listing too):

Rich (BB code):
while(1)
{
  _LATB5 = 0;
  _LATB5 = 1;
  _LATB5 = 0;
  _LATB5 = 1;

...

  _LATB5 = 0;
  _LATB5 = 1;
}
It's just test code to be dumped anyway... so give it LOTS of 1's and 0's so they look nice on your O scope.
 

Thread Starter

richiechen

Joined Jan 1, 2012
93
Thank you Ernie!! It works!
Does this:
BSET LATB, #5

mean 1 instruction cycle?
If so , it seems the MCU cannot reach the specification declared.

Cheers
Richie
 

THE_RB

Joined Feb 11, 2008
5,438
I use an old trick like this;

while(1)
{
LATA.F0 = TMR0.F7;
}

This gives zero average error and on most PICs give a frequency of xtal/1024 (assuming TMR0 prescaler is set to 1:1). On a PIC33 you will need to specify the right timer bit and the right output port pin of course.
 

ErnieM

Joined Apr 24, 2011
8,377
Thank you Ernie!! It works!
Does this:
BSET LATB, #5

mean 1 instruction cycle?
If so , it seems the MCU cannot reach the specification declared.
Well, I don't know lol. I don't use those devices but if you are inside MPLAB you can call up the disassembly listing form the menu and see just how many instructions each C statement created. Using MPLAB sim you can single step thru these and insure they do indeed execute in 1 cycle.

Markd77 may have a better idea using REFOCON. I don't have anything to add to his suggestion but it sounds like other people have had your problem and there is an existing solution.
 
Top