News:

;) This forum is the property of Proton software developers

Main Menu

Pic 16F1825 internal oscillator

Started by Yves, Apr 28, 2025, 09:48 AM

Previous topic - Next topic

Yves

Hello everyone,
I have an issue with a 16F1825 timing setup. I'm using its internal oscillator and to test its timing I toggle a LED every seconds but my LED is toggling to about every 46 seconds (just counting the seconds in my head). See below the test  code:

;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

   Device = 16F1825
        Declare Xtal = 32
   Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, CPD_OFF, BOREN_ON, CLKOUTEN_OFF, IESO_ON,
        FCMEN_ON
   Config2 WRT_OFF, PLLEN_ON, STVREN_ON,LVP_OFF

;**** End of Fuse Configurator Settings ****
While
 Toggle LED
 DelayMS 1000
 Wend
While
end


Not sure what I'm doing wrong

Yves


Yves

RGV250

Hi,
Is that the actual code you are using as it does not compile with several errors.

Regards,
Bob

RGV250

Hi,
Look at OSCON (section 5.6 in datasheet), as you have not set the IRCF bits I think it is using 0111 which is the default 500khz.
Quotebit 6-3 IRCF<3:0>: Internal Oscillator Frequency Select bits
000x = 31 kHz LF
0010 = 31.25 kHz MF
0011 = 31.25 kHz HF(1)
0100 = 62.5 kHz MF
0101 = 125 kHz MF
0110 = 250 kHz MF
0111 = 500 kHz MF (default upon Reset)
1000 = 125 kHz HF(1)
1001 = 250 kHz HF(1)
1010 = 500 kHz HF(1)
1011 = 1 MHz HF
1100 = 2 MHz HF
1101 = 4 MHz HF
1110 = 8 MHz or 32 MHz HF(see Section 5.2.2.1 "HFINTOSC")
1111 = 16 MHz HF

Bob

Yves

Thank you Bob, but please kindly indicate how do I set it in my configuration?
Yves

RGV250

Hi,
I do not use those devices and mostly use external osc so this is a guess but I think you need to add OSCCON = %11110000
after your config settings.
The main bits are 6-3 1110, see list in earlier post, bit 7 is not important as you have PLLEN_ON in your config settings.

Bob

Yves

Thank you Bob that works for me. Sorry for my ignorance.

Regards,

Yves
Yves

top204

Try the code template below for the PIC16F1825 device:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Internal Oscillator operating at 32MHz with its internal oscillator template for a PIC16F1825 device.
' Written by Les Johnson for the Positron8 BASIC Compiler.
'
    Device = 16F1825                                                ' Tell the compiler what device to compile for
    Declare Xtal = 32                                               ' Tell the compiler what frequency the device is operating at (in MHz)
    Declare Auto_Heap_Strings = On                                  ' Make all Strings "Heap" types, so they always get placed after standard variables
'
' Setup USART1
'
    Declare Hserial_Baud = 9600                                     ' Set the Baud rate for USART1
    Declare HRSOut1_Pin  = PORTC.4                                  ' Tell the compiler to setup pin PORTC.4 for USART1 Tx
    Declare HRSIn1_Pin   = PORTC.5                                  ' Tell the compiler to setup pin PORTC.5 for USART1 Rx

'------------------------------------------------------------------------------------------
' The main program starts here
'
Main:
    Setup()                                                         ' Setup the program and any peripherals

    Do

    Loop

'------------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Outout    : None
' Notes     : None
'
Proc Setup()
    Osc_Init()                                                      ' Initialise the oscillator on a PIC16F1825 device
'
' More setups here when required
'
EndProc

'------------------------------------------------------------------------------------------
' Initialise the oscillator on a PIC16F1825 device
' Input     : None
' Outout    : None
' Notes     : For internal oscillator
'
Proc Osc_Init()
    OSCCON = %01110000
    OSCTUNE = 0
    BORCON = 0
    DelayMs 100
EndProc

'------------------------------------------------------------------------------------------
' Setup the config fuses for an internal oscillator on a PIC16F1825 device
' OSC pins are general purpose I/O lines

    Config1 FOSC_INTOSC,_                                           ' INTOSC oscillator. I/O function on CLKIN pin
            WDTE_OFF,_                                              ' Watchdog Timer disabled
            PWRTE_OFF,_                                             ' Power-up Timer disabled
            MCLRE_ON,_                                              ' MCLR Pin function is MCLR
            CP_OFF,_                                                ' Flash Program memory code protection is disabled
            CPD_OFF,_                                               ' EEPROM protection is disabled
            BOREN_ON,_                                              ' Brown-out Reset enabled
            CLKOUTEN_OFF,_                                          ' CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
            IESO_ON,_                                               ' Internal/External Switchover mode is enabled
            FCMEN_ON                                                ' Fail-Safe Clock Monitor is enabled

    Config2 WRT_OFF,_                                               ' Flash Memory Self-Write protection off
            PLLEN_ON,_                                              ' 4xPLL enabled
            STVREN_ON,_                                             ' Stack Overflow or Underflow will cause a reset
            BORV_19,_                                               ' Brown-out reset voltage
            LVP_OFF                                                 ' High-voltage on MCLR/VPP must be used for programming


RGV250

QuoteSorry for my ignorance.
It is not a problem, we all have to ask sometimes. Even though it is not a device I use it is good for my brain cell to look through datasheets, even better when I can help :) 
Imagine how bad we will all get if we all relied on AI, I did read somewhere that relying on AI is making us dumber.

Bob