PIC16F877A Timer0/Timer1 Prescaler ignored during External Clock counting
Quote from Ahmed__________ on December 17, 2025, 11:17 pmI am reporting an issue where the hardware prescaler for Timer0 and Timer1 is bypassed or ignored when the MCU is configured to count an external clock source on the PIC16F877A. Even when setting the prescaler to 1:4, 1:8, or 1:256, the timer registers (TMR0/TMR1) increment at a 1:1 ratio with every incoming pulse.
Environment:
MCU: PIC16F877A
Simulator: SimulIDE (version 1.1.0)
Compiler: Microchip XC8
Input: 1Hz Square Wave Generator connected to RA4/T0CKI or RC0/T1CKI.
When
OPTION_REGis configured for an external clock source on RA4 with the prescaler assigned to Timer0, the expected behavior is thatTMR0increments once every N pulses (where N is the prescaler rate).In the current simulation,
TMR0increments on every pulse regardless of thePS<2:0>bit settings.Steps to Reproduce:
Use the provided C code below to generate a HEX file.
In SimulIDE, connect a 1Hz Pulse Generator to Pin 6 (RA4).
Connect PORTB to a set of LEDs or a Probe.
Run the simulation and observe that PORTB increments every 1 second instead of every 4 seconds.
#include <xc.h> // Basic Config #pragma config FOSC = XT, WDTE = OFF, LVP = OFF void main(void) { ADCON1 = 0x06; // Ensure PORTA is Digital TRISA = 0b00010000; // RA4 as Input TRISB = 0x00; // PORTB as Output PORTB = 0x00; // --- Timer0 Configuration --- // T0CS = 1 (External Clock) // PSA = 0 (Prescaler to Timer0) // PS = 001 (1:4 Ratio) OPTION_REG = 0b00100001; TMR0 = 0; while(1) { // Expected: Increments every 4 pulses // Actual: Increments every 1 pulse PORTB = TMR0; } }The same issue occurs with Timer1 (RC0/T1CKI) when setting
T1CONbits 5-4 for a 1:4 or 1:8 prescaler.
I would appreciate it if the development team could look into the Timer0/Timer1 hardware model to see if the prescaler logic is correctly linked when T0CS/TMR1CS is set to external.
Please let me know if you need the .simu file, the .hex file, or any further information to help debug this issue.
Best regards,
Ahmed Alghamdi
I am reporting an issue where the hardware prescaler for Timer0 and Timer1 is bypassed or ignored when the MCU is configured to count an external clock source on the PIC16F877A. Even when setting the prescaler to 1:4, 1:8, or 1:256, the timer registers (TMR0/TMR1) increment at a 1:1 ratio with every incoming pulse.
Environment:
-
MCU: PIC16F877A
-
Simulator: SimulIDE (version 1.1.0)
-
Compiler: Microchip XC8
-
Input: 1Hz Square Wave Generator connected to RA4/T0CKI or RC0/T1CKI.
When OPTION_REG is configured for an external clock source on RA4 with the prescaler assigned to Timer0, the expected behavior is that TMR0 increments once every N pulses (where N is the prescaler rate).
In the current simulation, TMR0 increments on every pulse regardless of the PS<2:0> bit settings.
Steps to Reproduce:
-
Use the provided C code below to generate a HEX file.
-
In SimulIDE, connect a 1Hz Pulse Generator to Pin 6 (RA4).
-
Connect PORTB to a set of LEDs or a Probe.
-
Run the simulation and observe that PORTB increments every 1 second instead of every 4 seconds.
#include <xc.h>
// Basic Config
#pragma config FOSC = XT, WDTE = OFF, LVP = OFF
void main(void) {
ADCON1 = 0x06; // Ensure PORTA is Digital
TRISA = 0b00010000; // RA4 as Input
TRISB = 0x00; // PORTB as Output
PORTB = 0x00;
// --- Timer0 Configuration ---
// T0CS = 1 (External Clock)
// PSA = 0 (Prescaler to Timer0)
// PS = 001 (1:4 Ratio)
OPTION_REG = 0b00100001;
TMR0 = 0;
while(1) {
// Expected: Increments every 4 pulses
// Actual: Increments every 1 pulse
PORTB = TMR0;
}
}
The same issue occurs with Timer1 (RC0/T1CKI) when setting T1CON bits 5-4 for a 1:4 or 1:8 prescaler.
I would appreciate it if the development team could look into the Timer0/Timer1 hardware model to see if the prescaler logic is correctly linked when T0CS/TMR1CS is set to external.
Please let me know if you need the .simu file, the .hex file, or any further information to help debug this issue.
Best regards,
Ahmed Alghamdi
Quote from arcachofo on December 17, 2025, 11:49 pmHi. Thanks for reporting.
Which version are you using?
Did you try with the last stable version?
Hi. Thanks for reporting.
Which version are you using?
Did you try with the last stable version?
Quote from Ahmed__________ on December 17, 2025, 11:51 pmI am using
- SimulIDE 1.1.0 – Last Stable version.
I am using
- SimulIDE 1.1.0 – Last Stable version.
Quote from arcachofo on December 18, 2025, 2:50 pmI think the issue is solved now.
I uploaded new tester builds for 1.1.0, feel free to test if it's working now as expected.
I think the issue is solved now.
I uploaded new tester builds for 1.1.0, feel free to test if it's working now as expected.
Quote from Ahmed__________ on December 18, 2025, 11:23 pmThanks @arcachofo!
Confirmed: after updating SimulIDE, the issue is fixed.
Timer0/Timer1 with external clock now apply the prescaler correctly 👍Much appreciated
Thanks @arcachofo!
Confirmed: after updating SimulIDE, the issue is fixed.
Timer0/Timer1 with external clock now apply the prescaler correctly 👍
Much appreciated
