News:

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

Main Menu

18F14Q40 Configuration issue

Started by okmn, May 22, 2024, 07:47 AM

Previous topic - Next topic

okmn

  Now I'm fighting another nonsense,
  The hero of this nonsense is 18F14Q40

i want just simple blink again  but i could not find  where am i making wrong!

"yes" to any coding help.

Device 18F14Q40
Declare Xtal = 64
Declare Optimiser_Level = 3
Config_Start
FEXTOSC = OFF      ' External Oscillator Mode Selection->Oscillator not enabled
RSTOSC = HFINTOSC_64MHZ      ' Power-up Default Value For COSC->HFINTOSC with HFFRQ = 64 MHz And CDIV = 1:1

FCMENP = OFF      ' Fail-Safe Clock Monitor Enable - Primary Xtal Enable->Fail-Safe Clock Monitor enabled; timer will flag FSCMP bit and OSFIF interrupt on EXTOSC failure.
CLKOUTEN = OFF      ' Clock Out Enable->CLKOUT function is disabled
FCMEN = OFF      ' Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor disabled
CSWEN = On      ' Clock Switch Enable->Writing To NOSC And NDIV is allowed
FCMENS = OFF      ' Fail-Safe Clock Monitor Enable - Secondary Xtal Enable->Fail-Safe Clock Monitor Disabled
PR1WAY = On      ' PRLOCKED One-Way Set Enable->PRLOCKED Bit can be cleared And Set only once

MVECEN = On      ' Multivector Enable->Multi-vector enabled, Vector table used For interrupts
MCLRE = EXTMCLR      ' Master Clear (MCLR) Enable->If LVP = 0, MCLR Pin is MCLR; If LVP = 1, RE3 pin function is MCLR
BOREN = OFF      ' Brown-out Reset Enable->Brown-out Reset disabled
PWRTS = PWRT_OFF      ' Power-up Timer Selection->PWRT is disabled
IVT1WAY = On      ' IVTLOCK One-Way Set Enable->IVTLOCKED Bit can be cleared And Set only once
LPBOREN = OFF      ' Low-Power BOR Enable->Low-Power BOR disabled

XINST = OFF      ' Extended Instruction Set Enable->Extended Instruction Set And Indexed Addressing Mode disabled
LVP = On      ' Low-Voltage Programming Enable->Low voltage programming enabled. MCLR/VPP Pin function is MCLR. MCLRE configuration Bit is ignored
ZCD = OFF      ' ZCD Disable->ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN Bit of ZCDCON
STVREN = On      ' Stack Overflow/Underflow Reset Enable->Stack full/underflow will cause Reset
BORV = VBOR_1P9      ' Brown-out Reset Voltage Selection->Brown-out Reset Voltage (VBOR) Set To 1.9V
PPS1WAY = On      ' PPSLOCKED One-Way Set Enable->PPSLOCKED Bit can be cleared And Set only once; PPS registers remain locked after one clear/set cycle

WDTCPS = WDTCPS_31      ' WDT Period Select->Divider ratio 1:65536; software control of WDTPS
WDTE = OFF      ' WDT Operating Mode->WDT Disabled; SWDTEN is ignored

WDTCWS = WDTCWS_7      ' WDT Window Select->window always open (100%); software control; keyed access not required
WDTCCS = SC      ' WDT Input Clock Selector->Software Control

SAFEN = OFF      ' Storage Area Flash (SAF) Enable->SAF disabled
BBEN = OFF      ' Boot Block Enable->Boot block disabled
BBSIZE = BBSIZE_512      ' Boot Block Size Selection->Boot Block size is 512 words

WRTB = OFF      ' Boot Block Write Protection->Boot Block not Write protected
WRTC = OFF      ' Configuration Register Write Protection->Configuration registers not Write protected
WRTD = OFF      ' Data EEPROM Write Protection->Data EEPROM not Write protected
WRTAPP = OFF      ' Application Block Write Protection->Application Block not write protected
WRTSAF = OFF      ' Storage Area Flash (SAF) Write Protection->SAF not Write Protected

Cp = On      ' User Program Flash Memory And Data EEPROM Code Protection->PFM And Data EEPROM Code protection enabled
Config_End
OSCCON1 = $62
OSCCON2 = $60
OSCCON3 = 0
OSCEN = 0
OSCFRQ = 8
OSCTUNE = 0
ACTCON = 0
While OSCSTATbits_PLLR = 0
Wend

