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

18f14k22 64mhz, only 2Mhz output? I don't think it takes...

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



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

18f14k22 64mhz, only 2Mhz output? I don't think it takes...
PostPosted: Wed Feb 22, 2012 2:31 pm     Reply with quote

I don't think it takes 12 clock cycles to run a simple output_high instruction.

I'm running the 18f14k22 at 64Mhz. The problem is, my program is as simple as:

Code:

#include "18f14k22.h"
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP,PLLEN,NOMCLR
#use delay(clock=64M)

void main()
{
   setup_oscillator(OSC_PLL_ON | OSC_16MHZ);
   //setup_oscillator(OSC_64MHZ); //also tried this w/o PLLEN fuse
   while(1)
   {
      output_high(pin_a0);
      output_low(pin_a0);
   }
}



When I monitor the output to A0, I only get 2.6Mhz. This would mean that it takes 24 clock cycles just to run 1 frame of output high, output low.

Am I missing something or is this correct?
_________________
Vinnie Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 2:45 pm     Reply with quote

Look at your .LST file and compare it to this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=38338

Also, remember that in 8-bit PICs (such as the 18F-series), it takes 4 Fosc
cycles per instruction cycle.
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed Feb 22, 2012 3:11 pm     Reply with quote

Based on that I'm still missing many clock cycles.

Code:
....................       output_high(LED);
01E0:  BCF    F92.5
01E2:  BSF    F89.5
....................       output_low(LED);
01E4:  BCF    F92.5
01E6:  BCF    F89.5
....................    }
01E8:  BRA    01E0
.................... }


Instruction / number of clocks required / total clocks used

BCF 1 1
BSF 1 2
BCF 1 3
BCF 1 4
BRA 2? 6

This brings me to a total of 6 clock cycles. I should be able to get 10Mhz if this is correct. Can you confirm?

EDIT: On second thought, I forgot to divide the clock/4 before counting cycles. Now it adds up.

64Mhz / 4 = 16M
16M / 6 Instructions = 2.66Mhz which happens to be exactly the speed I'm getting. Well at least I learned something today! Thanks PCM!
_________________
Vinnie Ryan


Last edited by vinniewryan on Wed Feb 22, 2012 3:15 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 3:14 pm     Reply with quote

64 MHz / 4 = 16 MHz instruction clock.

16 MHz / 6 instructions = 2.67 MHz loop frequency
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed Feb 22, 2012 4:01 pm     Reply with quote

Thanks for the help. I'll look into using fast_io to save a couple cycles.

cheers.
_________________
Vinnie Ryan
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed Feb 22, 2012 6:31 pm     Reply with quote

How do I know how many cycles an instruction will take? In that link, you mentioned that BSF and BCF each take 1 cycle, but GOTO takes 2. Is there a resource or document that lists each instruction and the amount of required cycles to execute?

I'm trying to interface with a camera sensor using a PIC. I've found that 64Mhz is too slow so I need to calculate the required speed in MIPs in order to choose the correct DSPIC.
_________________
Vinnie Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 7:01 pm     Reply with quote

Download the 18F14K22 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/41365E.pdf
Look at this table. It gives the instruction cycles for each instruction:
Quote:

TABLE 23-2: PIC18FXXXX INSTRUCTION SET
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed Feb 22, 2012 7:41 pm     Reply with quote

Oh great, I always thought this was determined by ASM rather than the PIC.

Thanks again.
_________________
Vinnie Ryan
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