# clock speed little question

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Jan 4, 2012.

1. ### Eric007 Thread Starter Senior Member

Aug 5, 2011
1,044
33
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...

2. ### mik3 Senior Member

Feb 4, 2008
4,846
63
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.

3. ### Markd77 Senior Member

Sep 7, 2009
2,803
594
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.

4. ### Eric007 Thread Starter Senior Member

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

5. ### t06afre AAC Fanatic!

May 11, 2009
5,939
1,222
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.

6. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
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.

7. ### Eric007 Thread Starter Senior Member

Aug 5, 2011
1,044
33

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...

8. ### Eric007 Thread Starter Senior Member

Aug 5, 2011
1,044
33
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

9. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,386
1,605
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?

10. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
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.

11. ### joeyd999 AAC Fanatic!

Jun 6, 2011
2,675
2,724
This sounds like it has something to do with his speech recognition system.

Aug 5, 2011
1,044
33
Hahahaha....

13. ### Eric007 Thread Starter Senior Member

Aug 5, 2011
1,044
33
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: Jan 4, 2012
14. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
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.

15. ### Eric007 Thread Starter Senior Member

Aug 5, 2011
1,044
33
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!

16. ### Markd77 Senior Member

Sep 7, 2009
2,803
594
You might find a few similarities, but the PIC16 and PIC32 are as different as apples and trousers.

17. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
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.

18. ### Eric007 Thread Starter Senior Member

Aug 5, 2011
1,044
33
Oh that's not a good news...hope instruction set is the same and hope I can adjust smoothly and quikly!

Thanks!

19. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
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

20. ### Eric007 Thread Starter Senior Member

Aug 5, 2011
1,044
33
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!