PDA

View Full Version : Measuring Period of a pulse



c_moore
- 14th February 2012, 23:21
Hello does anyone have a example of code to measure the period of a pulse? Maybe using CCP or something? Thanks.

Art
- 15th February 2012, 02:43
Don't have example code, but start a timer, set portb interrupt, get the value of the timer in the interrupt service routine,
reset the timer for the next pulse.

Jerson
- 15th February 2012, 04:05
I think you need to use the PULSIN command if you do not need interruptable operations.


PULSIN Pin,State,Var
Measures pulse width on Pin. If State is zero, the width of a low pulse
is measured. If State is one, the width of a high pulse is measured.
The measured width is placed in Var. If the pulse edge never happens
or the width of the pulse is too great to measure, Var is set to zero.
Pin is automatically made an input. Pin may be a constant, 0 - 15, or a
variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g.
PORTA.0).
The resolution of PULSIN is dependent upon the oscillator frequency. If
a 4MHz oscillator is used, the pulse width is returned in 10us increments.
If a 20MHz oscillator is used, the pulse width will have a 2us resolution.
Defining an OSC value has no effect on PULSIN. The resolution always
changes with the actual oscillator speed.

c_moore
- 15th February 2012, 10:41
Thanks for the replies.

Tobias
- 17th February 2012, 05:15
Here is a good read

http://www.picbasic.co.uk/forum/showthread.php?p=23401