Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What clock frequecy do i need?

Status
Not open for further replies.

davepusey

Member
I need my PIC to execute instructions at a precise rate of 22,050 per second. What clock frequency so I need?
 
From what i've just read in the datasheet the Clock Freq = Instruction Rate * 4

Am i correct. If I am that would mean that 22,050 instructions per secound * 4 = 88,200Hz clock freq.

Is all that correct? I hope so!
 
davepusey said:
From what i've just read in the datasheet the Clock Freq = Instruction Rate * 4

Am i correct. If I am that would mean that 22,050 instructions per secound * 4 = 88,200Hz clock freq.

Is all that correct? I hope so!

Yes it is, but not all instructions take only one clock cycle - jumps take two, and branches take either one or two.

Presumably this is to do with your WAV player?, you don't want to run the processor at a slow clock speed - certainly at this slow a speed it wouldn't be able to play back your 11KHz samples at anywhere near real time.

You should run the processor as fast as you can, 4MHz should probably be enough, but 20MHz is good if you have a 20MHz processor. You set the playback speed by the time delay between sucessive writes to the D2A, not by crippling the processor.
 
It takes to 2 intruction cycles to output each sample. So i figured I needed an excetion rate that is twice that of the sample rate.
 
davepusey said:
It takes to 2 intruction cycles to output each sample. So i figured I needed an excetion rate that is twice that of the sample rate.

Unfortunately not true - it would take 2 instruction cycles to output a single sample - any more will take considerably longer. You've got to jump back to the start of the loop, read the data from where ever it's stored, updating the address counter at the same time - loads more than 2 instructions!.

As I mentioned before, it's not common practice to cripple your processor to try and reduce it's speed to match your requirements - you simply write your program to run at the speed you need. Whereas you can quite easily slow your program down (the vast majority of PIC time is spent simply wasting time!), you can't speed it up!.
 
Nigel Goodwin said:
davepusey said:
it would take 2 instruction cycles to output a single sample - any more will take considerably longer. You've got to jump back to the start of the loop, read the data from where ever it's stored, updating the address counter at the same time - loads more than 2 instructions!.

Not in my program (see attachment).
 

Attachments

  • program_snippet.zip
    15.3 KB · Views: 251
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top