# clock speed little question

#### Eric007

Joined Aug 5, 2011
1,158
Hi all!

I got a very little question!

What's the difference between the 'operating speed' (device frequency) and the 'internal oscillator frequency' (31khz - 8 Mhz)?

Datasheet says PIC16F690 operating speed: 20 Mhz clock input

Basically what I'm trying to understand is the role of the two above...

#### mik3

Joined Feb 4, 2008
4,843
It means that the PIC has an internal oscillator which can be used to clock the PIC. It can be set between 31kHz and 8MHz. However, an external oscillator (like a crystal) can be used up to 20MHz.

#### Markd77

Joined Sep 7, 2009
2,806
The 20MHz is the maximum frequency of an external crystal or oscillator. If used then the PIC would run at the crystal frequency, many frequencies are available. Without the crystal, the PIC can use one of it's internal oscillator modes.
Whichever you use, most PIC16 chips instructions take 4 cycles (except goto, call, return, retfie, and conditional branching instructions like btfsc, which take twice as long) so at 20MHz you get 5 million instructions per second, at 8MHz you get 2 million per second, etc.

#### Eric007

Joined Aug 5, 2011
1,158
Ohk! I got it...so even when using external oscillator, it also gets divided by 4! Right?

#### t06afre

Joined May 11, 2009
5,934
Ohk! I got it...so even when using external oscillator, it also gets divided by 4! Right?
If you use an external oscillator(or crystal) equal to 4 MHz, or the the internal one set to 4 MHz. The two modes will equivalent regarding instructions per second. The Internal Oscillator is a good option for the beginner. It may lack the ppm accuracy then using a crystal oscillator. But it will work without any problems at all. Given that your PIC is powered correct.

#### thatoneguy

Joined Feb 19, 2009
6,359
Another tip: Don't always try to run the controller at the highest possible speed. That typically only runs the battery dead faster since uC's draw current when switching. Each oscillator cycle is a switch.

If you have delays in your code for reasons other than bit banging and LCD initialization, the clock is often too fast, and you'll get a lot longer battery life by going down to a 1 Mhz clock, or even 32kHz for applications like long period timers that need to blink an LED once an hour for a year.

#### Eric007

Joined Aug 5, 2011
1,158

I been writing codes here and I never used an external oscillator...I always run my pics at 4Mhz or 8 Mhz...

We'll understand why I am asking these questions in my next post...

#### Eric007

Joined Aug 5, 2011
1,158
Assume the following: a AVR uC running at 16 Mhz, a ADC sampled at 4Khz --> all the remaining code of the program must be able to execute in 4000 clock cycles (=16 millions/4Khz)...does it make sense!?

I know a lil bit of AVR but I'm a PIC guy! So I was thinking if I have to use a Pic in a program where I'll use an ADC sampled at ~4Khz and need at (let's say) 5000 clock cycle for remaing of my code program...==> that will make: 4000 clock cycle (ADC) times 5000 (remaing of code) = 20Mhz.

==> I will need a PIC that can run at 4 * 20Mhz = 80 Mhz.

Hope I'm explaining well what I'm trying to figure out...

If the above makes sense and is correct then I will say I don't like the fact that PiCs always divides its frequency by 4!

Regards, Eric

#### ErnieM

Joined Apr 24, 2011
8,382
Well I have a PIC that runs at 80 MHz, but that's both the clock and the instruction rate, so it is probably too fast for you.

5,000 instructions is a pretty good chunk of code, what are you doing with these 10 bits that takes that many instruction to process?

#### thatoneguy

Joined Feb 19, 2009
6,359
I believe your code could be optimized a great deal if 20Mhz is 4 times too slow when working with an ADC sample 4,000 times per second.

#### joeyd999

Joined Jun 6, 2011
5,402
Well I have a PIC that runs at 80 MHz, but that's both the clock and the instruction rate, so it is probably too fast for you.

5,000 instructions is a pretty good chunk of code, what are you doing with these 10 bits that takes that many instruction to process?
This sounds like it has something to do with his speech recognition system.

#### Eric007

Joined Aug 5, 2011
1,158
This sounds like it has something to do with his speech recognition system.
Hahahaha....

#### Eric007

Joined Aug 5, 2011
1,158
Guess my question was clear...

First, are there PICs with a bigger selectable frequency range 31Khz - 8Mhz ? (Well I'm interrested with the upper limit of the range)

Can you guyz then suggest me with a Pic that can run at Fosc/4 = ~ 20Mhz, PLEASE!!!??
Guess it is going to be a PIC that can accept an external (crystal) oscillator of 80Mhz, isnit?

Thanks!

Last edited:

#### thatoneguy

Joined Feb 19, 2009
6,359
If you are going to try speech recognition PIC32 80Mhz Arduino compatible board

It's a MIPS core (parallel processing), and runs at minimum 80 million instructions per second, sometimes more.

#### Eric007

Joined Aug 5, 2011
1,158
Thanks again thatoneguy!

Ima go for one one these: they both can run at 80Mhz...

PIC32MX320F128H (16K of RAM)
PIC32MX575F512H-80I/PT (64K of RAM)

Ima order it as soon as I can... I'll check their datasheets...
hope I can breadbord it and program it with my pickit3...
Also hope there won't be major change in programming...

Cheers!

#### Markd77

Joined Sep 7, 2009
2,806
Also hope there won't be major change in programming...
Cheers!
You might find a few similarities, but the PIC16 and PIC32 are as different as apples and trousers.

#### thatoneguy

Joined Feb 19, 2009
6,359
Thanks again thatoneguy!

Ima go for one one these: they both can run at 80Mhz...

PIC32MX320F128H (16K of RAM)
PIC32MX575F512H-80I/PT (64K of RAM)

Ima order it as soon as I can... I'll check their datasheets...
hope I can breadbord it and program it with my pickit3...
Also hope there won't be major change in programming...

Cheers!
You can program it with your PICKit 3, though I'd suggest getting the Arduino compatible one to start, it's cheap for what you get.

The PICKit 3 is about the only thing that is the same. New compilers, entirely different structure, etc.

#### Eric007

Joined Aug 5, 2011
1,158
You might find a few similarities, but the PIC16 and PIC32 are as different as apples and trousers.
Oh that's not a good news...hope instruction set is the same and hope I can adjust smoothly and quikly!

Thanks!

#### thatoneguy

Joined Feb 19, 2009
6,359
Oh that's not a good news...hope instruction set is the same and hope I can adjust smoothly and quikly!

Thanks!
The instruction set is close if you are programming in C

MIPS is an ENTIRELY different architecture than the mid-range PIC architecture. Take a look at MIPS on wiki.

They are the class of processors in the PSP and PlayStation 2

#### Eric007

Joined Aug 5, 2011
1,158
I plan to program in assembly language...I'm confortable wit assembly and not with C

Oh this is scary now! Is there a Pic out there with midrange architecture and that can run with ~60Mhz to ~80Mhz????

Thanks!