LATA = 0
LATB = 0
LATC = 0

TRISA = $20
TRISB = 0
TRISC = $1C

ANSELA = 0
ANSELB = 0
ANSELC = 0
WPUA = $20
WPUB = 0
WPUC = 0

ODCONA = 0
ODCONB = 0
ODCONC = 0

SLRCONA = $37
SLRCONB = $F0
SLRCONC = $FF

INLVLA = $3F
INLVLB = $F0
INLVLC = $FF
RB4I2C = 0
RB6I2C = 0
IOCAP = 0
IOCAN = 0
IOCAF = 0
IOCBP = 0
IOCBN = 0
IOCBF = 0
IOCCP = 0
IOCCN = $10
IOCCF = 0
IOCCFbits_IOCCF4 = 0
INTCON0bits_GIE = 0

Symbol Blink_Led_1 = PORTC.0
Symbol Blink_Led_2 = PORTA.2
Symbol Switch = PORTA.5
Do

    Toggle Blink_Led_1
    DelayMS 500
    Toggle Blink_Led_2
    DelayMS 500

Loop


the video showing running code produce by Mplab XC8



Frizie

What happens if you don't use TOGGLE but actually switch the ports with HIGH and LOW.
As far as I know, the TOGGLE instruction reads the PORT and then controls the PORT inversely.
But if the PORT is slightly overloaded, the same level is always assumed.

So try:

DO
  HIGH PORTC
.0
  DELAYMS 500
  HIGH PORTA.2
  DELAYMS 500
  LOW  PORTC.0
  DELAYMS 500
  LOW  PORTA.2
  DELAYMS 500
LOOP

Ohm sweet Ohm | www.picbasic.nl

top204

There were a few things incorrect in your code listing.

The While-Wend loop after the oscillator SFR settings will never exit because that is waiting for the PLL to become stable, but the internal 64MHz oscillator does not use the PLL peripheral the same as if it is enabled by the program (RSTOSC = HFINTOSC_64MHZ). The SFR settings were also set for a different fuse setting and enabling the PLL, so this would interfere with the HFINTOSC_64MHZ fuse and timings would be incorrect if the While-Wend were replaced with a simple delay to allow the oscillator to become stable before the main program starts. For the waiting loop for the PLL and the frequency altered using SFRs, the RSTOSC fuse needs to be set as: HFINTOSC_1MHZ.

With the HFINTOSC_64MHZ fuse setting, no SFR manipulation is required for the device's frequency. It will automatically operate at 64MHz on power-up.

Also, in the fuse settings the vectored interrupt was enabled and PPS single use lock and some other single use locks were enabled, so a program would not be able to alter them, and interrupts would not work at all because the compiler does not use vectored interrupts.

Below is a tested and working program to operate a PIC18F14Q40 device using its internal 64MHz oscillator, and flashing LEDs at the correct speed:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A working demo of a PIC18F14Q40 device flashing LEDs using its internal 64MHz oscillator.
' Written by Les Johnson for the Positron8 compiler.
'
    Device 18F14Q40                         ' Tell the compiler what device to compile for
    Declare Xtal = 64                       ' Tell the compiler what frequency the device is operating at
    Declare Optimiser_Level = 3             ' Set the highest level of optimisation (not recommended until normal optimisation proves the code runs correctly)
'
' Setup some pin alias names
'
    Symbol Blink_LED_1 = PORTC.0
    Symbol Blink_LED_2 = PORTA.0
    Symbol Switch_Pin = PORTA.5

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

    Do
        Toggle Blink_LED_1
        DelayMS 500
        Toggle Blink_LED_2
        DelayMS 500
    Loop

'-----------------------------------------------------------------------------------------------------
' Setup the program and peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    PinLow Blink_LED_1
    PinLow Blink_LED_2
    PinMode Switch_Pin, Input_PullUp        ' Set the switch pin as an input with the pin's internal pull-up resistor enabled
EndProc

