Today I started a project to try a few things with the PIC18F45K22. I had some timing problems with previously written code for other controllers. It turned out that there was something wrong with the clock frequency of the controller.
As the datasheet tells me, I should have a default clock frequency of 1MHz when using the internal oscillator. According to my oscilloscope I measured a clock frequency of 250kHz on the OSC2 (RA6) pin. So I started sniffing around in the datasheet and came across table 2-3 from the datasheet. This table says OSC2 pin will be 'Clock/4' when the controller is in SLEEP mode, which could be the source of my problem as 1MHz/4 = 250kHz. According to chapter 3.0 the controller will start with PRI_RUN mode when the device is reset, unless the Two-speed Start-up is enabled. So to be sure I disabled this mode by using the following configuration line:
#pragma config IESO = OFF
This line will disable the internal/external oscillator switchover bit, which will disable Two-speed Start-up according to paragraph 2.12.1.
Right now I tried multiple settings of the OSCCON, OSCCON2, OSCTUNE registers, which all failed. At this point I can't think of anything else what is causing this 'issue'. I hope someone will spot my error so I can run the device on the specified clock frequencies.
Currently I set these configuration bits:
#pragma config WDTEN = OFF
#pragma config FOSC = INTIO7 // Make clock visible on OSC2 pin
#pragma config LVP = OFF
#pragma config DEBUG = OFF
#pragma config IESO = OFF // Disable Two-speed Start-up
// Entry of application
int main(int argc, char** argv)
{
OSCCONbits.IRCF = 0b011; // default frequency
// Tried different OSCCON; OSCCON2; OSCTUNE settings, without succes
}
Datasheets(1): http://ww1.microchip.com/downloads/en/DeviceDoc/41412F.pdf