News:

Let's find out together what makes a PIC Tick!

Main Menu

XTAL value for low frequncies on 16LF1705

Started by kladogen, Nov 12, 2025, 01:05 PM

Previous topic - Next topic

kladogen

Hi, Im using 16LF1705 and I would like to know how I can declare the lower frequencies of the device. It supports 32MHz, 16MHz, 8MHz, 4MHz, 2MHz, 1MHz, 500KHz, 250KHz, 125KHz down to 31KHz.
However, when I try
declare Xtal 1 
for 1MHz I get the message "Crystal frequency 1MHz not supported with this device family".

Also I would like to know, If someone could help, the proper OSCCON value that I need to set for 1MHz. I have tried 01101000 for 4MHz with out success (since 4MHz is permiter by the compiler) but it does not work at all.

If I dont set the OSCCON the test program starts at default 500KHz and blinks a LED. I have a delay between on-off of 500ms and it takes about 4 secs - this is expected since I have declared the XTAL as 4MHz in order to compile but the real frequency is 500KHz - 8 times lower.

Thanks in advance,

Antonis


 

charliecoutas

Hi Antonis

I use this for a 16F1704 at 32Mhz. I don't know what is going wrong at your end but this might help:

Device = 16F1704                                   
                                                       
Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, LVP_OFF

   Declare Xtal=32                           

   Declare Adin_Tad = FRC                                               ;RC oscillator chosen for the ADC
   Declare Adin_Stime = 50                                              ;allow 50us sample time

   Dim wADC_Result      As Word                                         ;ADC value

   ANSELA = %00010000                                                   ;analogue input
   TRISA  = %00011000                                                   ;MCLRE is A3
   TRISC =  %00000000
       
        OSCCON = %11110000                                              ;PIC runs at 32Mhz with these settings                                                             
        OPTION_REG = %10000000                                          ;enable the pull-ups on PORTA


Charlie

trastikata

Hello,

on page 420 in the manual you can find the available frequency options which you can use in Positron.

The low frequency oscillator settings has been discussed several times on this boards.

Depending on what your code does, you can use the 4 MHz declaration and pro-rate some of the delays. For other functions that relay on declared frequency to calculate register settings, you will have to write your own code and set the registers.

kladogen

Thank you for the tip. In that case I will declare 4Mhz, set the frequency to 1Mhz and divide delays by 4.
However, at some point I need to use the serial port, so maybe I can temporarily increase the frequency to 4Mhz while using the serial port and then decrease it again to 1Mhz?

Thanks again,

Antonis

RGV250

#4
Hi,
Quoteso maybe I can temporarily increase the frequency to 4Mhz while using the serial port and then decrease it again to 1Mhz?
No, I have never done it but what you need to do is set the registers like these
Quote;Calculated Baudrate = 9615 @ Xtal 4MHz, Error = 0.16%
        Declare Hserial_RCSTA = 144 ; Enable continuous receive
        Declare Hserial_TXSTA = 36  ; Enable transmit, BRGH = 1
        Declare Hserial_SPBRG = 25  ; Baud Rate Generator Value
        Declare Hserial_Clear = On  ; Clear overflow automatically
There used to be several calculators which others might point to that will help. Just use the actual xtal you are using.
A quick google fo PIC serial calculator came up with this. https://www.nicksoft.org/el/calc/?ac=spbrg&submitted=1&mcu=PIC16F1829&Fosc=4&FoscMul=1000000&FoscAutoSelector=0&MaxBaudRateError=1


Regards,
Bob

Stephen Moss

Quote from: kladogen on Nov 12, 2025, 01:05 PMAlso I would like to know, If someone could help, the proper OSCCON value that I need to set for 1MHz.
If you want to use the configuration fuses to select the clock source (shipping default) you need to select the IntOsc option for the internal Oscillator.
The value needed for the OSCCON register would then be 0101 1000.
However if you want to ignore the Config fuse setting for the Oscillator source selection the value required for the would be 0101 101x where X can be 1 or 0 to set the internal Oscillator as the clock source.

Quote from: kladogen on Nov 12, 2025, 01:05 PMI have tried 01101000 for 4MHz with out success (since 4MHz is permiter by the compiler) but it does not work at all.
The value looks right, are you sure you had the Internal Oscillator selected as the clock source in the config fuses?

Quote from: kladogen on Nov 13, 2025, 07:50 AMHowever, at some point I need to use the serial port, so maybe I can temporarily increase the frequency to 4Mhz while using the serial port and then decrease it again to 1Mhz?
That should be possible, the easiest way would be to write the applicable value to the OSCCON register to select the different frequencies from the internal oscillator.
Alternatively, it looks like you could enable the PLL, pass the 1MHz output from the internal oscillator to it and then use the PLLMUX bits to select between using the 1MHz PLL input or the 4MHz PLL output, but that is a lot more messing about than just selecting a new internal oscillator frequency.

The big question is, that if you will need to run the PIC at 4MHz for the serial port, why can you not simply keep it running at 4MHz all the time?   


kladogen

I have just tried changing the frequency when the serial port is needed and it seems to work fine. I will make more tests in the following days.