'-----------------------------------------------------------------------------------------------------
' Setup the config fuses for internal oscillator at 64MHz, with OSC pins as I/O lines.
' For PIC18F14Q40 and PIC18F05Q41 devices, and most other 18FxxQ4x devices.
'
Config_Start
    FEXTOSC = Off                           ' External Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ                 ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    CLKOUTEN = Off                          ' CLKOUT function is disabled
    PR1WAY = Off                            ' PRLOCKED bit can be set and cleared repeatedly
    CSWEN = On                              ' Writing to NOSC and NDIV is allowed
    FCMEN = On                              ' Fail-Safe Clock Monitor enabled
    FCMENP = On                             ' Fail-Safe Clock Monitor enabled.
    FCMENS = On                             ' Fail-Safe Clock Monitor enabled.
    MCLRE = EXTMCLR                         ' MCLR pin is MCLR
    PWRTS = PWRT_OFF                        ' PWRT is disabled
    MVECEN = Off                            ' Interrupt controller does not use vector table to prioritise interrupts
    IVT1WAY = On                            ' IVTLOCKED bit can be cleared and set only once
    LPBOREN = On                            ' Low-Power BOR enabled
    BOREN = On                              ' Brown-out Reset enabled according to SBOREN
    BORV = VBOR_1P9                         ' Brown-out Reset Voltage (VBOR) set to 1.9V
    ZCD = Off                               ' ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off                           ' PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = On                             ' Stack full/underflow will cause Reset
    LVP = Off                               ' HV on MCLR/VPP must be used for programming
    XINST = Off                             ' Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCPS = WDTCPS_17                      ' WDT Period Divider ratio 1:4194304
    WDTE = Off                              ' WDT disabled
    WDTCWS = WDTCWS_7                       ' WDT window always open (100%)
    WDTCCS = SC                             ' WDT input clock Software Control
    BBSIZE = BBSIZE_512                     ' Boot Block size is 512 words
    BBEN = Off                              ' Boot block disabled
    SAFEN = Off                             ' SAF disabled
    Debug = Off                             ' Background Debugger disabled
    WRTB = Off                              ' Boot Block not Write protected
    WRTC = Off                              ' Configuration registers not Write protected
    WRTD = Off                              ' Data EEPROM not Write protected
    WRTSAF = Off                            ' SAF not Write Protected
    WRTAPP = Off                            ' Application Block not write protected
    Cp = Off                                ' PFM and Data EEPROM code protection disabled
Config_End

Also, all your original code that was copied and adapted from the MPLABX IDE is just not needed in the vast majority of programs, and the Positron compilers set pins to digital mode before a user's program starts. All of those SFR settings produced by the MPLABX MCC plugin actually creates a huge amount of wasted code, and can cause problems themselves. The MCC plugin comes in handy sometimes, but not just used "as-is". :-)

One good thing about the newer 18FxxQ4x devices is that they appear to have a standard for their peripherals and SFRs, so code for one should work on another, within limits.

They are new devices with some new, and quear, features, but after time they will become really nice devices to use. However, never take what the MCC plugin spits out too literally. It is microchip after all ! And it is paid third parties who probably do not actually use the devices, that are creating the code generation. So what is good on paper, does not always work in the real world unless you use it practically and understand it fully, as my dad always used to tell me. :-)

tnencon

#3
Hello friends;
I want to run Timer0 interrupt with PIC18F14Q40. I made the timer0 settings as follows, so that there is an interrupt every 100uS.
T0CON0 = $93 (16 bit, Prescaler: 16, Postscaler: 4, clock source:Fosc/4)
T0CON1 = $44
TMR0H = $FF
TMR0L = $E7
However, the interrupt occurs approximately every 200mS, instead of every 100uS.
The crystal frequency is internally set to 64MHz.
t= Prescaler*Postscaler*(65536-65511)/(Fosc/4)
I calculated it with the formula.
What is the point I missed? I would appreciate it if you could help me.
(After solving this problem, I want to experiment with Timer2 interrupt.)

tnencon

