Timer1 Interrupt & Gate

New Member
2009/12/01 07:15:29
Hi everybody

I'm trying to make make timer1 count from the start of input on a gate (Porta.4) and if said gate goes low before timer1 reaches 10 seconds then if want to turn off timer1 and turn off a running led light, otherwise reset timer1, start running led and start over with the counting provided that the gate is still high.

Anybody who could give me a small example as to how I would accomplish something like this?

My Chip is a PIC16F631 and the clockspeed is 4MHz

Thanks in advance.
New Member
RE: Timer1 Interrupt & Gate 2009/12/03 03:22:48
Nobody who can help?

I'm not looking for complete code, just something to get me startet
Scheisse Menschen
RE: Timer1 Interrupt & Gate 2009/12/03 03:27:35
Hmm, well: have you already written any program for a PIC? And for that family?

I'd start with a basic template and then add features step by step : the Timer, etc.

New Member
RE: Timer1 Interrupt & Gate 2009/12/03 03:36:54
Yeah I have programmed for that PIC before and I have a program I want to incorporate this timer1

I'm just totally lost with regards to this timer1, that's why I was hopping for some samples
New Member
RE: Timer1 Interrupt & Gate 2009/12/03 03:47:26
This is what I have as far as code for Timer1

/****Timer1 Init Start****/
//T1CON = 0b101.110.01;
T1GSS = 1; //Timer1 Gate Source Select bit
//1 = Timer1 gate source is T1G

T1GINV = 0; //Timer1 Gate Invert bit, 1 = count when high
TMR1GE = 1; //Timer1 Gate Enable bit
T1CKPS1 = 1; //T1CKPS<1:0>
T1CKPS0 = 1; //Timer1 Input Clock Prescale Select bits
//11 = 1:8 Prescale Value
//10 = 1:4 Prescale Value
//01 = 1:2 Prescale Value
//00 = 1:1 Prescale Value
T1OSCEN = 0; //LP Oscillator Enable Control bit
TMR1CS = 0; //Timer1 Clock Source Select bit, 1 = External
TMR1ON = 1; //Timer1 On bit

TMR1H = 0x00; //Timer1 Most Significant Byte
TMR1L = 0x00; //Timer1 Least Significant Byte

TMR1IE = 1; //Timer1 Overflow Interrupt Enable bit
PEIE = 1; //Peripheral Interrupt Enable bit
/****Timer1 Init End****/
Super Member
RE: Timer1 Interrupt & Gate 2009/12/05 07:57:55
Can you explain your requirements better?  Perhaps draw a timing diagram?

New Member
RE: Timer1 Interrupt & Gate 2009/12/09 01:06:45
Sorry for the late reply

I want to measure the time between pulses on a port and if the time exceeds 10seconds I want to do something otherwise I want to do something else

The port I want to measure on is conveniently PORTA4 which can be set up to enable Timer1 and make it count when it's high/low
New Member
RE: Timer1 Interrupt & Gate 2009/12/23 01:09:03
Anybody who can give me a small sample of how I should do this and point me in the right direction?

I was thinking it would be smart to have the timer start when the Timer Gate goes high. But I can't really figure out how to measure the time correctly because I want the check the time between to high pulses. :/