I'm currently using PIC MCU clock with 4MHz Crystal Oscillator and I have set the frequency to 32MHz using PLL.
Can someone guide me on how to calculate the timing for executing 1 instruction. Should I use the 4MHz or 32MHz to calculate for the time of each instruction.
Assuming that your using a third of 96MHz to obtain 32MHz then each instruction cycle is 1/(32,000,000/4) = 125nS. Be aware that some instructions can be 2 or 3 cycles long.
Assuming that your using a third of 96MHz to obtain 32MHz then each instruction cycle is 1/(32,000,000/4) = 125nS. Be aware that some instructions can be 2 or 3 cycles long.
Sorry Sky,
I couldn't see why you was referring to a 4Mhz xtal. Mike's formula is right. (unless the instruction requires more than 1 cycle to complete as Mike said) ie base it on 32Mhz/4
Another way to see how many cycles are used by your code is to use the "Simulator trace" in the view options of MPLAB.
You can then step through some code and see the cumulative number of cycles used.
If you right click in the trace window, you can then change the option to display the time in hex,decimal cycle count or seconds elapsed etc.
Sorry Sky,
I couldn't see why you was referring to a 4Mhz xtal. Mike's formula is right. (unless the instruction requires more than 1 cycle to complete as Mike said) ie base it on 32Mhz/4
I know Mikes formula was correct but what I mean was, I used a 4MHz xtal to clock my microcontroller, but in the software part, I set the internal osc to 8MHz than followed by using the PLL to make it to 32MHz.
Also, I understand that some instruction may take more than 1 cycle to execute.
So my instruction calculation is based on the final 32MHz that i have set or based on the 4MHz xtal.
I suppose each instruction executing timing is using the 4MHz and the 32MHz that I have set is for Timer. Can anyone correct me if I made mistakes?
Its like Boomslang said, you can't use both external crystal AND Internal oscillator. Use INTIO67 to enable the internal oscillator, and then the pins that your xtal were connected to, can be used as a couple of extra I/O..
so... now your are set as Boomslang said, your calculation is based on 4mhz (internal osc) with osctune cleared(0) or 16mhz with osctune set (1)
Personally, I rarely used xtals, unless really necessary
I'm sorry to ask, but with is the PPL and for what is usefull? As I read, means that the MCU can achive highers speeds activating the PPL to multiply the normal OSC freq?
PLL (not PPL) is a 4x clock multiplier that can be used to achieve a higher clock speed when using the internal oscillator ie 4 x 8= 32Mhz. It can be configured by your software to run at slower speeds, and speed up when needed. This would be useful in a portable situation, to save power..
Its like Boomslang said, you can't use both external crystal AND Internal oscillator. Use INTIO67 to enable the internal oscillator, and then the pins that your xtal were connected to, can be used as a couple of extra I/O..
so... now your are set as Boomslang said, your calculation is based on 4mhz (internal osc) with osctune cleared(0) or 16mhz with osctune set (1)
Personally, I rarely used xtals, unless really necessary
I'm sorry to ask, but with is the PPL and for what is usefull? As I read, means that the MCU can achive highers speeds activating the PPL to multiply the normal OSC freq?
PLL will multiply your internal oscillator by 4 times where you can achieve a higher clock speed. You have to configure the PLL by software. I have the C version on how to configure it 2 post ago.
If you don't know what it is, then you don't require it!.
Essentially it's used to give 40MHz from a 10MHz crystal, but it can be used for any lower frequencies as well. You can't buy 40MHz crystals, so it's easier to multiply a 10MHz.