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.

to start a timer...

Status
Not open for further replies.

TKS

New Member
Hi,

i was wondering if it is possible to measure the time between 2 pulses on a given port..??

and that for 9 ports...

the maximum pulses will be arround 12 pulses on each 9 pins per second..??

can a 20Mhz pic do this..???
do i need to work whit interupts..???

are there 9 timers available..

i want to count the time between 2 pulses because this is better then

counting over a period the pulses..

TKS
 
:idea:

If you want a simple(ish) solution, use a descreet logic chip, not sure of the number, but a 9->1 switch, feed the input of this to rb0 and use tmr0 in external mode.

Or for 8 inputs you can use the interrupt on change feature of port b and read and store tmr0 into seperate registers.

I am asumming you are using an 18pin PIC.....
 
uhh...

let's say i use

1 16F877a

or 9 16F877a
i don't care..

i only need to know if it can handle the pulses on the i/o lines

in that way that i canmeasure the time between the pulses

and i can know on which line it was...

TKS
 
Re: uhh...

TKS said:
let's say i use

1 16F877a

or 9 16F877a
i don't care..

i only need to know if it can handle the pulses on the i/o lines

in that way that i canmeasure the time between the pulses

and i can know on which line it was...

TKS

You need to give more details of your requirements, presumably (from what you've already said) you are effectively wanting to measure the frequency of the pulses - but as it's a low frequency, you are planning measure the time for one cycle, and calculating the frequency from that. This is a standard way of measuring low frequencies.

It's quite simple to do totally in software, there's no need for timers, simply follow these steps:

1) Test the port pin, and wait until it's low.

2) Wait until the port pin goes high - start of cycle.

3) Increment a software counter, use as many bytes as you need for the resolution you require.

4) Check if port is low again, if not go back to 3).

5) Increment the software counter again.

6) Check if port if high again, if not go back to 5).

7) End of routine, software counter holds a representation of the width of one cycle.

This will only work for one input pin at a time, for more than one input pin you would need to measure then in turn - if the pulses appear at random intervals, on random pins, it gets a lot more difficult.

So please give more details of what you are trying to do!.
 
If it repeats, it may be feasible to count how many pulses you've seen in the last second (or several seconds, given that it's only 12/sec).

Can't use external interrupts without a mux. The PortB pins get used for those, and there are only 8 of them.

With a signal of such low freq, you'd probably just use a timer though, and periodically check whether there's a rising edge on the pin. At 20MHz vs 12 Hz, you've got nearly half a million clks per clk, so it shouldn't be hard to get good resolution. You might do something like TMR0 configured as 8 bit timer, creating an interrupt every 256 clks. Maintain a counter for each pin. In the ISR, just check if any of the pins have changed. If so, copy the counter for that pin and zero the original, if not, increment it.

If the counter is 16 bit, be sure to protect it against being modified by the ISR while being read elsewhere.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top