Swordfish Code Snippet - External Oscillator and PLL


The fastest a 16F PIC micro can run is 5 Million Instructions Per Second (MIPS), almost every 18F PIC micro can run at 10 MIPS, some more. Here's an extract from an 18F datasheet;

"The HSPLL mode makes use of the HS mode oscillator
for frequencies up to 10 MHz. A PLL then multiplies the
oscillator output frequency by 4 to produce an internal
clock frequency up to 40 MHz."

But how exactly to we enable this PLL feature so our PIC can run 4 times faster than usual? Its simple with a higher language Development suit like Swordfish,

Example PLL Usage
Device = 18F458
Clock = 40
Config OSC = HSPLL
// Start Of Program...


The above code is simply the start of the program. OSC = HSPLL enables the High Speed (HS) PLL feature, but there are some limitations to take into account.

Remember that the PIC usually executes an instruction once every 4 oscillator cycles, with PLL, it can be reduced t a 1:1, that is, one oscillation = 1 instruction. With this in mind, and the PIC's max speed (10 MIPS), the greatest external crystal that can be used is 10Mhz. If you compared the speed to a PIC running normally, it would be that of a PIC running with a 40Mhz crystal. That is why the Clock setting is declared as 40Mhz, allowing the compiler to generate the right delays etc when required.

Some 18F PIC's can operate at 48Mhz (12 MIPS), check the datasheet for more information about the PIC your using.

Forum Activity

Member Access