Quote from: tnencon on Jul 27, 2024, 12:53 PMHello friends;
I want to run Timer0 interrupt with PIC18F14Q40. I made the timer0 settings as follows, so that there is an interrupt every 100uS.
T0CON0 = $93 (16 bit, Prescaler: 16, Postscaler: 4, clock source:Fosc/4)
T0CON1 = $44
TMR0H = $FF
TMR0L = $E7
However, the interrupt occurs approximately every 200mS, instead of every 100uS.
The crystal frequency is internally set to 64MHz.
t= Prescaler*Postscaler*(65536-65511)/(Fosc/4)
I calculated it with the formula.
What is the point I missed? I would appreciate it if you could help me.
(After solving this problem, I want to experiment with Timer2 interrupt.)
When I define Timer0 as 8-Bit and not 16-Bit, it works fine. In this situation
'16-Bit
' TMR0H = $FF
' TMR0L = $E7
'8-Bit
    TMR0H = $18
    TMR0L = 0
'T0OUTPS 1:4; T0EN enabled; T016BIT 16-bit;
'T0CON0 = $93
'T0OUTPS 1:4; T0EN enabled; T016BIT 8-bit;
T0CON0 = $83
should be set as .
But why does it work correctly when we set it to 8-bit, but not when we set it to 16-bit?

top204

In past projects I've used Timer0 operating in 16-bit mode on a PIC18F05Q41 device and it works well.

The smaller Q devices seem to match each other, for now, with SFRs, and the demonstration template code listing I have just created below compiles correctly, so it should work on a PIC18F14Q40 device.

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Timer0 routines for a PIC18F14Q40 device.
' Written by Les Johnson for the Positron8 compiler.
'
    Device = 18F14Q40                                               ' Tell the compiler what device to compile for
    Declare Xtal = 64                                               ' Tell the compiler what frequency the device is operating at (in MHz)
    On_Hardware_Interrupt Goto ISR_Handler                          ' Point the compiler to the interrupt handler
'
' Setup USART1
'
    Declare Hserial1_Baud = 9600
    Declare HRSOut1_Pin   = PORTC.4
'
' Timer0 meta-macros to make the code easier to read and use
'
$define Timer0_Flag() PIR3bits_TMR0IF                               ' Timer0 flag
$define Timer0_FlagClear()  Timer0_Flag() = 0                       ' Clear the Timer0 flag
$define Timer0_IntEnable()  PIE3bits_TMR0IE = 1                     ' Enable a Timer0 interrupt
$define Timer0_IntDisable() PIE3bits_TMR0IE = 0                     ' Disable a Timer0 interrupt
$define Timer0_Start() T0CON0bits_T0EN = 1                          ' Start Timer0
$define Timer0_Stop()  T0CON0bits_T0EN = 0                          ' Stop Timer0

$define Periph_IntEnable()  INTCON0bits_GIEL = 1                    ' Enable peripheral interrupts
$define Periph_IntDisable() INTCON0bits_GIEL = 0                    ' Disable peripheral interrupts
$define Global_IntEnable()  INTCON0bits_GIE = 1                     ' Enable global interrupts
$define Global_IntDisable() INTCON0bits_GIE = 0                     ' Disable global interrupts
'
' Create any Global variables here
'
    Dim wTimer0ReloadVal As Word Heap                               ' Holds the Timer0 reload value for the interrupt handler
    Dim wTimer0_SFR As TMR0L.Word                                   ' Create a 16-bit SFR from TMR0L\H

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

'-------------------------------------------------------------------------------------------------
' Setup the program's variables, and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Timer0_Init_100us()                                             ' Setup Timer0 for an overflow every 100us with a 64MHz oscillator
    Periph_IntEnable()                                              ' Enable peripheral interrupts (not needed for a Timer0 interrupt, but better safe than sorry)
    Global_IntEnable()                                              ' Enable global interrupts
EndProc

'-------------------------------------------------------------------------------------------------
' Setup Timer0 for an overflow every 100us with a 64MHz oscillator
' Input     : None
' Output    : None
' Notes     : None
'
Proc Timer0_Init_100us()
    T0CON1 = %01000000                                              ' Timer0 uses FOSC/4. Prescaler is 1:1. Set for not synchronised
    wTimer0_SFR = $F9C0                                             ' Set Timer0 for a 100us overflow at 64MHz device operation
    wTimer0ReloadVal = wTimer0_SFR                                  ' Load the 16-bit TMR0L\H values to the 16-bit reload variable
    Timer0_FlagClear()                                              ' Clear the Timer0 interrupt flag
    Timer0_IntEnable()                                              ' Enable a Timer0 interrupt
    T0CON0 = %10010000                                              ' Postscaler is 1:1. Timer0 enabled and set for 16-bit mode
