Other Parts Discussed in Thread: CONTROLSUITE
I have verified with a volt meter that there is a voltage on the ADC line I am trying measure using the ADC. For some reason when I ever I call the function to read the voltage it always returns 0v. Can someone tell me if my function is not working?
the command being sent is TMS ADCINB7=?
This is what is stored in command.
void Console_ADC(void){
//---------------------------------------------------------------------------
Uint16 adc_channel;
Uint16 result;
float32 f[5];
float32 x;
char Vout[8];
Uint16 i,j;
char mode[9];
for(i=0;i<8;i++)
mode[i] = command[i+7];
mode[8] = 0;
//---------ADC READ--------------//
if(command[10] < 0x38 & command[10] > 0x2F & (command[9]=='A'|command[9]=='B') ) //verify the channel from a commmand sent
{
String_ADC[5]=command[9]; //set the channel in reply
String_ADC[6]=command[10]; //set the channel in reply
//this section decodes the input channel ('A0-B7') into the correct channel code (00-0F)
adc_channel= command[9]; //set result index as 'A' or 'B'
adc_channel<<=8; //shift to upper nibble
adc_channel |= command[10]; //put '1'-'7' in lower nibble
adc_channel -= 0x4130; //subtract 'A0'
if(adc_channel > 7) //if the command was 'Bx'
adc_channel -= 0xF8; //shift down to 8
//set the first four conversions to the desired channel for oversampling
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = adc_channel;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = adc_channel;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = adc_channel;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = adc_channel;
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; //reset sequencer
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;//clear previous ADC interrupt flag
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1; //start adc
while(AdcRegs.ADCST.bit.INT_SEQ1 != 1){}//wait for conversion to finish
for(i=0;i<4;i++)
{
result = adc_results[i]; //get the result
SciaTxByte(adc_results[i]);//see whats in the result
result >>=4; //shift down to valid data
if(result == 0x0FFF) // if it is over 3V
{
f[i+1] = 3000; //set a 3V
}
else
{
f[i+1] = (float)result; //cast as float
f[i+1]/=0x1000; //convert to proportion of 3V
f[i+1] *= 3000; //result as mV
}
f[0] += f[i+1]/4; //save running average in element 0
}
snprintf(Vout,7, "%f",f[0] ); //print as string for console
for(i=0;i<8;i++)
String_ADC[i+8] = Vout[i]; //put the voltage string in the response string
SciaTx(String_ADC); //send result via console
SciaTx("mV"); //append mV to the value
if(f[0] >= 3000) //if the value is over 3V
SciaTx(" (OVERLOAD)"); //send overload
SciaTx(String_crlf);
f[0] = 0;
}