Delta 36-R31 User Manual Page 83

  • Download
  • Add to my manuals
  • Print
  • Page
    / 84
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 82
ACC-36E Manual
Appendix C: using Pointers 83
int ACC36E_ADC(unsigned int Card_Index, unsigned int ADC_Pair, unsigned int Polarity, int
*ADC_Low, int *ADC_High)
{ /*Inputs:
Card_Index: The addressing index (n) of the card, based on SW1 settings.
ADC_Pair: The number of the ADC pair one desires to sample. Pair 1: ADC 1 & 9, pair 2:
ADC 2 & 10
... pair 8: ADC 8 & 16
Polarity: 0 = sample as unipolar input signal, 1 = sample as bipolar input signal
*ADC_Low: Address of the variable the user wants to use to store the low ADC result (user
needs
to pass in &ADC_Low)
*ADC_High: Address of the variable the user wants to use to store the high ADC result
(user needs to pass in &ADC_High)
Outputs:
return 0 if ADC conversion was successful
return -1 if user entered invalid Card_Index
return -2 if user entered invalid ADC_Pair
return -3 if user entered invalid Polarity
return -4 if ADC conversion timed out
Function puts ADC result low into *ADC_Low and result high into *ADC_High if the
conversion was successful*/
unsigned int Address,BaseOffset,ConvertCode;
int WaitResult;
volatile unsigned int *pACC36E_ADC_ChSelect;
volatile unsigned int *pACC36E_Data_Read_Unipolar; // Unsigned for bipolar input signals
volatile int *pACC36E_Data_Read_Bipolar; // Signed for bipolar input signals
if(Card_Index < 0 || Card_Index > 15)
{
return -1;
}
if((ADC_Pair < 1) || (ADC_Pair > 8))
{
return -2;
}
if((Polarity != 0) && (Polarity != 1))
{
return -3;
}
if(Polarity == 0) // Unipolar input signal
{
ConvertCode = ADC_Pair - 1;
} else { // Bipolar input signal
ConvertCode = ADC_Pair + 7;
}
BaseOffset = pshm->OffsetCardIO[Card_Index];
Address = (unsigned int)piom + BaseOffset/4;
pACC36E_ADC_ChSelect = (volatile unsigned int*)Address;
// Shift and mask to write the convert code to the correct place in the ADC word
*pACC36E_ADC_ChSelect = ((ConvertCode) << 8) & 0xFFFFFF00;
// Wait for the ADC to finish converting
WaitResult = ACC36E_WaitForADC(Card_Index);
if(WaitResult == -1){ // If the ADC conversion timed out
return (-4); // Return with error code
} else { // Otherwise return ADC result
if(Polarity == 0)
{
pACC36E_Data_Read_Unipolar = (volatile unsigned int*)Address;
// Shift and cast to get just the ADC results with the proper signs
*ADC_Low = ((unsigned int)(((*pACC36E_Data_Read_Unipolar) << 12) >> 20));
*ADC_High = ((unsigned int)((*pACC36E_Data_Read_Unipolar) >> 20));
} else {
pACC36E_Data_Read_Bipolar = (volatile int*)Address;
// Shift and cast to get just the ADC results with the proper signs
*ADC_Low = ((int)(((*pACC36E_Data_Read_Bipolar) << 12) >> 20));
*ADC_High = ((int)((*pACC36E_Data_Read_Bipolar) >> 20));
}
}
return 0;
}
Page view 82
1 2 ... 78 79 80 81 82 83 84

Comments to this Manuals

No comments