AIOUSB::CounterSubsystem Class Reference

#include <CounterSubsystem.hpp>

Inheritance diagram for AIOUSB::CounterSubsystem:

Inheritance graph
[legend]
Collaboration diagram for AIOUSB::CounterSubsystem:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual std::ostream & print (std::ostream &out)
int getNumCounterBlocks () const
int getNumCounters () const
CountergetCounter (int counter)
UShortArray readCounts (bool oldData)
CounterSubsystemselectGate (int counter)
double startClock (int counterBlock, double clockHz)
CounterSubsystemstopClock (int counterBlock)

Protected Member Functions

 CounterSubsystem (USBDevice &parent)
virtual ~CounterSubsystem ()

Protected Attributes

int numCounterBlocks
int numCounters
CounterList counters

Static Protected Attributes

static const int COUNTERS_PER_BLOCK = 3

Friends

class Counter
class USB_AI16_Family
class USB_CTR_15_Family
class USB_DIO_32_Family


Detailed Description

Class CounterSubsystem represents the counter/timer subsystem of a device. One accesses this counter/timer subsystem through its parent object, typically through a method such as ctr() (see USB_AI16_Family::ctr()).

Constructor & Destructor Documentation

AIOUSB::CounterSubsystem::CounterSubsystem ( USBDevice parent  )  [protected]

AIOUSB::CounterSubsystem::~CounterSubsystem (  )  [protected, virtual]


Member Function Documentation

Counter & AIOUSB::CounterSubsystem::getCounter ( int  counter  ) 

Gets a reference to an individual counter. You must obtain a reference to a counter before you can perform counter operations.

Parameters:
counter the counter for which to obtain a reference (0 to n-1).
Returns:
A reference to the specified counter.
Exceptions:
IllegalArgumentException 

int AIOUSB::CounterSubsystem::getNumCounterBlocks (  )  const [inline]

Gets the number of counter blocks. Typically there are three counters per counter block.

Returns:
The number of counter blocks.

int AIOUSB::CounterSubsystem::getNumCounters (  )  const [inline]

Gets the number of individual counters, indexed from 0 to n-1.

Returns:
The number of individual counters.

ostream & AIOUSB::CounterSubsystem::print ( std::ostream &  out  )  [virtual]

Prints the properties of this subsystem. Mainly useful for diagnostic purposes.

Parameters:
out the print stream where properties will be printed.
Returns:
The print stream.

Implements AIOUSB::DeviceSubsystem.

UShortArray AIOUSB::CounterSubsystem::readCounts ( bool  oldData  ) 

Reads the current count values of all the counters, optionally including an "old data" indication. If oldData is true, then an extra word will be returned (one word for each counter, plus one extra word) that contains an "old data" indication, which is useful for optimizing polling rates. If the value of the final word is zero, then the data is "old data," meaning you are polling the counters faster than your gate signal is running. If oldData is false, then only the count values are returned.

Parameters:
oldData true includes the "old data" indication in the returned data; false returns just the count values.
Returns:
An array containing the current count values for all the counters plus an optional "old data" indication in the final word.
Exceptions:
OperationFailedException 

CounterSubsystem & AIOUSB::CounterSubsystem::selectGate ( int  counter  ) 

Selects the counter to use as a gate in frequency measurement on other counters.

Parameters:
counter the counter to select as a gate (0 to n-1).
Returns:
This subsystem, useful for chaining together multiple operations.
Exceptions:
IllegalArgumentException 
OperationFailedException 

double AIOUSB::CounterSubsystem::startClock ( int  counterBlock,
double  clockHz 
)

Selects an output frequency for a counter block and starts the counters. selectGate( int counter ) and readCounts( bool oldData ) are used in measuring frequency. To measure frequency one must count pulses for a known duration. In simplest terms, the number of pulses that occur for 1 second translates directly to Hertz. In the USB-CTR-15 and other supported devices, you can create a known duration by configuring one counter to act as a "gating" signal for any collection of other counters. The other "measurement" counters will only count during the "high" side of the gate signal, which we can control.

So, to measure frequency you:
1. Create a gate signal of known duration
2. Connect this gating signal to the gate pins of all the "measurement" counters
3. Call selectGate() to tell the board which counter is generating that gate
4. Call readCounts( true ) periodically to read the latched count values from all the "measurement" counters.

In practice, it may not be possible to generate a gating signal of sufficient duration from a single counter. Simply concatenate two or more counters into a series, or daisy-chain, and use the last counter's output as your gating signal. This last counter in the chain should be selected as the "gate source" using selectGate( int counter ).

Once a value has been read from a counter using the readCounts( true ) call, it can be translated into actual Hz by dividing the count value returned by the high-side-duration of the gating signal, in seconds. For example, if your gate is configured for 10Hz, the high-side lasts 0.05 seconds. If you read 1324 counts via the readCounts( true ) call, the frequency would be "1324 / 0.05", or 26.48 KHz.

Parameters:
counterBlock the counter block to use to generate the frequency.
clockHz the desired output frequency (in Hertz).
Returns:
The actual frequency that will be generated, limited by the device's capabilities.
Exceptions:
IllegalArgumentException 
OperationFailedException 

CounterSubsystem& AIOUSB::CounterSubsystem::stopClock ( int  counterBlock  )  [inline]

Halts the counter started by startClock( int counterBlock, double clockHz )

Parameters:
counterBlock the counter block to halt generating a frequency.
Returns:
This subsystem, useful for chaining together multiple operations.


Friends And Related Function Documentation

friend class Counter [friend]

friend class USB_AI16_Family [friend]

friend class USB_CTR_15_Family [friend]

friend class USB_DIO_32_Family [friend]


Member Data Documentation

const int AIOUSB::CounterSubsystem::COUNTERS_PER_BLOCK = 3 [static, protected]


doxygen