You need to log in to create posts and topics.

PIC16F877A Timer0/Timer1 Prescaler ignored during External Clock counting

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:

  1. Use the provided C code below to generate a HEX file.

  2. In SimulIDE, connect a 1Hz Pulse Generator to Pin 6 (RA4).

  3. Connect PORTB to a set of LEDs or a Probe.

  4. 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

Hi. Thanks for reporting.

Which version are you using?
Did you try with the last stable version?

I am using

arcachofo has reacted to this post.
arcachofo

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.

https://simulide.com/p/testers/ 

Ahmed__________ has reacted to this post.
Ahmed__________

Thanks @arcachofo!
Confirmed: after updating SimulIDE, the issue is fixed.
Timer0/Timer1 with external clock now apply the prescaler correctly 👍

Much appreciated

arcachofo has reacted to this post.
arcachofo