AnsweredAssumed Answered

Re: The  ADC conversion

Question asked by PRATIBHA SURABHI on Jan 23, 2017
Latest reply on Jan 30, 2017 by PRATIBHA SURABHI

hello, I am using S12ZVML128 controller.

I am not getting ADC conversion result in result register.I have initialized ADC as following.I am calling GetADCValue(E_ADC_CHANNEL_NUMBER leAdcChanNo) function in main by passing channel number.

I am not getting what i have missed in this code to get the conversion value.

Please help me for that? 

 

volatile UINT8 ADC0CommandList[1][4] = {{0xC0,0x00,0x00,0x00}};

volatile UINT8 ADC1CommandList[1][4] = {{0xC0,0x00,0x00,0x00}};
volatile unsigned short ADC0ResultList[1] = {0};
volatile unsigned short ADC1ResultList[1] = {0};

 

typedef enum
{
ADC_CHANNEL_NO_TOTAL_PHASE_CURRENT=0x10, //AN0_0
ADC_CHANNEL_NO_W_PHASE_VOLTAGE=0x50, //AN1_0
ADC_CHANNEL_NO_V_PHASE_VOLTAGE=0x14, //AN0_4
ADC_CHANNEL_NO_U_PHASE_VOLTAGE=0x13, //AN0_3
ADC_CHANNEL_NO_TEMPERATURE_SENSOR=0x51, //AN1_1
ADC_CHANNEL_NO_BATTERY_VOLTAGE=0x52 //AN1_2
}E_ADC_CHANNEL_NUMBER;

 

void InitADC(void)
{

 

//ADC0
ADC0CTL_0 = 0x09; // single access mode-data bus,Trigger mode
//ADC0CTL_0_STR_SEQA = 1; // Store result at abort/restart
ADC0CTL_1=0x10;
ADC0STS=0x00;
ADC0FMT_DJM = 1; // left justified result data
ADC0FMT_SRES = 4; // 12-bit result
ADC0TIM=0; // clock: clk = fbus / (2x(reg.value + 1)) [0.25 - 8MHz]
ADC0CBP = ADC0CommandList;
ADC0RBP = ADC0ResultList;
ADC0CTL_0_ADC_EN = 1;
//ADC1
ADC1CTL_0 = 0x09; // single access mode-data bus,Trigger mode
//ADC1CTL_0_STR_SEQA = 1; // Store result at abort/restart
ADC1CTL_1=0x10;
ADC1STS=0x00;
ADC1FMT_DJM = 1; // left justified result data
ADC1FMT_SRES = 4; // 12-bit result
ADC1TIM=0; // clock: clk = fbus / (2x(reg.value + 1)) [0.25 - 8MHz]
ADC1CBP = ADC1CommandList;
ADC1RBP = ADC1ResultList;
ADC1CTL_0_ADC_EN = 1;

}

UINT16 GetADCValue(E_ADC_CHANNEL_NUMBER leAdcChanNo)
{
   UINT16 lu16AdcConvResult = 0;
   UINT8 lu8cmdListVar=0;
   UINT8 var=0;
if((leAdcChanNo>>6)==1)      //for ADC 1 channel
{
var=(leAdcChanNo & 0x3F)+0xC0;
ADC1CommandList[0][1]=var;
ADC1FLWCTL_RSTA = 1;
while(!ADC1CONIF)
{

}
ADC1CONIF=ADC1CONIF;
return(ADC1ResultList[0]);
}
else if((leAdcChanNo>>6)!=1)   //for ADC 0 channel
{
var=(leAdcChanNo & 0x3F)+0xC0;
ADC0CommandList[0][1]=var;
ADC0FLWCTL_RSTA = 1;
while(!ADC1CONIF)
{

}
ADC0CONIF=ADC0CONIF;
return(ADC0ResultList[0]);
}
else
{

}

}

Outcomes