News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

12F1840 PLL problem

Started by See_Mos, May 03, 2026, 04:13 PM

Previous topic - Next topic

See_Mos

Les has provided a template 12F1840 32MHz.inc

A problem that I came across a long time ago is that the timing was all wrong so I added an LED toggled at 10mS to give 50Hz output which is an easy timing comparison using the oscilloscope.

According to the data sheet Les' template is correct.  With PLLEN_ON :-

Proc Osc_32MHz()
    OSCCON = %11110010                                              ' Enable the 4xPLL so the device operates at 32MHz with its internal oscillator
    OSCTUNE = $00
    BORCON = $00
EndProc

But the only way that I can get the PLL to work is if I change OSCON to %11110000 and I cannot find out why.

Any ideas please?

Pepe

5.2.1.4 4X PLL
The oscillator module contains a 4X PLL that can be used with both external and internal clock sources to provide a system clock source. The input frequency for the 4X PLL must fall within specifications. See the PLL Clock Timing Specifications in Section30.0 "Electrical Specifications". The 4X PLL may be enabled for use by one of two methods:
1. Program the PLLEN bit in Configuration Word 2 to a '1'.
2. Write the SPLLEN bit in the OSCCON register to a '1'. If the PLLEN bit in Configuration Word 2 is programmed to a '1', then the value of SPLLEN is ignored.

JackB

#2
Device = 12F1840
Declare Xtal = 32     

OSCCON = $70  ' = %01110000

Config1 FOSC_INTOSC , WDTE_OFF , PWRTE_OFF , MCLRE_OFF , CP_OFF , CPD_OFF , BOREN_OFF
Config2 WRT_OFF , PLLEN_ON , LVP_OFF

Let us know if it's working

See_Mos

Thanks, I am still confused as to why Les' code didn't work.

I will have to come back to this later as the project is working perfectly at 16MHz

ChrisRowe

From the datasheet section 5.2.2.6..
The 4x PLL is not available for use with the internal
oscillator when the SCS bits of the OSCCON register
are set to '1x'. The SCS bits must be set to '00' to use
the 4x PLL with the internal oscillator


See_Mos

Thanks Chris.

It would have made more sense if they described it by example.

Stephen Moss

Quote from: See_Mos on May 06, 2026, 02:53 PMThanks Chris.

It would have made more sense if they described it by example.
They could have put a note on the OSCON register page to indicate you need to have the SCS bits set to 00 for the 32MHz option to make it clearer for those familiar with PIC's who may have chosen to skip the blurb (as you do) and go straight the the OSCON register, as logically you can see why someone who has only looked at the at the OSCON register would expect that if they use that register to select the internal oscillator running at 8MHz and enable the PLL as in posted code that would result in clocking the core at 32MHz.
Which is why looking the the posted OSCCON settings I was also initially thinking that should work.

Figure 5.1 on page 39 of the data sheet gives a little more clarity as to why it does not. If you select the internal Oscillator, the processor clock source is taken from the output of the internal Oscillator multiplexer as set by the IRCF bits, however the PLL output is not routed via that multiplexer which is why the code example (presumably) results in the PIC operating at 8MHz rather than 32MHz and thus the need to select HFINTSOC as the clock source (to set it as the PLL input) via the Config fuses.