Capture Object

Top  Previous  Next

Allows measuring frequency and pulse width.

Description

There are four capture channels, 0 - 3, that measure period and pulse width of a digital input. Any of pins A0 - A7 or B0 - B7 can be assigned to a capture channel. Once a pin has been assigned to a capture channel, it is continuously monitored for pulse width and period. The most recent value of pulse width or period can be read at any time.

 

To assign a pin to a capture channel, use the pin property array. The array has four elements, one for each channel. A pin number (0 - 7 for PortA, 8 - 15 for PortB) is assigned to the property array element that corresponds to the capture channel.

 

To read the most recent complete period of a capture channel, call the period function passing the channel number (0 - 3). The value returned is the integer number of counts in the period. The resolution constant returns the number of counts per second. Thus the frequency of the signal can be computed as follows:

 

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

 

where channel is the capture channel number. To compute period in fractional seconds, just use the reciprocal of this calculation.

 

Likewise, to read the pulse width of a capture channel, use the pulseHi function or the pulseLo function, for high pulse width or low pulse width, respectively. These functions return integer counts which can be converted to fractional seconds by dividing by resolution.

Constants

resolution

Gets the number of counts per second.

Static Functions

period

Gets the period of a capture channel.

pulseHi

Gets the high pulse width of a capture channel.

pulseLo

Gets the low pulse width of a capture channel.

Static Properties

pin

An array that gets or sets which pin is assigned to each capture channel.