Skip to main content
Skip table of contents

4.1.9 - Easy Functions [U3 Datasheet]

References for the easy functions can be found in our UD Library Docs.

The easy functions are simple alternatives to the very flexible IOType based method normally used by this driver. There are 6 functions available:

eAIN() //Read 1 analog input.
eDAC() //Write to 1 analog output.
eDI() //Read 1 digital input.
eDO() //Write to 1 digital output.
eTCConfig() //Configure all timers and counters.
eTCValues() //Update/reset and read all timers and counters.

In addition to the basic operations, these functions also automatically handle configuration as needed. For example, eDO() sets the specified line to digital output if previously configured as analog and/or input, and eAIN() sets the line to analog if previously configured as digital. Passing a -1 to any of the configuration parameters (resolution, range, etc) will use the driver's current value instead of having to specify it. This is useful so that you can use the driver's default values for those properties, which will work in most cases.

The first 4 functions should not be used when speed is critical with multi-channel reads. These functions use one low-level function per operation, whereas using the normal Add/Go/Get method with IOTypes, many operations can be combined into a single low-level call. With single channel operations, however, there will be little difference between using an easy function or Add/Go/Get.

The last two functions handle almost all functionality related to timers and counters, and will usually be as efficient as any other method. These easy functions are recommended for most timer/counter applications.

Following is example pseudocode:

//Take a single-ended measurement from AIN3.
//eAIN (Handle, ChannelP, ChannelN, *Voltage, Range, Resolution,
// Settling, Binary, Reserved1, Reserved2)
eAIN(lngHandle, 3, 31, &dblVoltage, 0, 0, 0, 0, 0, 0);
printf("AIN3 value = %.3f\n",dblVoltage);

//Set DAC0 to 3.1 volts.
//eDAC (Handle, Channel, Voltage, Binary, Reserved1, Reserved2)
eDAC(lngHandle, 0, 3.1, 0, 0, 0);

//Read state of FIO2.
//eDI (Handle, Channel, *State)
eDI(lngHandle, 2, &lngState);
printf("FIO2 state = %.0f\n",lngState);

//Set FIO3 to output-high.
//eDO (Handle, Channel, State)
eDO(lngHandle, 3, 1);

//Enable and configure 1 output timer and 1 input timer, and enable Counter0.
//Fill the arrays with the desired values, then make the call.
alngEnableTimers = {1,1}; //Enable Timer0-Timer1
alngTimerModes = {LJ_tmPWM8,LJ_tmRISINGEDGES32}; //Set timer modes
adblTimerValues = {16384,0}; //Set PWM8 duty-cycle to 75%.
alngEnableCounters = {1,0}; //Enable Counter0
//eTCConfig (Handle, *aEnableTimers, *aEnableCounters, TCPinOffset,
// TimerClockBaseIndex, TimerClockDivisor, *aTimerModes,
// *aTimerValues, Reserved1, Reserved2);
eTCConfig(lngHandle, alngEnableTimers, alngEnableCounters, 4, LJ_tc48MHZ, 0, alngTimerModes, adblTimerValues, 0, 0);

//Read and reset the input timer (Timer1), read and reset Counter0, and update
//the value (duty-cycle) of the output timer (Timer0).
//Fill the arrays with the desired values, then make the call.
alngReadTimers = {0,1}; //Read Timer1
alngUpdateResetTimers = {1,1}; //Update Timer0 and reset Timer1
alngReadCounters = {1,0}; //Read Counter0
alngResetCounters = {1,0}; //Reset Counter0
adblTimerValues = {32768,0}; //Change Timer0 duty-cycle to 50%
//eTCValues (Handle, *aReadTimers, *aUpdateResetTimers, *aReadCounters,
// *aResetCounters, *aTimerValues, *aCounterValues, Reserved1,
// Reserved2);
eTCValues(lngHandle, alngReadTimers, alngUpdateResetTimers, alngReadCounters, alngResetCounters, adblTimerValues, adblCounterValues, 0, 0);
printf("Timer1 value = %.0f\n",adblTimerValues[1]);
printf("Counter0 value = %.0f\n",adblCounterValues[0]);

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.