EndProc

'-------------------------------------------------------------------------------------------------
' Read the 16-bit Timer0 registers value
' Input     : None
' Output    : Returns the 16-bit Timer0 value
' Notes     : None
'
Proc Timer0_Read(), Word
    Result.Byte0 = TMR0L
    Result.Byte1 = TMR0H
EndProc

'--------------------------------------------------------------------------
' Write 16-bits to the Timer0 registers
' Input     : pTimerVal holds the 16-bit value to write to Timer0
' Output    : None
' Notes     : None
'
Proc Timer0_Write16(pTimerVal As Word)
    TMR0H = pTimerVal.Byte1
    TMR0L = pTimerVal.Byte0
EndProc

'-------------------------------------------------------------------------------------------------
' Interrupt Handler
' Input     : None
' Output    : None
' Notes     : Interrupts on a Timer0 overflow
'
ISR_Handler:
    Context Save                                                    ' Save any compiler system variables and certain SFRs used within the interrupt handler
    If Timer0_Flag() = 1 Then                                       ' Was it a Timer0 overflow that triggered the interrupt?
        '
        ' Yes. So code goes here for the Timer0 interrupt
        '
        wTimer0_SFR = wTimer0ReloadVal                              ' Load TMR0L\H with the reload value for the duration required
        Timer0_FlagClear()                                          ' Clear the Timer0 flag
    EndIf
    Context Restore                                                 ' Restore any compiler system variables and SFRs used within the interrupt handler, and exit the interrupt

'-------------------------------------------------------------------------------------------------
' Setup the config fuses for internal oscillator at 64MHz, with OSC pins as I/O
' For a PIC18F14Q40 device
'
Config_Start
    FEXTOSC = Off                           ' External Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ                 ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1

    CLKOUTEN = Off                          ' CLKOUT function is disabled
    PR1WAY = Off                            ' PRLOCKED bit can be set and cleared repeatedly
    CSWEN = On                              ' Writing to NOSC and NDIV is allowed
    FCMEN = Off                             ' Fail-Safe Clock Monitor disabled
    FCMENP = Off                            ' Fail-Safe Clock Monitor will not flag FSCMP bit and OSFIF interrupt on EXTOSC failure
    FCMENS = Off                            ' Fail-Safe Clock Monitor will not flag FSCMP bit and OSFIF interrupt on SOSC failure

    MCLRE = EXTMCLR                         ' MCLR pin is MCLR
    PWRTS = PWRT_OFF                        ' PWRT is disabled
    MVECEN = Off                            ' Interrupt controller does not use vector table
    IVT1WAY = On                            ' IVTLOCKED bit can be cleared and set only once
    LPBOREN = On                            ' Low-Power BOR enabled
    BOREN = On                              ' Brown-Out Reset enabled according to SBOREN

    BORV = VBOR_1P9                         ' Brown-out Reset Voltage (VBOR) set to 1.9V
    ZCD = Off                               ' ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off                           ' PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = On                             ' Stack full/underflow will cause reset
    LVP = Off                               ' Higher Voltage on MCLR/VPP must be used for programming
    XINST = Off                             ' Extended Instruction Set disabled

    WDTCPS = WDTCPS_17                      ' WDT Period Divider ratio 1:4194304
    WDTE = Off                              ' WDT disabled

    WDTCWS = WDTCWS_7                       ' WDT window always open (100%); software control; keyed access not required
    WDTCCS = SC                             ' WDT input clock Software Control

    BBSIZE = BBSIZE_512                     ' Boot Block size is 512 words
    BBEN = Off                              ' Boot block disabled
    SAFEN = Off                             ' SAF disabled
    Debug = Off                             ' Background Debugger disabled

    WRTB = Off                              ' Boot Block not Write protected
    WRTC = Off                              ' Configuration registers not Write protected
    WRTD = Off                              ' Data EEPROM not Write protected
    WRTSAF = Off                            ' SAF not Write Protected
    WRTAPP = Off                            ' Application Block not write protected

    Cp = Off                                ' PFM and Data EEPROM code protection disabled
Config_End

