AnsweredAssumed Answered

S12ZVM   ADC  怎么使用

Question asked by 歌 苏 on Nov 30, 2017
Latest reply on Dec 1, 2017 by 歌 苏

各位,

         我用芯片 S12ZVM 和 参考程序:AN4718SW 控制无刷直流电机。现在在ADC这遇到问题,以前没用过S12ZVM这种ADC配置方法,有些地方不懂。

1,ADC0CBP_0 = (uint8_t)(((vuint32_t)&ADC0CommandList[0][0]) >> 16);

     ADC0CBP_1 = (uint8_t)(((vuint32_t)&ADC0CommandList[0][0]) >> 8);
     ADC0CBP_2 = (uint8_t)((vuint32_t)&ADC0CommandList[0][0]);

没看懂这三行是怎么将这些{0x40,0xD0,0x00,0x00}和{0xC0,0xCB,0x00,0x00}配置到ADC_CMD寄存器的,而且是采集电流和电压的,我对于这个基于命令列表的配置方式不太懂。

 

2,需要同时采集电流电压,按照void InitADC(void),设置后为什么就可以了,我实际运行时只能采集到电流值,ADC0ResultList[1] 的值和 ADC0ResultList[0] 的值是一样的,并不是电压值。

 

volatile uint8_t ADC0CommandList[6][4] @0x00001030 = \
{ \
{0x40,0xD0,0x00,0x00}, // End of sequence, convert AN0 pin DC bus current, 4 clock cycles sample time 
{0xC0,0xCB,0x00,0x00}, // End of list, convert HD pin DC bus voltage, 4 clock cycles sample time 
{0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00}
{0x00,0x00,0x00,0x00}
};

// ADC0 conversion results. Select array address, where address last 2 bits value is 0 (see ADC0RBP)
volatile uint16_t ADC0ResultList[6] @0x00001060 = {0, 0, 0, 0, 0, 0};

 

void InitADC(void)
{
// ADC0
// Dual access mode vis internal interface and data bus
ADC0CTL_0_ACC_CFG = 3;
// Store result at abort/restart
ADC0CTL_0_STR_SEQA = 1;

// ADC clock 6.25 MHz
ADC0TIM = ADC_TIM;

// Left justified data result
ADC0FMT_DJM = 0;
// 12-bit data result
ADC0FMT_SRES = 4;
// End of list interrupt enable
ADC0CONIE_1_EOL_IE = 1;

// ADC0 Command Base Pointer
ADC0CBP_0 = (uint8_t)(((vuint32_t)&ADC0CommandList[0][0]) >> 16);
ADC0CBP_1 = (uint8_t)(((vuint32_t)&ADC0CommandList[0][0]) >> 8);
ADC0CBP_2 = (uint8_t)((vuint32_t)&ADC0CommandList[0][0]);

// ADC0 Result Base Pointer
ADC0RBP_0 = (uint8_t)(((vuint32_t)&ADC0ResultList[0]) >> 16);
ADC0RBP_1 = (uint8_t)(((vuint32_t)&ADC0ResultList[0]) >> 8);
ADC0RBP_2 = (uint8_t)((vuint32_t)&ADC0ResultList[0]);

// Enable ADC0
ADC0CTL_0_ADC_EN = 1;

ADC0EIE = 0xEE; // enable all errors interrupts
}

Outcomes