Delta 36-R31 User Manual Page 34

  • Download
  • Add to my manuals
  • Print
  • Page
    / 84
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 33
ACC-36E Manual
USing acc-36E with power umac 34
Accessing ADCs from C Environment (For C Programmers)
Reading:
The GetPmacVar() function below allows one to read the ACC-36E structures in C. It is defined as
int GetPmacVar (char *pinstr, double *pdata), where:
- The first argument is a string containing the name of the variable to query.
- The second argument is a double containing the address of the ADC result (low or high).
Writing:
The SetPmacVar() function below allows writing to the ACC-36E structures in C. It is defined as:
int SetPmacVar (char *pinstr, double data), where:
- The first argument is a string containing the name of the variable to which to write.
- The second argument is a double containing the value to write.
WARNING
When using C routines, failure to release control of the loop
waiting for the ADC conversions to finish may cause PMAC to
lock up, possibly creating a runaway condition. Thus, one of the
following functions, WaitForADC(), has precautions in order to
release control of the wait loop in the event that the ADC
conversion bits never become 1.
Example: Unipolar Manual ADC Read in a CPLC
Configuring one ACC-36E with unipolar inputs at base offset $A00000.
#include <gplib.h>
#include <stdio.h>
#include <dlfcn.h>
// Definition(s)
#define FirstCardNumber 0 // At Base Offset $A00000
// Prototype(s)
int WaitForADC(unsigned int Card_Index);
void user_plcc() {
unsigned int ADC_Result_Unipolar[16],index;
int waitResult = 0;
char buffer[32]="";
double temp = 0,ConvertCode = 0;
// Access ADC results one by one in a for loop
for(index = 0; index < 8; index++) {
// Prepare string
sprintf(buffer,"ACC36E[%d].ConvertCode",FirstCardNumber);
ConvertCode = index; // Compute convert code
// Write Unipolar convert code to Channel Select structure
SetPmacVar(buffer,ConvertCode);
// Poll conversion complete bits until the conversions are finished
waitResult = WaitForADC(FirstCardNumber);
if(waitResult < 0)
{
return; // Conversion was not successful
}
// Prepare string
sprintf(buffer,"ACC36E[%d].ADCuLow",FirstCardNumber);
GetPmacVar(buffer,&temp); // Read the structure
// Cast and store low unipolar (unsigned) ADC Result in array element
ADC_Result_Unipolar[index] = (unsigned int)temp;
Page view 33
1 2 ... 29 30 31 32 33 34 35 36 37 38 39 ... 83 84

Comments to this Manuals

No comments