tnencon

Quote from: top204 on Jul 27, 2024, 05:37 PMI've used Timer0 operating in 16-bit mode on a PIC18F05Q41 device and it works well.

The smaller Q devices seem to match each other, for now, with SFRs, and the demonstration template code listing I have just created below compiles correctly, so it should work on a PIC18F14Q40 device.

'
'  /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\    \/\\\                                                /\\\          /\\\
'  \/\\\\\\\\\\\/        /\\\\\    /\\\\\\\\\\    /\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'    \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\    \/\\\        \/\\\        /\\\\\\\\\\
'      \/\\\    \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\    \/\\\ /\\  /\\\/////\\\
'      \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\  \//\\\\\\\\/\\
'        \///        \///    \/////    \//////////    \//////////      \/////        \/////    \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Timer0 routines for a PIC18F14Q40 device.
' Written by Les Johnson for the Positron8 compiler.
'
    Device = 18F14Q40                                              ' Tell the compiler what device to compile for
    Declare Xtal = 64                                              ' Tell the compiler what frequency the device is operating at (in MHz)
    On_Hardware_Interrupt Goto ISR_Handler                          ' Point the compiler to the interrupt handler
'
' Setup USART1
'
    Declare Hserial1_Baud = 9600
    Declare HRSOut1_Pin  = PORTC.4
'
' Timer0 meta-macros to make the code easier to read and use
'
$define Timer0_Flag() PIR3bits_TMR0IF                              ' Timer0 flag
$define Timer0_FlagClear()  Timer0_Flag() = 0                      ' Clear the Timer0 flag
$define Timer0_IntEnable()  PIE3bits_TMR0IE = 1                    ' Enable a Timer0 interrupt
$define Timer0_IntDisable() PIE3bits_TMR0IE = 0                    ' Disable a Timer0 interrupt
$define Timer0_Start() T0CON0bits_T0EN = 1                          ' Start Timer0
$define Timer0_Stop()  T0CON0bits_T0EN = 0                          ' Stop Timer0

$define Periph_IntEnable()  INTCON0bits_GIEL = 1                    ' Enable peripheral interrupts
$define Periph_IntDisable() INTCON0bits_GIEL = 0                    ' Disable peripheral interrupts
$define Global_IntEnable()  INTCON0bits_GIE = 1                    ' Enable global interrupts
$define Global_IntDisable() INTCON0bits_GIE = 0                    ' Disable global interrupts
'
' Create any Global variables here
'
    Dim wTimer0ReloadVal As Word Heap                              ' Holds the Timer0 reload value for the interrupt handler
    Dim wTimer0_SFR As TMR0L.Word                                  ' Create a 16-bit SFR from TMR0L\H

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

'-------------------------------------------------------------------------------------------------
' Setup the program's variables, and any peripherals
' Input    : None
' Output    : None
' Notes    : None
'
Proc Setup()
    Timer0_Init_100us()                                            ' Setup Timer0 for an overflow every 100us with a 64MHz oscillator
    Periph_IntEnable()                                              ' Enable peripheral interrupts (not needed for a Timer0 interrupt, but better safe than sorry)
    Global_IntEnable()                                              ' Enable global interrupts
EndProc

'-------------------------------------------------------------------------------------------------
' Setup Timer0 for an overflow every 100us with a 64MHz oscillator
' Input    : None
' Output    : None
' Notes    : None
'
Proc Timer0_Init_100us()
    T0CON1 = %01000000                                              ' Timer0 uses FOSC/4. Prescaler is 1:1. Set for not synchronised
    wTimer0_SFR = $F9C0                                            ' Set Timer0 for a 100us overflow at 64MHz device operation
    wTimer0ReloadVal = wTimer0_SFR                                  ' Load the 16-bit TMR0L\H values to the 16-bit reload variable
    Timer0_FlagClear()                                              ' Clear the Timer0 interrupt flag
    Timer0_IntEnable()                                              ' Enable a Timer0 interrupt
    T0CON0 = %10010000                                              ' Postscaler is 1:1. Timer0 enabled and set for 16-bit mode
EndProc

