Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16F631, Timer1 & Gate

Status
Not open for further replies.

Nayth

New Member
Hi eveybody

I'm trying to measure time between 2 pulses on PORTA.4 which just so happens to be the Timer1 Gate.

I was thinking that it should be possible to start the timer when the port goes high and then stop it again when it goes high the next time and see if 10 seconds has passed. If 10 seconds has passed I want to do something otherwise something else.

My problem is that I don't know where to start.

Anybody who could give me an example of how I should go about this?

I'm using PIC16F631 running at 4MHz

Thanks in advance :)
 
Hmm.. I am not sure Timer 1 Gate feature is meant for what you plan to do.

Referring to Timer1 Block Diagram, T1G pin is indirectly connected to TMR1's enable 'pin'. My rough guess is Timer1 will only count when T1G is LOW and stop counting when T1G is HIGH.

What you intend to do it to time between 2 rising edge of the pulse right..? My suggestion is to use interrupt-on-change.

Basically, interrupt will be triggered when the state of pin changes (either from LOW to HIGH or HIGH to LOW). What I would do is to

1) Read the timer value at every interrupt.
2) Decide whether it is change of LOW to HIGH or HIGH to LOW.
3) If it is LOW to HIGH change then decide whether is it the first pulse or second pulse. (I would use a flag to indicate).
4) If it is first pulse, just store the timer value in a variable. If it is the second pulse, get the different between the 2 timer values. With some calculation, you can get the time between 2 pulses.
 
Last edited:
Referring to Timer1 Block Diagram, T1G pin is indirectly connected to TMR1's enable 'pin'. My rough guess is Timer1 will only count when T1G is LOW and stop counting when T1G is HIGH.

Code:
T1GINV: Timer1 Gate Invert bit(1)
1 = Timer1 gate is active high (Timer1 counts when Timer1 gate signal is high)
0 = Timer1 gate is active low (Timer1 counts when gate is low)

[SIZE="1"]Note 1: T1GINV bit inverts the Timer1 gate logic, regardless of source.[/SIZE]

You might be right about the IOC though, it's probably the easiest way to do it
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top