Hello does anyone have a example of code to measure the period of a pulse? Maybe using CCP or something? Thanks.
Printable View
Hello does anyone have a example of code to measure the period of a pulse? Maybe using CCP or something? Thanks.
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.
I think you need to use the PULSIN command if you do not need interruptable operations.
Code: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.
Thanks for the replies.
Here is a good read
http://www.picbasic.co.uk/forum/showthread.php?p=23401