# Timer 1 can't increment on external T1OSI source for PIC16f627A

New to PIC programming

Trying to Simulate a PIC16F627A TIMER 1 using MPLAB X IDE where RB7/T1OSI increments, and it toggles RB4 through TMR1 ISR.

#include <stdio.h>

#include <xc.h

#pragma config WDTE = 0;

//timer1
//period 1 ms or every 100 T1CKI
//external from T1CKI rising edge (1 sec Period) T1OSCEN = 0; //
//PIN RB4

void interrupt Pulse_ISR (void)
{
PORTBbits.RB4 = !PORTBbits.RB4;
PIR1bits.TMR1IF = 0;
TMR1L = 0x96;
TMR1H = 0xFF;
}

void Init (void)
{
//Global Interrupt
//Peripheral Interrupt
//TMR1IE
//1:8 prescalar
//t = 1us*8*N    N = 100
//TMR1 = (2^16+1) - 100 = 65436 FF96

TRISB4 = 0;//RB4 is output
TRISB6 = 1;//RB6 and RB7 are input
TRISB7 = 1;

INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
PIE1bits.TMR1IE = 1;

T1CONbits.T1CKPS = 0b11;//1:8
T1CONbits.T1OSCEN = 1;//TMR1 increments on T1OSI RB7
T1CONbits.TMR1CS = 1;

TMR1L = 0x96;
TMR1H = 0xFF;

PORTBbits.RB4 = 1;

T1CONbits.TMR1ON = 1;
}

void main (void)
{
Init ();

//I will simulate a 1 ms pulse 50% Duty Cycle at T1CKI/RB6

while(1);
}


I created a stimuli where I created a pulse on pin RB7 with period of 500us

and I watch the result throught IO pins

I build the project and Debug it, watch RB4 IO Pins and it never toggles.

Can someone tell me why? Thank you.

MPLAB X IDE v3.55 PIC16F627A Debugging Tool: Simulator

• If you add a debug breakpoint in the ISR, does it ever execute that code? – Roger Rowland Apr 20 '17 at 7:19
• You might also need to set LVP off, otherwise RB4 will be used as PGM, and won't work as a digital output. – Roger Rowland Apr 20 '17 at 7:29
• @RogerRowland No it doesn't – Forat Apr 20 '17 at 11:38
• @RogerRowland, I don't think that's the case, because before I got this issue, I did the same thing with RB6/T1CKI... (same code with the only difference T1OSCEN = 1;//to enable T1OSO), and it worked. – Forat Apr 20 '17 at 11:39
• @RogerRowland, I read something at the PIC16F627A Manual, that I think might be related. Page 53 of the Manual "A crystal oscillator circuit is built in between pins T1OSI (input) and T1OSO (amplifier output). It is enabled by setting control bit T1OSCEN (T1CON<3>). It will continue to run during Sleep. It is primarily intended for a 32.768 kHz watch crystal. Table 7-1 shows the capacitor selection for the Timer1 oscillator. The user must provide a software time delay to ensure proper oscillator start-up." This I don't understand what it means? – Forat Apr 20 '17 at 12:21

• I tried your code and it didn't work for me either but it somehow worked if I injected the clock on the T1OSOpin. Since, if you're using a crystal, you'd have both pins connected to it you may try simulating your program with that workaround. – zakkos Apr 22 '17 at 15:05