open_phoenix(void) |
|
Opens the phoenix
driver and returns zero on success. For this call to succeed the device driver phdriver should be loaded and the device file '/dev/phoenix' should exist. /etc/rc.d/rc.local should have the scripts to load the driver during startup. Only one program can use the driver at a time |
#include "phlib.h" main() { if(!open_phoenix()) { fprintf(stderr, "Phoenix driver open failed.\n"); exit(1); } } |
int read_inputs (void) | |
Returns the status of the four Digital Input pins in a 4 bit word. Returns a value from 0 to 15 depends on the voltage levels present. | // Sets data to digital value at
the Input data = read_inputs(); |
boolean write_outputs (int dat) | |
Writes a value from 0 to 255 to the eight digital output pins of Phoenix. | // Sets lower four pins to HIGH,
rest
to LOW write_outputs(15); |
set_dac (int val) | |
Sets the 8 bit DAC
output
from -5V to +5V depends on the argument given. val : from 0 to 255 |
// Sets the DAC to nearly zero
volt set_dac(128); |
boolean set_voltage (double mv) | |
Sets DAC output from -5V to +5V depends on the argument given. The arguments ranges from -5000 to +5000 millivolts | // Sets the DAC to one volt set_voltage(1000.0); |
boolean rotate_motor (int nsteps, int dir) | |
Rotates the Stepper Motor. nsteps denotes the no. of steps and dir denotes the direction (1-clock & 0-anticlock). | // Takes 100 steps in clockwise
direction rotate_motor(100,1); |
boolean write_motor (int dat) | |
Writes values in between 0 and 15 to Stepper Motor Outputs. dat denotes the value to stepper motor outputs. | // Energises coil A
of stepper motor write_motor(1); |
boolean select_adc (int chan) | |
Selects the ADC
channel to be digitized There are four channels (0 to 3) Adding 4 to the channel number will do the next digitization without sampling the input, ie. the voltage held by the HOLD capacitor during the last digitization. |
double ts; int val; select_adc(0); // Selects channel 0 val = read_adc(&ts) // samples and digitizes channel 0 select_adc(0+4) // next read_adc will not sample the input |
int read_adc (double *ts) | |
Reads analog input. Returns the value read from ADC and a Timestamp (microseconds elapsed after year AD 1970) value. | double timestamp; int val; val =read_adc(×tamp); |
double zero_to_5000 (void) | |
Returns voltage in millivolts (0 to 5000mV) from the ADC. | double val; val = zero_to_5000(); |
double minus5000_to_5000 (void) | |
Returns the voltage in between -5000 mV to +5000 mV corresponding to the value read from ADC. | // Sets the data to a value at
the
ADC input between -5000 to +5000mV data = minus5000To5000(); |
boolean read_block (int npoints, int delay, boolean bipolar, double* tstamp, double *adval) | |
Digitizes the ADC input
npoints: number of digitizations. ( maximum 1024) delay : interval between two digitizations (min.115 usecs) bipolar: If TRUE returns -5000 to 5000 else 0 to 5000 mV tstamp : array to return the time stamps adval : array to return voltage in mv. |
double ts[256],
val[256]; read_block (256, 200, 1, ts, val); |
boolean
multi_read_block (int npoints, int nchan, int delay, double *t, int *a,
int *b,int *c, int *d) |
|
Digitizes the ADC
inputs (multiple channels) npoints : number of digitizations.(maximum 1024) nchan : number of channels (1 to 4). Starts with zero only. delay : interval between two digitizations(min.115 usecs) t : double array for time stamp a,b,c,d : int arrays for data (fills only the first nchan ones) This routine does simultaneous sampling of all the channels and digitizes them one by one. |
int
a[100], b[100], c[100], d[100]; double t[100]; int nchan = 2; multi_read_block (100, 2, 200, t, a,b, c, d); // fills only a and b since nchan = 2 |
boolean trig_read_block (int pin, int npoints, int deadtime, int delay, boolean trig_pol, double *tstamp, int *adval) | |
Digitization of the
ADC is triggered by an edge on 'pin'. pin : Digital input pin (0 to 3) npoints : number of digitizations.( maximum 1024) deadtime: time interval from the Edge to the first digitization. delay : between digitizations trig_pol : trigger polarity (rising or falling edge) tstamp : array of type double to return the time stamps adval : arrayof type double to return adc output |
double ts[256]; int val[256]; trig_read_block (0, 256, 500, 200, 1, ts, val); |
double period (int bit) | |
Measures the time interval for 10 cycles of the input signal, to calculate and return the Period of the signal, at the digital input pin spesified as argument. | // Sets the data to time period
of the signal at Dig Input 0 data = period (0); |
double r2rtime (int pin1, int pin2) | |
Returns the time interval between a rising edge on pin1 to a rising edge on pin2. If same pin is specified it will return the time interval between two consecutive rising edges. | // Sets the data to time
interval between a rising edge on pin0 to a rising edge on pin1 in usec. data=r2rtime(0,1); |
double r2ftime (int pin1, int pin2) | |
Returns the time interval between a rising edge on pin1 to a falling edge on pin2. If same pin is specified it will return the 'high time' of the TTL pulse fed to that pin. Also used for testing the accuracy of the system. | // Sets the data to time
interval between a rising edge on pin0 to a falling edge on pin1 in
usec. data=r2ftime (0,1); |
double f2rtime (int pin1, int pin2) | |
Returns the time interval between a falling edge on pin1 to a rising edge on pin2. If same pin is specified it will return the 'low time' of the TTLpulse fed to that pin. | // Sets the data to time
interval between a falling edge on pin0 to a rising edge on pin1 in
usec. data=f2rtime(0,1); |
double f2ftime (int pin1, int pin2) | |
Returns the time interval between a falling edge on pin1 to a falling edge on pin2. If same pin is specified it will return the time between two consecutive falling edges. | // Sets the data to time
interval between a falling edge on pin0 to a falling edge on pin1 in
usec. data=f2ftime(0,1); |
double set2rtime (int pin1, int pin2) | |
Returns the time
interval from
setting a bit on output pin1 to the rising edge on input pin2. pin1 : 0 to 7 means the Digital output pins. 8 to 11 means stepper motor outputs A,B,C and D pin2 : Input pins 0 to 3 |
// Sets the data to time
interval from setting output pin0 to the rising edge on an input pin0
in usec. data=set2rtime(0,0); |
double set2ftime (int pin1, int pin2) | |
Returns the time
interval from
setting a bit on output pin1 to the falling edge on input pin2. pin1 : 0 to 7 means the Digital output pins. 8 to11 means stepper motor outputs A,B,C and D pin2 : Input pins 0 to 3 |
// Sets the data to time
interval from setting output pin0 to the falling edge on an input pin0
in usec. data=set2ftime(0,0); |
double clr2rtime (int pin1, int pin2) | |
Returns the time
interval from
clearing the output pin1 to the rising edge on input pin2. pin1 : 0 to 7 means the Digital output pins. 8 to11 means stepper motor outputs A,B,C and D pin2 : Input pins 0 to 3 |
// Sets the data to time
interval from clearing output pin0 to the rising edge on an input pin0
in usec. data=clr2rtime(0,0); |
double clr2ftime (int pin1, int pin2) | |
Returns the
time interval from
clearing the output pin1 to the falling edge on input pin2. pin1 : 0 to 7 means the Digital output pins. 8 to11 means stepper motor outputs A,B,C and D pin2 : Input pins 0 to 3 |
// Sets the data to time
interval from clearing output pin0 to the falling edge on an input pin0
in usec. data=clr2ftime(0,0); |
double pulse2rtime (int pin1, int pin2, int width, int deadtime, int pol) | |
Generates a pulse on
pin1 and
returns the time interval from that pulse to the rising edge on pin2. pin1 : 0 to 7 for digital outputs, 8 to 11 for stepper motor outputs pin2 : 0 to 3 width: width of the pulse, Assumes the output was zero when called deadtime: Starts waiting only after elapsing deadtime. pol: 0 -> HIGH TRUE TTL (1 -> LOW TRUE) |
// Sets the data to time
interval from a 2 usec wide pulse output pin0 to a rising edge on
pin 0. Deadtime of 10 usec. LOW TRUE TTL pulse. data=pulse2rtime(0,0,2,10,1); |
double pulse2ftime (int pin1, int pin2, int width, int deadtime, int pol) | |
Generates a pulse on
pin1 and
returns the time interval from that pulse to the falling edge on pin2. pin1 : 0 to 7 for digital outputs, 8 to 11 for stepper motor outputs pin2 : 0 to 3 width: width of the pulse, Assumes the output was zero when called deadtime: Starts waiting only after elapsing deadtime. pol: 0 -> HIGH TRUE TTL (1 -> LOW TRUE) |
// Sets the data to time
interval from a 2 usec wide pulse output pin0 to a falling edge
on pin 0. Deadtime of 10 usec. LOW TRUE TTL pulse. data=pulse2ftime(0,0,2,10,1); |
double mid_high_time (int pin) | |
Returns the time of occurance of a Positive TTL pulse on the specified digital input. This function is used for measuring time intervals in the order of seconds by subtracting the values from two calls. | // Sets the data to time of
occurance of the midpoint of a Positive TTL pulse on the digital input0 data=mid_high_time (0); |
double mid_low_time (int pin) | |
Returns the time of occurance of a Negative TTL pulse on the specified digital input. This function is used for measuring time intervals in the order of seconds by subtracting the values from two calls. | // Sets the data to time of
occurance of the midpoint of a Negative TTL pulse on the digital input0. data=mid_low_time (0); |
double pulse_out (int pin, int high, int low, int np, int pol) | |
Generates a pulse on
a digital
output or the stepper motor output pin. pin : 0 to 7 means the bits on digital output. 8 tp 11 means Stepper Motor outputs. high : HIGH time of the pulse in usecs low : LOW time of the pulse in usecs np : number of pulses to be generated pol : 0 -> HIGH TRUE TTL (1 -> LOW TRUE) |
// Generates 10 pulses of 10usec
width and a time period of 100usec on digital output pin1. pulse_out (1,10,90,10, 0); |
int set_timeout (unsigned int i) | |
Time measurement calls waits inside the kernel and freezes the system for that period. It is essential to provide maximum limits for waiting.The default is around 2 seconds.This can be set between 5 m sec and 5 sec. | // Freezes the system for 1sec set_timeout (1000); |