S12ZVM ADC 怎么使用

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

S12ZVM ADC 怎么使用

1,761 Views
sufree
Contributor II

各位,

         我用芯片 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
}

2 Replies

1,184 Views
RadekS
NXP Employee
NXP Employee

Hi,

The ADC0CommandList contains list of ADC commands. These commands are loaded into ADC through DMA.

So, we configure ADC0CBP register as pointer to the ADC0CommandList array.

That way, the ADC know where to start with reading ADC commands.

 

The same is valid for ADC0RBP register(s). It contains pointer to the result array in RAM.

 

Note: Please be aware that RAM starts at address 0x1000 by default and if you didn’t change a linker file, you placed the command and result lists on the area which is dedicated by stack (first 256B in RAM by default)

I would like to recommend keep command and result lists placement on the linker file.

For example:

volatile uint8_t ADC0CommandList[6][4] __attribute__ ((aligned (4))) = \

instead of

volatile uint8_t ADC0CommandList[6][4] @0x00001030 = \

 

If you need measure two channels simultaneously, you have to use both ADCs (ADC0 and ADC1) triggered by the same event.

 

Unfortunately, I am not sure why ADC0ResultList [1] and ADC0ResultList [0] values are the same on your side.

Anyway, you need two triggers for measure both values on the ADC0.

I hope it helps you.

Radek

1,184 Views
sufree
Contributor II

OK,thank you very much.

0 Kudos