PIC18F45K50 – Timer Oscillator Help

Thread Starter


Joined Mar 10, 2016
As a newbie I’ve managed to get multiple timers and Interrupts working flashing LED at different rates (all be it with hap hazard timing so far). Thanks to John for the pointers.

I'm currently writing up my learning pitfalls and currently cleaning my working code, happy to post them if anyone would like my examples, not perfect but better then I've been able to find.

Timers and OSC's :-
I’m trying to understand Oscillators and Timers in more detail. I’ve read the data sheets, I’ve read their various programing docs, I looked at examples (you can never find what you need, :) ) but I’m not understanding the Oscillators relationship with the timers.

I know I’m being dumb, but, the docs say INTOSC is 16Mhz and INTRC is 32kHz, and that timer 1 and 3 I think it was are linked. Looking at the Logic diagrams left me unsure. I’m beginning to think I can only set 1 Oscillator which effect all Timers, but other parts of the doc talk about T1 and T3 only being effected? I know I can play with this.

I would just like to understand a little bit more and a few pointers before spending hours getting it wrong.

So may I ask a few questions, and then I can go and re-read.

Background :-
Once my skills have improved, my long term project needs to read a slow changing SQ Wave (0hz to 400hz, and create 2 different (SQ Wave) output (PWM signals?) which are in the same range but slightly different to the input, but both varying and drive from the input with various corrections.

Thus I’m thinking 32kHz timer would save lots of extra divide routines.

Questions :-
  1. If I set the Oscillators via INTRC to 32kHz, It looks like it will effects all Timers, does it?
  2. I assume the CPU core speed is not effected?
  3. Can the various timers be set to different Oscillators?
  4. Given my Long term project and I using the wrong functionality, i.e. Interrupts to read and timers to write the new SQ Wave
    1. I’ve also read somewhere you can capture a signal into a timer, but I’m still thinking my interrupt capture is better, not sure why yet
    2. The 2 SQ Ware outputs need to be autonomous with the main code as other functions will be running adjusting their output
    3. On one test when I switched timer0 of if seemed to switch time 3 off, the question is are there dependency's between timers ?
Thanks you in advance
Regards Geoff.
After 25yrs plus off writing Corporate Business Applications and Database's, this is so much more fun :)
Last edited:


Joined Sep 13, 2015
Generally, you will need to look at the oscillator section to see how the clock tree works and which clock is picked to drive the CPU and peripherals.

As to timers, you will need to look at their respective block diaghram to see how to select different clock sources.

On the wave generation, it can be done in software or hardware (through output compare or pwm).
Last edited:


Joined Jul 18, 2013
Also there are pre and post scalers for timers that can be used for changing the timing rate.
TMR1 also has 32khz capability via the SOSCO - SOSCI input.


Joined Dec 2, 2013
Hi, Pic has in fact 3 clock sources
a;internal(up to 8MHz selectable in a register).
b:external xtal up to 40MHz. ( xtal or generator)
c: external 32 KHz ( xtal or generator).

When 32Khz is activated it will run regardless the others (a / b)
This allows you the catch interrupt when the unit is in sleep and allows you to run a clock/calendar.
When an interrupt occurs the pic can activate a or b and the system comes to speed.
The main clock then is a or b while c is still running.
be aware that two cycles are needed that implies that the working clock is maximum 1/2 a or 1/2 b.
A divers are put in place to divide this clock even more.

Timers are derived from the clock here you will find the relation between them.
Timers have a presentable counter allowing you to give an overflow interrupt in a few counts hence short time.
( look at the PIC example 'clock in sleep mode' this will explain most of your questions)

It is not difficult the best thing to do is play with it make an output like out=!out; and observe the signal and it timing.