AnsweredAssumed Answered

Multichannel ADC S12

Question asked by 智超 陆 on Oct 21, 2018
Latest reply on Oct 30, 2018 by lama

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.

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

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

Outcomes