Certainly :-)
First you need to set certain bits in the CONFIG registers - normally you do this in your compiler or programmer:
Primary oscillator modes are set with the FOSC 0:3 bits of the CONFIG1H register - with these bits you can choose to use the internal oscillator, and have RA6 and RA7 as general purpose IO or as a clock output.
Then you need to set bits in the OSCCON (Oscillator Control) register - you can set these bits at runtime in code.
The internal High Frequency oscillator runs at 16Mhz, so you want to select the HF internal oscillator and set bits 4,5 & 6 of OSCCON all to 1 to use it without a divisor.
See page 29 of the Data sheet for more details of the OSCCON register.
See page 41 of data sheet for a full description of all the registers involved in setting the oscillator speed and options.
Since these registers also contain bits for other functions, it's not possible for me to just say sat CONFIG1H to this and OSCCON to that in order to get 16 Mhz.
But the steps are:
Set CONFIG1H to select the internal HF oscillator
and then set bits 4,5 & 6 of OSCCON to 111 to select 16Mhz.
The other bits of these registers will need to be set in accordance with your other requirements.
The data sheet can be found here.
I hope this has helped.
Question, if the PIC has been set to 64Mhz and then you put this in main:
while(1)
{
PORTD=0xFF;
Nop();
Nop();
PORTD=0x00;
}
what is the port d frequency?, I am getting just under 4Mhz?
If I make FOSC=INTIO7, then I can see a 16Mhz squarewave (abeit a poor one) or RCA-6, is the HSPLL only for external crystals, or can it be set for the internal clock as well?
Also has anyone got an example of I2C communication?, I believe I am setting it up correctly, but if I try and send a byte, I can see diddly squat on the I2C pins (SCL for example).
Also is it possible to change the configuration bits implicitly, such as FOSC = 0b1001 (this does not work btw), rather than by assigned variable (INTIO67, INTIO7, HSPLL etc).
John.
Hi,
If the PIC has been set to 64Mhz then the PORTD frequency is about 2,6MHz (1/ (375 ns x 6 instruction)) or 1/(62,5e-9*6)= 2,6MHz
Do you no that PIC18F25K20 do not have PORTD ?
Arnauld