Demand Peripherals     Robotics and Automation Made Easy

COUNT4: Quad Up-Counter

The count4 peripheral provides four independent channels of count and period information. The sampling interval can be between 10 and 60 milliseconds in steps fo 10 ms. The counters can count rising, falling, or both edges in a pulse stream.

Each count reading is followed by the number of seconds it took to reach that count. The measured count interval is accurate to the microsecond. Having a count and an interval lets you computer the period with high accuracy even at very low count rates.



The COUNT4 peripheral is often paired with either the GPIO4 card or the GPIO4-ST card.

Each input pin is connected to separate counter. The maximum input frequency for each counter is 1.0 MHz.



The quad counter offers a configurable update rate and a choice of counting on the leading edge, the trailing edge, or on both edges. The output is a set of eight numbers that are four pairs of count and interval information. The count output works with select().

counts : Counts and intervals as four pairs of numbers where the first number is an unsigned integer and the second number is the number of seconds in the interval as a floating point number with 6 digits after the decimal point. All values are separated by spaces and each reading is terminated by a newline.

This resource is read-only. You can use the dpcat command and select() to get continuous updates into your program.

edges : Which edges to count as four single digit numbers in the range of 0 to 3. A setting of 0 disables the counter, a setting of 1 counts rising edged, 2 counts falling edges, and a setting of 3 counts both edges. Set all edges to 0 to turn off all output.

update_rate : Update period for the counts resource in milliseconds. The dpcat command and select() on counts will will give a readable file descriptor every update_rate milliseconds. This update period must be between 10 and 60 milliseconds in steps of 10 milliseconds. That is, valid values are 10, 20, 30, 40, 50, or 60 milliseconds.

This is a read-write resource and works with dpset and dpget but not dpcat.



Count both edges on channel one, disable channels two through four, and set the sample rate to 50 milliseconds.

   dpset count4 edges 3 0 0 0
   dpset count4 update_rate 50
   dpcat count4 counts

A sample output from 'counts' might be:

    1   0.007472   0   0.000000   0   0.000000   0   0.000000
    0   0.000000   0   0.000000   0   0.000000   0   0.000000
    1   0.007476   0   0.000000   0   0.000000   0   0.000000
    1   0.007474   0   0.000000   0   0.000000   0   0.000000
    0   0.000000   0   0.000000   0   0.000000   0   0.000000

You can not get an accurate frequency from counts alone but by including the accumulation time you can see that the input frequency is about 133.8 Hertz.


WARNING: Count4 is sensitive to noise around the zero-to-one threshold. Use Schmitt triggers to condition inputs that are not inherently digital.


FPGA Defined Peripherals
User Interface
FPGA Configuration
FPGA Buttons & LEDs
Host Tx/Rx Interface
AVR Interface
Stereo Audio Amplifier
Text LCD and Keypad
Quad WS2812 Interface
Quad Slide Pot
IR Recv/Xmit
6 Digit LCD
RC Decoder
Keyfob RF Decoder
Rotary Encoder Interface
Quad Touch Interface
Motion Control
Dual DC Motor Controller
Dual Quadrature Decoder
Quad 13 Bit Servo
Bipolar Stepper Controller
Unipolar Stepper Controller
Simple Input / Output
Quad Binary Output
Quad Binary Input
Octal Input/Output
32 Channel Binary Output
32 Channel Binary Input
Quad Serial Output
Octal Serial Output
Octal 12-bit ADC
Quad Ping))) Interface
Pololu QTR Interface
Octal SRF04 Interface
Generic I2C
Generic SPI
Octal 8-Bit DAC
Quad Digital Potentiometer
Quad PWM Output
Quad PWM Input
Quad Event Counter
Real Time Clock
Dual Pulse Generator

Interface Cards
Control Cards
User Interface
Stereo Audio Amplifier
IR Recv/xmit
Six Digit LCD Display
Keyfob RF Receiver
Rotary Encoder
Quad Switch Card
Text LCD / keypad
Quad Slide Pot
Quad Touch Interface
Motion Control
Dual 7-amp H-bridge
Quad Open Drain Driver
Quad 10 Amp Relay Card
Input / Output
Octal 8-Bit DAC
Quad Digital Potentiometer
Octal 12-bit ADC
Octal SRF04
I2C Prototyping
SPI Prototyping
USB 2.0 Hub
Real Time Clock
Octal Input/Output
32 Channel Input
32 Channel Output
Power Distribution Card
15 Amp Power Distribution
5 Volt Switching Regulator
ATX Power Break-Out Card
Disk Drive Power Break-Out
MP43 Aluminum Mounting Plate
WW4 Large Prototyping Card
WW2 Prototyping Card
WW1 Small Prototyping Card
SMP SMD Prototyping Card