Multichannel ADC S12

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multichannel ADC S12

524 Views
563451665
Contributor I

Hello, everyone.

I have a problem, when I use multi-channel ADC, only AN0 and AN1 are enabled, but their readings are the same. I can read different data when my ATDCTL0 exceeds the sequence, but I think the data in one of the channels is read at different times.

My main chip is S12VR48.

/************************************************************************************/

void ADC_Double_init(void) //非中断
{
ATDCTL0 = 0x01; //多通道转化的序列环绕到AN1
ATDCTL1 = 0X00; // 0000 0000 8位采样精度 采样前不放电(放电可能导致问题)
ATDCTL2 = 0x00; // 0000 0000 外部触发禁止 中断禁止 禁止快清
ATDCTL3 = 0x90;
//右对齐、数据长度2 冻结模式下继续转换 FIFO不启动
ATDCTL4 = 0xab; // 1010 1011 16AD采样时间 Fad = 1MHZ
/* fATDCLK = fBUS / (2*(PRS + 1)) Fadcclk=1MHz=24MHz/24*/
ATDCTL5 = 0x31; //0011 0001 连续转换 多通道 AN1选择
ATDDIEN = 0X00; //禁用数字输入缓冲器到ANx pin
}

This is the initialization setting of ADC.

/**********************************************************************************/

pastedImage_1.png

When my ATDCTL0 exceeds AN1, the reading becomes different, but if one channel is grounded the other becomes zero.

/*********************************************************************************/

void main(void) {
/* put your own code here */
MCUinit();
SwitchPowerModuleInit();
HS0On();
ADC_Double_init();
// PWMinit_PWM45();
MotorControlInit();
EnableInterrupts; //开放总中断
for(;;) //TEMP
{
while(!ATDSTAT0_SCF); // 等待转换结束,退出循环
ad_value_0=ATDDR0;
Delay(800); // 延时
ATDSTAT2L= ATDSTAT2L_CCF0_MASK; /*清标志位*/
ATDSTAT2L= ATDSTAT2L_CCF1_MASK; /*清标志位*/
ATDSTAT0 = ATDSTAT0_SCF_MASK; /*序列转换标志位*/
Sequence_Data = ATDSTAT0_CC; /*取出序列的数据序列*/
if (Sequence_Data==1)
{
ad_value_1=ATDDR1;
}
//ad_value_1=ATDDR0;

Delay(800); // 延时
if (ad_value_0 > ad_value_1)
{
MotorControlForwardOn();
}
else
MotorControlForwardOff();
//_FEED_COP(); /* feeds the dog */
}
/* loop forever */
/* please make sure that you never leave main */
}

here is my main code

Labels (1)
Tags (1)
0 Kudos
1 Reply

377 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

to say truth I am "a little bit" confused of your description of the issue and using the ADC module.

Why to use continuous conversion and then insert delay in the code. Next conversions are performed and I have info about completion of the first one (SCF).

Why you convert to channels if it is enough to convert one channel either in continuous mode or as a simple sequence at the right moment?

Channel AN0 is reserved so its value does not have any sense.

If you want to be absolute sure of conversion then use discharge Sample capacitor feature (ATDCTL1).

During debugging I suggest to use to also enable feature Finish conversion then freeze (ATDCTL3).
the easiest would be to know what do you exactly want to do (flow chart) and on the basis of expectations to select proper mode of converter.

Moreover, I hope you know the results are always stored in ATDDR registers from ATDDR0. For exampel, if I convert channels 4,5,6 the results will be in ATDDR 0,1,2.

best regards,

Ladislav

0 Kudos