'-------------------------------------------------------------------------------------------------
' Read the 16-bit Timer0 registers value
' Input    : None
' Output    : Returns the 16-bit Timer0 value
' Notes    : None
'
Proc Timer0_Read(), Word
    Result.Byte0 = TMR0L
    Result.Byte1 = TMR0H
EndProc

'--------------------------------------------------------------------------
' Write 16-bits to the Timer0 registers
' Input    : pTimerVal holds the 16-bit value to write to Timer0
' Output    : None
' Notes    : None
'
Proc Timer0_Write16(pTimerVal As Word)
    TMR0H = pTimerVal.Byte1
    TMR0L = pTimerVal.Byte0
EndProc

'-------------------------------------------------------------------------------------------------
' Interrupt Handler
' Input    : None
' Output    : None
' Notes    : Interrupts on a Timer0 overflow
'
ISR_Handler:
    Context Save                                                    ' Save any compiler system variables and certain SFRs used within the interrupt handler
    If Timer0_Flag() = 1 Then                                      ' Was it a Timer0 overflow that triggered the interrupt?
        '
        ' Yes. So code goes here for the Timer0 interrupt
        '
        wTimer0_SFR = wTimer0ReloadVal                              ' Load TMR0L\H with the reload value for the duration required
        Timer0_FlagClear()                                          ' Clear the Timer0 flag
    EndIf
    Context Restore                                                ' Restore any compiler system variables and SFRs used within the interrupt handler, and exit the interrupt

'-------------------------------------------------------------------------------------------------
' Setup the config fuses for internal oscillator at 64MHz, with OSC pins as I/O
' For a PIC18F14Q40 device
'
Config_Start
    FEXTOSC = Off                          ' External Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ                ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1

    CLKOUTEN = Off                          ' CLKOUT function is disabled
    PR1WAY = Off                            ' PRLOCKED bit can be set and cleared repeatedly
    CSWEN = On                              ' Writing to NOSC and NDIV is allowed
    FCMEN = On                              ' Fail-Safe Clock Monitor enabled
    FCMENP = On                            ' Fail-Safe Clock Monitor enabled; timer will flag FSCMP bit and OSFIF interrupt on EXTOSC failure.
    FCMENS = On                            ' Fail-Safe Clock Monitor enabled; timer will flag FSCMP bit and OSFIF interrupt on SOSC failure.

    MCLRE = EXTMCLR                        ' MCLR pin is MCLR
    PWRTS = PWRT_OFF                        ' PWRT is disabled
    MVECEN = Off                            ' Interrupt controller does not use vector table to prioritze interrupts
    IVT1WAY = On                            ' IVTLOCKED bit can be cleared and set only once
    LPBOREN = On                            ' Low-Power BOR enabled
    BOREN = On                              ' Brown-out Reset enabled according to SBOREN

    BORV = VBOR_1P9                        ' Brown-out Reset Voltage (VBOR) set to 1.9V
    ZCD = Off                              ' ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off                          ' PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = On                            ' Stack full/underflow will cause Reset
    LVP = Off                              ' HV on MCLR/VPP must be used for programming
    XINST = Off                            ' Extended Instruction Set and Indexed Addressing Mode disabled

    WDTCPS = WDTCPS_17                      ' WDT Period Divider ratio 1:4194304
    WDTE = Off                              ' WDT disabled

    WDTCWS = WDTCWS_7                      ' WDT window always open (100%); software control; keyed access not required
    WDTCCS = SC                            ' WDT input clock Software Control

    BBSIZE = BBSIZE_512                    ' Boot Block size is 512 words
    BBEN = Off                              ' Boot block disabled
    SAFEN = Off                            ' SAF disabled
    Debug = Off                            ' Background Debugger disabled

    WRTB = Off                              ' Boot Block not Write protected
    WRTC = Off                              ' Configuration registers not Write protected
    WRTD = Off                              ' Data EEPROM not Write protected
    WRTSAF = Off                            ' SAF not Write Protected
    WRTAPP = Off                            ' Application Block not write protected

    Cp = Off                                ' PFM and Data EEPROM code protection disabled
Config_End

Thanks for the reply Les;
If the postscaler is selected as 1:1 in the code, my code works properly. However, when we change the postscaler ratio, the code works incorrectly as I mentioned before.
Note: There is no problem with the prescaler ratio, I can make adjustments by making any changes I want.
Thanks in advance.