View previous topic :: View next topic |
Author |
Message |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
18f14k22 64mhz, only 2Mhz output? I don't think it takes... |
Posted: Wed Feb 22, 2012 2:31 pm |
|
|
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
|
|
|
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Wed Feb 22, 2012 3:11 pm |
|
|
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
|
|
Posted: Wed Feb 22, 2012 3:14 pm |
|
|
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
|
|
Posted: Wed Feb 22, 2012 4:01 pm |
|
|
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
|
|
Posted: Wed Feb 22, 2012 6:31 pm |
|
|
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
|
|
|
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Wed Feb 22, 2012 7:41 pm |
|
|
Oh great, I always thought this was determined by ASM rather than the PIC.
Thanks again. _________________ Vinnie Ryan |
|
|
|