period Function

Top  Previous  Next

Gets the period of a capture channel.

Syntax

Cell.Capture.period(channel)

Arguments

channelThe capture channel number, range 0 - 3.

Return Value

The integer number of counts in the most recent full cycle on the capture channel input, or 0 if there has been no transition on the input since the last time the period was read.

Remarks

The capture channel must be assigned a pin using the pin property before the period function can return a valid value.

 

The value is in counts; use the resolution constant to get the number of counts per second. The actual frequency can be computed as follows:

 

freq = Cell.Capture.resolution / Cell.Capture.period(channel);

 

while the actual period (in fractional seconds) can computed as follows:

 

period = Cell.Capture.period(channel) / Cell.Capture.resolution;

 

where channel is the desired capture channel number.

 

Once the period has been read, subsequent attempts to read the value will return 0 until a transition (low-to-high or high-to-low) occurs on the channel's input pin.

Examples

See example for the pulseHi function.

See Also

pin Property, resolution Constant